UNPKG

use-material-you

Version:

React hook to create dynamic schemes and variants based on M3/material-color-utilities

3,134 lines 109 kB
import * as gt from "react";
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function N(t) {
  return t < 0 ? -1 : t === 0 ? 0 : 1;
}
function st(t, e, r) {
  return (1 - r) * t + r * e;
}
function Ot(t, e, r) {
  return r < t ? t : r > e ? e : r;
}
function ht(t, e, r) {
  return r < t ? t : r > e ? e : r;
}
function kt(t) {
  return t = t % 360, t < 0 && (t = t + 360), t;
}
function W(t) {
  return t = t % 360, t < 0 && (t = t + 360), t;
}
function pt(t, e) {
  const r = t[0] * e[0][0] + t[1] * e[0][1] + t[2] * e[0][2], n = t[0] * e[1][0] + t[1] * e[1][1] + t[2] * e[1][2], a = t[0] * e[2][0] + t[1] * e[2][1] + t[2] * e[2][2];
  return [r, n, a];
}
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
const Ft = [
  [0.41233895, 0.35762064, 0.18051042],
  [0.2126, 0.7152, 0.0722],
  [0.01932141, 0.11916382, 0.95034478]
], vt = [
  [
    3.2413774792388685,
    -1.5376652402851851,
    -0.49885366846268053
  ],
  [
    -0.9691452513005321,
    1.8758853451067872,
    0.04156585616912061
  ],
  [
    0.05562093689691305,
    -0.20395524564742123,
    1.0571799111220335
  ]
], Bt = [95.047, 100, 108.883];
function lt(t, e, r) {
  return (255 << 24 | (t & 255) << 16 | (e & 255) << 8 | r & 255) >>> 0;
}
function Dt(t) {
  const e = nt(t[0]), r = nt(t[1]), n = nt(t[2]);
  return lt(e, r, n);
}
function bt(t) {
  return t >> 16 & 255;
}
function Pt(t) {
  return t >> 8 & 255;
}
function Mt(t) {
  return t & 255;
}
function Et(t, e, r) {
  const n = vt, a = n[0][0] * t + n[0][1] * e + n[0][2] * r, i = n[1][0] * t + n[1][1] * e + n[1][2] * r, u = n[2][0] * t + n[2][1] * e + n[2][2] * r, l = nt(a), m = nt(i), M = nt(u);
  return lt(l, m, M);
}
function zt(t) {
  const e = Z(bt(t)), r = Z(Pt(t)), n = Z(Mt(t));
  return pt([e, r, n], Ft);
}
function _t(t) {
  const e = Z(bt(t)), r = Z(Pt(t)), n = Z(Mt(t)), a = Ft, i = a[0][0] * e + a[0][1] * r + a[0][2] * n, u = a[1][0] * e + a[1][1] * r + a[1][2] * n, l = a[2][0] * e + a[2][1] * r + a[2][2] * n, m = Bt, M = i / m[0], d = u / m[1], w = l / m[2], f = it(M), c = it(d), s = it(w), h = 116 * c - 16, y = 500 * (f - c), p = 200 * (c - s);
  return [h, y, p];
}
function Nt(t) {
  const e = tt(t), r = nt(e);
  return lt(r, r, r);
}
function Tt(t) {
  const e = zt(t)[1];
  return 116 * it(e / 100) - 16;
}
function tt(t) {
  return 100 * qt((t + 16) / 116);
}
function yt(t) {
  return it(t / 100) * 116 - 16;
}
function Z(t) {
  const e = t / 255;
  return e <= 0.040449936 ? e / 12.92 * 100 : Math.pow((e + 0.055) / 1.055, 2.4) * 100;
}
function nt(t) {
  const e = t / 100;
  let r = 0;
  return e <= 31308e-7 ? r = e * 12.92 : r = 1.055 * Math.pow(e, 1 / 2.4) - 0.055, Ot(0, 255, Math.round(r * 255));
}
function Vt() {
  return Bt;
}
function it(t) {
  const e = 0.008856451679035631, r = 24389 / 27;
  return t > e ? Math.pow(t, 1 / 3) : (r * t + 16) / 116;
}
function qt(t) {
  const e = 0.008856451679035631, r = 24389 / 27, n = t * t * t;
  return n > e ? n : (116 * t - 16) / r;
}
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class X {
  /**
   * Create ViewingConditions from a simple, physically relevant, set of
   * parameters.
   *
   * @param whitePoint White point, measured in the XYZ color space.
   *     default = D65, or sunny day afternoon
   * @param adaptingLuminance The luminance of the adapting field. Informally,
   *     how bright it is in the room where the color is viewed. Can be
   *     calculated from lux by multiplying lux by 0.0586. default = 11.72,
   *     or 200 lux.
   * @param backgroundLstar The lightness of the area surrounding the color.
   *     measured by L* in L*a*b*. default = 50.0
   * @param surround A general description of the lighting surrounding the
   *     color. 0 is pitch dark, like watching a movie in a theater. 1.0 is a
   *     dimly light room, like watching TV at home at night. 2.0 means there
   *     is no difference between the lighting on the color and around it.
   *     default = 2.0
   * @param discountingIlluminant Whether the eye accounts for the tint of the
   *     ambient lighting, such as knowing an apple is still red in green light.
   *     default = false, the eye does not perform this process on
   *       self-luminous objects like displays.
   */
  static make(e = Vt(), r = 200 / Math.PI * tt(50) / 100, n = 50, a = 2, i = !1) {
    const u = e, l = u[0] * 0.401288 + u[1] * 0.650173 + u[2] * -0.051461, m = u[0] * -0.250268 + u[1] * 1.204414 + u[2] * 0.045854, M = u[0] * -2079e-6 + u[1] * 0.048952 + u[2] * 0.953127, d = 0.8 + a / 10, w = d >= 0.9 ? st(0.59, 0.69, (d - 0.9) * 10) : st(0.525, 0.59, (d - 0.8) * 10);
    let f = i ? 1 : d * (1 - 1 / 3.6 * Math.exp((-r - 42) / 92));
    f = f > 1 ? 1 : f < 0 ? 0 : f;
    const c = d, s = [
      f * (100 / l) + 1 - f,
      f * (100 / m) + 1 - f,
      f * (100 / M) + 1 - f
    ], h = 1 / (5 * r + 1), y = h * h * h * h, p = 1 - y, A = y * r + 0.1 * p * p * Math.cbrt(5 * r), b = tt(n) / e[1], R = 1.48 + Math.sqrt(b), g = 0.725 / Math.pow(b, 0.2), T = g, C = [
      Math.pow(A * s[0] * l / 100, 0.42),
      Math.pow(A * s[1] * m / 100, 0.42),
      Math.pow(A * s[2] * M / 100, 0.42)
    ], F = [
      400 * C[0] / (C[0] + 27.13),
      400 * C[1] / (C[1] + 27.13),
      400 * C[2] / (C[2] + 27.13)
    ], B = (2 * F[0] + F[1] + 0.05 * F[2]) * g;
    return new X(b, B, g, T, w, c, s, A, Math.pow(A, 0.25), R);
  }
  /**
   * Parameters are intermediate values of the CAM16 conversion process. Their
   * names are shorthand for technical color science terminology, this class
   * would not benefit from documenting them individually. A brief overview
   * is available in the CAM16 specification, and a complete overview requires
   * a color science textbook, such as Fairchild's Color Appearance Models.
   */
  constructor(e, r, n, a, i, u, l, m, M, d) {
    this.n = e, this.aw = r, this.nbb = n, this.ncb = a, this.c = i, this.nc = u, this.rgbD = l, this.fl = m, this.fLRoot = M, this.z = d;
  }
}
X.DEFAULT = X.make();
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class Y {
  /**
   * All of the CAM16 dimensions can be calculated from 3 of the dimensions, in
   * the following combinations:
   *      -  {j or q} and {c, m, or s} and hue
   *      - jstar, astar, bstar
   * Prefer using a static method that constructs from 3 of those dimensions.
   * This constructor is intended for those methods to use to return all
   * possible dimensions.
   *
   * @param hue
   * @param chroma informally, colorfulness / color intensity. like saturation
   *     in HSL, except perceptually accurate.
   * @param j lightness
   * @param q brightness; ratio of lightness to white point's lightness
   * @param m colorfulness
   * @param s saturation; ratio of chroma to white point's chroma
   * @param jstar CAM16-UCS J coordinate
   * @param astar CAM16-UCS a coordinate
   * @param bstar CAM16-UCS b coordinate
   */
  constructor(e, r, n, a, i, u, l, m, M) {
    this.hue = e, this.chroma = r, this.j = n, this.q = a, this.m = i, this.s = u, this.jstar = l, this.astar = m, this.bstar = M;
  }
  /**
   * CAM16 instances also have coordinates in the CAM16-UCS space, called J*,
   * a*, b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16
   * specification, and is used to measure distances between colors.
   */
  distance(e) {
    const r = this.jstar - e.jstar, n = this.astar - e.astar, a = this.bstar - e.bstar, i = Math.sqrt(r * r + n * n + a * a);
    return 1.41 * Math.pow(i, 0.63);
  }
  /**
   * @param argb ARGB representation of a color.
   * @return CAM16 color, assuming the color was viewed in default viewing
   *     conditions.
   */
  static fromInt(e) {
    return Y.fromIntInViewingConditions(e, X.DEFAULT);
  }
  /**
   * @param argb ARGB representation of a color.
   * @param viewingConditions Information about the environment where the color
   *     was observed.
   * @return CAM16 color.
   */
  static fromIntInViewingConditions(e, r) {
    const n = (e & 16711680) >> 16, a = (e & 65280) >> 8, i = e & 255, u = Z(n), l = Z(a), m = Z(i), M = 0.41233895 * u + 0.35762064 * l + 0.18051042 * m, d = 0.2126 * u + 0.7152 * l + 0.0722 * m, w = 0.01932141 * u + 0.11916382 * l + 0.95034478 * m, f = 0.401288 * M + 0.650173 * d - 0.051461 * w, c = -0.250268 * M + 1.204414 * d + 0.045854 * w, s = -2079e-6 * M + 0.048952 * d + 0.953127 * w, h = r.rgbD[0] * f, y = r.rgbD[1] * c, p = r.rgbD[2] * s, A = Math.pow(r.fl * Math.abs(h) / 100, 0.42), b = Math.pow(r.fl * Math.abs(y) / 100, 0.42), R = Math.pow(r.fl * Math.abs(p) / 100, 0.42), g = N(h) * 400 * A / (A + 27.13), T = N(y) * 400 * b / (b + 27.13), C = N(p) * 400 * R / (R + 27.13), F = (11 * g + -12 * T + C) / 11, B = (g + T - 2 * C) / 9, x = (20 * g + 20 * T + 21 * C) / 20, z = (40 * g + 20 * T + C) / 20, S = Math.atan2(B, F) * 180 / Math.PI, v = S < 0 ? S + 360 : S >= 360 ? S - 360 : S, j = v * Math.PI / 180, G = z * r.nbb, K = 100 * Math.pow(G / r.aw, r.c * r.z), U = 4 / r.c * Math.sqrt(K / 100) * (r.aw + 4) * r.fLRoot, et = v < 20.14 ? v + 360 : v, ft = 0.25 * (Math.cos(et * Math.PI / 180 + 2) + 3.8), dt = 5e4 / 13 * ft * r.nc * r.ncb * Math.sqrt(F * F + B * B) / (x + 0.305), ut = Math.pow(dt, 0.9) * Math.pow(1.64 - Math.pow(0.29, r.n), 0.73), At = ut * Math.sqrt(K / 100), wt = At * r.fLRoot, Rt = 50 * Math.sqrt(ut * r.c / (r.aw + 4)), xt = (1 + 100 * 7e-3) * K / (1 + 7e-3 * K), Ct = 1 / 0.0228 * Math.log(1 + 0.0228 * wt), Lt = Ct * Math.cos(j), St = Ct * Math.sin(j);
    return new Y(v, At, K, U, wt, Rt, xt, Lt, St);
  }
  /**
   * @param j CAM16 lightness
   * @param c CAM16 chroma
   * @param h CAM16 hue
   */
  static fromJch(e, r, n) {
    return Y.fromJchInViewingConditions(e, r, n, X.DEFAULT);
  }
  /**
   * @param j CAM16 lightness
   * @param c CAM16 chroma
   * @param h CAM16 hue
   * @param viewingConditions Information about the environment where the color
   *     was observed.
   */
  static fromJchInViewingConditions(e, r, n, a) {
    const i = 4 / a.c * Math.sqrt(e / 100) * (a.aw + 4) * a.fLRoot, u = r * a.fLRoot, l = r / Math.sqrt(e / 100), m = 50 * Math.sqrt(l * a.c / (a.aw + 4)), M = n * Math.PI / 180, d = (1 + 100 * 7e-3) * e / (1 + 7e-3 * e), w = 1 / 0.0228 * Math.log(1 + 0.0228 * u), f = w * Math.cos(M), c = w * Math.sin(M);
    return new Y(n, r, e, i, u, m, d, f, c);
  }
  /**
   * @param jstar CAM16-UCS lightness.
   * @param astar CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian
   *     coordinate on the Y axis.
   * @param bstar CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian
   *     coordinate on the X axis.
   */
  static fromUcs(e, r, n) {
    return Y.fromUcsInViewingConditions(e, r, n, X.DEFAULT);
  }
  /**
   * @param jstar CAM16-UCS lightness.
   * @param astar CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian
   *     coordinate on the Y axis.
   * @param bstar CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian
   *     coordinate on the X axis.
   * @param viewingConditions Information about the environment where the color
   *     was observed.
   */
  static fromUcsInViewingConditions(e, r, n, a) {
    const i = r, u = n, l = Math.sqrt(i * i + u * u), M = (Math.exp(l * 0.0228) - 1) / 0.0228 / a.fLRoot;
    let d = Math.atan2(u, i) * (180 / Math.PI);
    d < 0 && (d += 360);
    const w = e / (1 - (e - 100) * 7e-3);
    return Y.fromJchInViewingConditions(w, M, d, a);
  }
  /**
   *  @return ARGB representation of color, assuming the color was viewed in
   *     default viewing conditions, which are near-identical to the default
   *     viewing conditions for sRGB.
   */
  toInt() {
    return this.viewed(X.DEFAULT);
  }
  /**
   * @param viewingConditions Information about the environment where the color
   *     will be viewed.
   * @return ARGB representation of color
   */
  viewed(e) {
    const r = this.chroma === 0 || this.j === 0 ? 0 : this.chroma / Math.sqrt(this.j / 100), n = Math.pow(r / Math.pow(1.64 - Math.pow(0.29, e.n), 0.73), 1 / 0.9), a = this.hue * Math.PI / 180, i = 0.25 * (Math.cos(a + 2) + 3.8), u = e.aw * Math.pow(this.j / 100, 1 / e.c / e.z), l = i * (5e4 / 13) * e.nc * e.ncb, m = u / e.nbb, M = Math.sin(a), d = Math.cos(a), w = 23 * (m + 0.305) * n / (23 * l + 11 * n * d + 108 * n * M), f = w * d, c = w * M, s = (460 * m + 451 * f + 288 * c) / 1403, h = (460 * m - 891 * f - 261 * c) / 1403, y = (460 * m - 220 * f - 6300 * c) / 1403, p = Math.max(0, 27.13 * Math.abs(s) / (400 - Math.abs(s))), A = N(s) * (100 / e.fl) * Math.pow(p, 1 / 0.42), b = Math.max(0, 27.13 * Math.abs(h) / (400 - Math.abs(h))), R = N(h) * (100 / e.fl) * Math.pow(b, 1 / 0.42), g = Math.max(0, 27.13 * Math.abs(y) / (400 - Math.abs(y))), T = N(y) * (100 / e.fl) * Math.pow(g, 1 / 0.42), C = A / e.rgbD[0], F = R / e.rgbD[1], B = T / e.rgbD[2], x = 1.86206786 * C - 1.01125463 * F + 0.14918677 * B, z = 0.38752654 * C + 0.62144744 * F - 897398e-8 * B, O = -0.0158415 * C - 0.03412294 * F + 1.04996444 * B;
    return Et(x, z, O);
  }
  /// Given color expressed in XYZ and viewed in [viewingConditions], convert to
  /// CAM16.
  static fromXyzInViewingConditions(e, r, n, a) {
    const i = 0.401288 * e + 0.650173 * r - 0.051461 * n, u = -0.250268 * e + 1.204414 * r + 0.045854 * n, l = -2079e-6 * e + 0.048952 * r + 0.953127 * n, m = a.rgbD[0] * i, M = a.rgbD[1] * u, d = a.rgbD[2] * l, w = Math.pow(a.fl * Math.abs(m) / 100, 0.42), f = Math.pow(a.fl * Math.abs(M) / 100, 0.42), c = Math.pow(a.fl * Math.abs(d) / 100, 0.42), s = N(m) * 400 * w / (w + 27.13), h = N(M) * 400 * f / (f + 27.13), y = N(d) * 400 * c / (c + 27.13), p = (11 * s + -12 * h + y) / 11, A = (s + h - 2 * y) / 9, b = (20 * s + 20 * h + 21 * y) / 20, R = (40 * s + 20 * h + y) / 20, T = Math.atan2(A, p) * 180 / Math.PI, C = T < 0 ? T + 360 : T >= 360 ? T - 360 : T, F = C * Math.PI / 180, B = R * a.nbb, x = 100 * Math.pow(B / a.aw, a.c * a.z), z = 4 / a.c * Math.sqrt(x / 100) * (a.aw + 4) * a.fLRoot, O = C < 20.14 ? C + 360 : C, S = 1 / 4 * (Math.cos(O * Math.PI / 180 + 2) + 3.8), j = 5e4 / 13 * S * a.nc * a.ncb * Math.sqrt(p * p + A * A) / (b + 0.305), G = Math.pow(j, 0.9) * Math.pow(1.64 - Math.pow(0.29, a.n), 0.73), K = G * Math.sqrt(x / 100), U = K * a.fLRoot, et = 50 * Math.sqrt(G * a.c / (a.aw + 4)), ft = (1 + 100 * 7e-3) * x / (1 + 7e-3 * x), mt = Math.log(1 + 0.0228 * U) / 0.0228, dt = mt * Math.cos(F), ut = mt * Math.sin(F);
    return new Y(C, K, x, z, U, et, ft, dt, ut);
  }
  /// XYZ representation of CAM16 seen in [viewingConditions].
  xyzInViewingConditions(e) {
    const r = this.chroma === 0 || this.j === 0 ? 0 : this.chroma / Math.sqrt(this.j / 100), n = Math.pow(r / Math.pow(1.64 - Math.pow(0.29, e.n), 0.73), 1 / 0.9), a = this.hue * Math.PI / 180, i = 0.25 * (Math.cos(a + 2) + 3.8), u = e.aw * Math.pow(this.j / 100, 1 / e.c / e.z), l = i * (5e4 / 13) * e.nc * e.ncb, m = u / e.nbb, M = Math.sin(a), d = Math.cos(a), w = 23 * (m + 0.305) * n / (23 * l + 11 * n * d + 108 * n * M), f = w * d, c = w * M, s = (460 * m + 451 * f + 288 * c) / 1403, h = (460 * m - 891 * f - 261 * c) / 1403, y = (460 * m - 220 * f - 6300 * c) / 1403, p = Math.max(0, 27.13 * Math.abs(s) / (400 - Math.abs(s))), A = N(s) * (100 / e.fl) * Math.pow(p, 1 / 0.42), b = Math.max(0, 27.13 * Math.abs(h) / (400 - Math.abs(h))), R = N(h) * (100 / e.fl) * Math.pow(b, 1 / 0.42), g = Math.max(0, 27.13 * Math.abs(y) / (400 - Math.abs(y))), T = N(y) * (100 / e.fl) * Math.pow(g, 1 / 0.42), C = A / e.rgbD[0], F = R / e.rgbD[1], B = T / e.rgbD[2], x = 1.86206786 * C - 1.01125463 * F + 0.14918677 * B, z = 0.38752654 * C + 0.62144744 * F - 897398e-8 * B, O = -0.0158415 * C - 0.03412294 * F + 1.04996444 * B;
    return [x, z, O];
  }
}
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class D {
  /**
   * Sanitizes a small enough angle in radians.
   *
   * @param angle An angle in radians; must not deviate too much
   * from 0.
   * @return A coterminal angle between 0 and 2pi.
   */
  static sanitizeRadians(e) {
    return (e + Math.PI * 8) % (Math.PI * 2);
  }
  /**
   * Delinearizes an RGB component, returning a floating-point
   * number.
   *
   * @param rgbComponent 0.0 <= rgb_component <= 100.0, represents
   * linear R/G/B channel
   * @return 0.0 <= output <= 255.0, color channel converted to
   * regular RGB space
   */
  static trueDelinearized(e) {
    const r = e / 100;
    let n = 0;
    return r <= 31308e-7 ? n = r * 12.92 : n = 1.055 * Math.pow(r, 1 / 2.4) - 0.055, n * 255;
  }
  static chromaticAdaptation(e) {
    const r = Math.pow(Math.abs(e), 0.42);
    return N(e) * 400 * r / (r + 27.13);
  }
  /**
   * Returns the hue of a linear RGB color in CAM16.
   *
   * @param linrgb The linear RGB coordinates of a color.
   * @return The hue of the color in CAM16, in radians.
   */
  static hueOf(e) {
    const r = pt(e, D.SCALED_DISCOUNT_FROM_LINRGB), n = D.chromaticAdaptation(r[0]), a = D.chromaticAdaptation(r[1]), i = D.chromaticAdaptation(r[2]), u = (11 * n + -12 * a + i) / 11, l = (n + a - 2 * i) / 9;
    return Math.atan2(l, u);
  }
  static areInCyclicOrder(e, r, n) {
    const a = D.sanitizeRadians(r - e), i = D.sanitizeRadians(n - e);
    return a < i;
  }
  /**
   * Solves the lerp equation.
   *
   * @param source The starting number.
   * @param mid The number in the middle.
   * @param target The ending number.
   * @return A number t such that lerp(source, target, t) = mid.
   */
  static intercept(e, r, n) {
    return (r - e) / (n - e);
  }
  static lerpPoint(e, r, n) {
    return [
      e[0] + (n[0] - e[0]) * r,
      e[1] + (n[1] - e[1]) * r,
      e[2] + (n[2] - e[2]) * r
    ];
  }
  /**
   * Intersects a segment with a plane.
   *
   * @param source The coordinates of point A.
   * @param coordinate The R-, G-, or B-coordinate of the plane.
   * @param target The coordinates of point B.
   * @param axis The axis the plane is perpendicular with. (0: R, 1:
   * G, 2: B)
   * @return The intersection point of the segment AB with the plane
   * R=coordinate, G=coordinate, or B=coordinate
   */
  static setCoordinate(e, r, n, a) {
    const i = D.intercept(e[a], r, n[a]);
    return D.lerpPoint(e, i, n);
  }
  static isBounded(e) {
    return 0 <= e && e <= 100;
  }
  /**
   * Returns the nth possible vertex of the polygonal intersection.
   *
   * @param y The Y value of the plane.
   * @param n The zero-based index of the point. 0 <= n <= 11.
   * @return The nth possible vertex of the polygonal intersection
   * of the y plane and the RGB cube, in linear RGB coordinates, if
   * it exists. If this possible vertex lies outside of the cube,
   * [-1.0, -1.0, -1.0] is returned.
   */
  static nthVertex(e, r) {
    const n = D.Y_FROM_LINRGB[0], a = D.Y_FROM_LINRGB[1], i = D.Y_FROM_LINRGB[2], u = r % 4 <= 1 ? 0 : 100, l = r % 2 === 0 ? 0 : 100;
    if (r < 4) {
      const m = u, M = l, d = (e - m * a - M * i) / n;
      return D.isBounded(d) ? [d, m, M] : [-1, -1, -1];
    } else if (r < 8) {
      const m = u, M = l, d = (e - M * n - m * i) / a;
      return D.isBounded(d) ? [M, d, m] : [-1, -1, -1];
    } else {
      const m = u, M = l, d = (e - m * n - M * a) / i;
      return D.isBounded(d) ? [m, M, d] : [-1, -1, -1];
    }
  }
  /**
   * Finds the segment containing the desired color.
   *
   * @param y The Y value of the color.
   * @param targetHue The hue of the color.
   * @return A list of two sets of linear RGB coordinates, each
   * corresponding to an endpoint of the segment containing the
   * desired color.
   */
  static bisectToSegment(e, r) {
    let n = [-1, -1, -1], a = n, i = 0, u = 0, l = !1, m = !0;
    for (let M = 0; M < 12; M++) {
      const d = D.nthVertex(e, M);
      if (d[0] < 0)
        continue;
      const w = D.hueOf(d);
      if (!l) {
        n = d, a = d, i = w, u = w, l = !0;
        continue;
      }
      (m || D.areInCyclicOrder(i, w, u)) && (m = !1, D.areInCyclicOrder(i, r, w) ? (a = d, u = w) : (n = d, i = w));
    }
    return [n, a];
  }
  static midpoint(e, r) {
    return [
      (e[0] + r[0]) / 2,
      (e[1] + r[1]) / 2,
      (e[2] + r[2]) / 2
    ];
  }
  static criticalPlaneBelow(e) {
    return Math.floor(e - 0.5);
  }
  static criticalPlaneAbove(e) {
    return Math.ceil(e - 0.5);
  }
  /**
   * Finds a color with the given Y and hue on the boundary of the
   * cube.
   *
   * @param y The Y value of the color.
   * @param targetHue The hue of the color.
   * @return The desired color, in linear RGB coordinates.
   */
  static bisectToLimit(e, r) {
    const n = D.bisectToSegment(e, r);
    let a = n[0], i = D.hueOf(a), u = n[1];
    for (let l = 0; l < 3; l++)
      if (a[l] !== u[l]) {
        let m = -1, M = 255;
        a[l] < u[l] ? (m = D.criticalPlaneBelow(D.trueDelinearized(a[l])), M = D.criticalPlaneAbove(D.trueDelinearized(u[l]))) : (m = D.criticalPlaneAbove(D.trueDelinearized(a[l])), M = D.criticalPlaneBelow(D.trueDelinearized(u[l])));
        for (let d = 0; d < 8 && !(Math.abs(M - m) <= 1); d++) {
          const w = Math.floor((m + M) / 2), f = D.CRITICAL_PLANES[w], c = D.setCoordinate(a, f, u, l), s = D.hueOf(c);
          D.areInCyclicOrder(i, r, s) ? (u = c, M = w) : (a = c, i = s, m = w);
        }
      }
    return D.midpoint(a, u);
  }
  static inverseChromaticAdaptation(e) {
    const r = Math.abs(e), n = Math.max(0, 27.13 * r / (400 - r));
    return N(e) * Math.pow(n, 1 / 0.42);
  }
  /**
   * Finds a color with the given hue, chroma, and Y.
   *
   * @param hueRadians The desired hue in radians.
   * @param chroma The desired chroma.
   * @param y The desired Y.
   * @return The desired color as a hexadecimal integer, if found; 0
   * otherwise.
   */
  static findResultByJ(e, r, n) {
    let a = Math.sqrt(n) * 11;
    const i = X.DEFAULT, u = 1 / Math.pow(1.64 - Math.pow(0.29, i.n), 0.73), m = 0.25 * (Math.cos(e + 2) + 3.8) * (5e4 / 13) * i.nc * i.ncb, M = Math.sin(e), d = Math.cos(e);
    for (let w = 0; w < 5; w++) {
      const f = a / 100, c = r === 0 || a === 0 ? 0 : r / Math.sqrt(f), s = Math.pow(c * u, 1 / 0.9), y = i.aw * Math.pow(f, 1 / i.c / i.z) / i.nbb, p = 23 * (y + 0.305) * s / (23 * m + 11 * s * d + 108 * s * M), A = p * d, b = p * M, R = (460 * y + 451 * A + 288 * b) / 1403, g = (460 * y - 891 * A - 261 * b) / 1403, T = (460 * y - 220 * A - 6300 * b) / 1403, C = D.inverseChromaticAdaptation(R), F = D.inverseChromaticAdaptation(g), B = D.inverseChromaticAdaptation(T), x = pt([C, F, B], D.LINRGB_FROM_SCALED_DISCOUNT);
      if (x[0] < 0 || x[1] < 0 || x[2] < 0)
        return 0;
      const z = D.Y_FROM_LINRGB[0], O = D.Y_FROM_LINRGB[1], S = D.Y_FROM_LINRGB[2], v = z * x[0] + O * x[1] + S * x[2];
      if (v <= 0)
        return 0;
      if (w === 4 || Math.abs(v - n) < 2e-3)
        return x[0] > 100.01 || x[1] > 100.01 || x[2] > 100.01 ? 0 : Dt(x);
      a = a - (v - n) * a / (2 * v);
    }
    return 0;
  }
  /**
   * Finds an sRGB color with the given hue, chroma, and L*, if
   * possible.
   *
   * @param hueDegrees The desired hue, in degrees.
   * @param chroma The desired chroma.
   * @param lstar The desired L*.
   * @return A hexadecimal representing the sRGB color. The color
   * has sufficiently close hue, chroma, and L* to the desired
   * values, if possible; otherwise, the hue and L* will be
   * sufficiently close, and chroma will be maximized.
   */
  static solveToInt(e, r, n) {
    if (r < 1e-4 || n < 1e-4 || n > 99.9999)
      return Nt(n);
    e = W(e);
    const a = e / 180 * Math.PI, i = tt(n), u = D.findResultByJ(a, r, i);
    if (u !== 0)
      return u;
    const l = D.bisectToLimit(i, a);
    return Dt(l);
  }
  /**
   * Finds an sRGB color with the given hue, chroma, and L*, if
   * possible.
   *
   * @param hueDegrees The desired hue, in degrees.
   * @param chroma The desired chroma.
   * @param lstar The desired L*.
   * @return An CAM16 object representing the sRGB color. The color
   * has sufficiently close hue, chroma, and L* to the desired
   * values, if possible; otherwise, the hue and L* will be
   * sufficiently close, and chroma will be maximized.
   */
  static solveToCam(e, r, n) {
    return Y.fromInt(D.solveToInt(e, r, n));
  }
}
D.SCALED_DISCOUNT_FROM_LINRGB = [
  [
    0.001200833568784504,
    0.002389694492170889,
    2795742885861124e-19
  ],
  [
    5891086651375999e-19,
    0.0029785502573438758,
    3270666104008398e-19
  ],
  [
    10146692491640572e-20,
    5364214359186694e-19,
    0.0032979401770712076
  ]
];
D.LINRGB_FROM_SCALED_DISCOUNT = [
  [
    1373.2198709594231,
    -1100.4251190754821,
    -7.278681089101213
  ],
  [
    -271.815969077903,
    559.6580465940733,
    -32.46047482791194
  ],
  [
    1.9622899599665666,
    -57.173814538844006,
    308.7233197812385
  ]
];
D.Y_FROM_LINRGB = [0.2126, 0.7152, 0.0722];
D.CRITICAL_PLANES = [
  0.015176349177441876,
  0.045529047532325624,
  0.07588174588720938,
  0.10623444424209313,
  0.13658714259697685,
  0.16693984095186062,
  0.19729253930674434,
  0.2276452376616281,
  0.2579979360165119,
  0.28835063437139563,
  0.3188300904430532,
  0.350925934958123,
  0.3848314933096426,
  0.42057480301049466,
  0.458183274052838,
  0.4976837250274023,
  0.5391024159806381,
  0.5824650784040898,
  0.6277969426914107,
  0.6751227633498623,
  0.7244668422128921,
  0.775853049866786,
  0.829304845476233,
  0.8848452951698498,
  0.942497089126609,
  1.0022825574869039,
  1.0642236851973577,
  1.1283421258858297,
  1.1946592148522128,
  1.2631959812511864,
  1.3339731595349034,
  1.407011200216447,
  1.4823302800086415,
  1.5599503113873272,
  1.6398909516233677,
  1.7221716113234105,
  1.8068114625156377,
  1.8938294463134073,
  1.9832442801866852,
  2.075074464868551,
  2.1693382909216234,
  2.2660538449872063,
  2.36523901573795,
  2.4669114995532007,
  2.5710888059345764,
  2.6777882626779785,
  2.7870270208169257,
  2.898822059350997,
  3.0131901897720907,
  3.1301480604002863,
  3.2497121605402226,
  3.3718988244681087,
  3.4967242352587946,
  3.624204428461639,
  3.754355295633311,
  3.887192587735158,
  4.022731918402185,
  4.160988767090289,
  4.301978482107941,
  4.445716283538092,
  4.592217266055746,
  4.741496401646282,
  4.893568542229298,
  5.048448422192488,
  5.20615066083972,
  5.3666897647573375,
  5.5300801301023865,
  5.696336044816294,
  5.865471690767354,
  6.037501145825082,
  6.212438385869475,
  6.390297286737924,
  6.571091626112461,
  6.7548350853498045,
  6.941541251256611,
  7.131223617812143,
  7.323895587840543,
  7.5195704746346665,
  7.7182615035334345,
  7.919981813454504,
  8.124744458384042,
  8.332562408825165,
  8.543448553206703,
  8.757415699253682,
  8.974476575321063,
  9.194643831691977,
  9.417930041841839,
  9.644347703669503,
  9.873909240696694,
  10.106627003236781,
  10.342513269534024,
  10.58158024687427,
  10.8238400726681,
  11.069304815507364,
  11.317986476196008,
  11.569896988756009,
  11.825048221409341,
  12.083451977536606,
  12.345119996613247,
  12.610063955123938,
  12.878295467455942,
  13.149826086772048,
  13.42466730586372,
  13.702830557985108,
  13.984327217668513,
  14.269168601521828,
  14.55736596900856,
  14.848930523210871,
  15.143873411576273,
  15.44220572664832,
  15.743938506781891,
  16.04908273684337,
  16.35764934889634,
  16.66964922287304,
  16.985093187232053,
  17.30399201960269,
  17.62635644741625,
  17.95219714852476,
  18.281524751807332,
  18.614349837764564,
  18.95068293910138,
  19.290534541298456,
  19.633915083172692,
  19.98083495742689,
  20.331304511189067,
  20.685334046541502,
  21.042933821039977,
  21.404114048223256,
  21.76888489811322,
  22.137256497705877,
  22.50923893145328,
  22.884842241736916,
  23.264076429332462,
  23.6469514538663,
  24.033477234264016,
  24.42366364919083,
  24.817520537484558,
  25.21505769858089,
  25.61628489293138,
  26.021211842414342,
  26.429848230738664,
  26.842203703840827,
  27.258287870275353,
  27.678110301598522,
  28.10168053274597,
  28.529008062403893,
  28.96010235337422,
  29.39497283293396,
  29.83362889318845,
  30.276079891419332,
  30.722335150426627,
  31.172403958865512,
  31.62629557157785,
  32.08401920991837,
  32.54558406207592,
  33.010999283389665,
  33.4802739966603,
  33.953417292456834,
  34.430438229418264,
  34.911345834551085,
  35.39614910352207,
  35.88485700094671,
  36.37747846067349,
  36.87402238606382,
  37.37449765026789,
  37.87891309649659,
  38.38727753828926,
  38.89959975977785,
  39.41588851594697,
  39.93615253289054,
  40.460400508064545,
  40.98864111053629,
  41.520882981230194,
  42.05713473317016,
  42.597404951718396,
  43.141702194811224,
  43.6900349931913,
  44.24241185063697,
  44.798841244188324,
  45.35933162437017,
  45.92389141541209,
  46.49252901546552,
  47.065252796817916,
  47.64207110610409,
  48.22299226451468,
  48.808024568002054,
  49.3971762874833,
  49.9904556690408,
  50.587870934119984,
  51.189430279724725,
  51.79514187861014,
  52.40501387947288,
  53.0190544071392,
  53.637271562750364,
  54.259673423945976,
  54.88626804504493,
  55.517063457223934,
  56.15206766869424,
  56.79128866487574,
  57.43473440856916,
  58.08241284012621,
  58.734331877617365,
  59.39049941699807,
  60.05092333227251,
  60.715611475655585,
  61.38457167773311,
  62.057811747619894,
  62.7353394731159,
  63.417162620860914,
  64.10328893648692,
  64.79372614476921,
  65.48848194977529,
  66.18756403501224,
  66.89098006357258,
  67.59873767827808,
  68.31084450182222,
  69.02730813691093,
  69.74813616640164,
  70.47333615344107,
  71.20291564160104,
  71.93688215501312,
  72.67524319850172,
  73.41800625771542,
  74.16517879925733,
  74.9167682708136,
  75.67278210128072,
  76.43322770089146,
  77.1981124613393,
  77.96744375590167,
  78.74122893956174,
  79.51947534912904,
  80.30219030335869,
  81.08938110306934,
  81.88105503125999,
  82.67721935322541,
  83.4778813166706,
  84.28304815182372,
  85.09272707154808,
  85.90692527145302,
  86.72564993000343,
  87.54890820862819,
  88.3767072518277,
  89.2090541872801,
  90.04595612594655,
  90.88742016217518,
  91.73345337380438,
  92.58406282226491,
  93.43925555268066,
  94.29903859396902,
  95.16341895893969,
  96.03240364439274,
  96.9059996312159,
  97.78421388448044,
  98.6670533535366,
  99.55452497210776
];
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class _ {
  static from(e, r, n) {
    return new _(D.solveToInt(e, r, n));
  }
  /**
   * @param argb ARGB representation of a color.
   * @return HCT representation of a color in default viewing conditions
   */
  static fromInt(e) {
    return new _(e);
  }
  toInt() {
    return this.argb;
  }
  /**
   * A number, in degrees, representing ex. red, orange, yellow, etc.
   * Ranges from 0 <= hue < 360.
   */
  get hue() {
    return this.internalHue;
  }
  /**
   * @param newHue 0 <= newHue < 360; invalid values are corrected.
   * Chroma may decrease because chroma has a different maximum for any given
   * hue and tone.
   */
  set hue(e) {
    this.setInternalState(D.solveToInt(e, this.internalChroma, this.internalTone));
  }
  get chroma() {
    return this.internalChroma;
  }
  /**
   * @param newChroma 0 <= newChroma < ?
   * Chroma may decrease because chroma has a different maximum for any given
   * hue and tone.
   */
  set chroma(e) {
    this.setInternalState(D.solveToInt(this.internalHue, e, this.internalTone));
  }
  /** Lightness. Ranges from 0 to 100. */
  get tone() {
    return this.internalTone;
  }
  /**
   * @param newTone 0 <= newTone <= 100; invalid valids are corrected.
   * Chroma may decrease because chroma has a different maximum for any given
   * hue and tone.
   */
  set tone(e) {
    this.setInternalState(D.solveToInt(this.internalHue, this.internalChroma, e));
  }
  constructor(e) {
    this.argb = e;
    const r = Y.fromInt(e);
    this.internalHue = r.hue, this.internalChroma = r.chroma, this.internalTone = Tt(e), this.argb = e;
  }
  setInternalState(e) {
    const r = Y.fromInt(e);
    this.internalHue = r.hue, this.internalChroma = r.chroma, this.internalTone = Tt(e), this.argb = e;
  }
  /**
   * Translates a color into different [ViewingConditions].
   *
   * Colors change appearance. They look different with lights on versus off,
   * the same color, as in hex code, on white looks different when on black.
   * This is called color relativity, most famously explicated by Josef Albers
   * in Interaction of Color.
   *
   * In color science, color appearance models can account for this and
   * calculate the appearance of a color in different settings. HCT is based on
   * CAM16, a color appearance model, and uses it to make these calculations.
   *
   * See [ViewingConditions.make] for parameters affecting color appearance.
   */
  inViewingConditions(e) {
    const n = Y.fromInt(this.toInt()).xyzInViewingConditions(e), a = Y.fromXyzInViewingConditions(n[0], n[1], n[2], X.make());
    return _.from(a.hue, a.chroma, yt(n[1]));
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class E {
  /**
   * Returns a contrast ratio, which ranges from 1 to 21.
   *
   * @param toneA Tone between 0 and 100. Values outside will be clamped.
   * @param toneB Tone between 0 and 100. Values outside will be clamped.
   */
  static ratioOfTones(e, r) {
    return e = ht(0, 100, e), r = ht(0, 100, r), E.ratioOfYs(tt(e), tt(r));
  }
  static ratioOfYs(e, r) {
    const n = e > r ? e : r, a = n === r ? e : r;
    return (n + 5) / (a + 5);
  }
  /**
   * Returns a tone >= tone parameter that ensures ratio parameter.
   * Return value is between 0 and 100.
   * Returns -1 if ratio cannot be achieved with tone parameter.
   *
   * @param tone Tone return value must contrast with.
   * Range is 0 to 100. Invalid values will result in -1 being returned.
   * @param ratio Contrast ratio of return value and tone.
   * Range is 1 to 21, invalid values have undefined behavior.
   */
  static lighter(e, r) {
    if (e < 0 || e > 100)
      return -1;
    const n = tt(e), a = r * (n + 5) - 5, i = E.ratioOfYs(a, n), u = Math.abs(i - r);
    if (i < r && u > 0.04)
      return -1;
    const l = yt(a) + 0.4;
    return l < 0 || l > 100 ? -1 : l;
  }
  /**
   * Returns a tone <= tone parameter that ensures ratio parameter.
   * Return value is between 0 and 100.
   * Returns -1 if ratio cannot be achieved with tone parameter.
   *
   * @param tone Tone return value must contrast with.
   * Range is 0 to 100. Invalid values will result in -1 being returned.
   * @param ratio Contrast ratio of return value and tone.
   * Range is 1 to 21, invalid values have undefined behavior.
   */
  static darker(e, r) {
    if (e < 0 || e > 100)
      return -1;
    const n = tt(e), a = (n + 5) / r - 5, i = E.ratioOfYs(n, a), u = Math.abs(i - r);
    if (i < r && u > 0.04)
      return -1;
    const l = yt(a) - 0.4;
    return l < 0 || l > 100 ? -1 : l;
  }
  /**
   * Returns a tone >= tone parameter that ensures ratio parameter.
   * Return value is between 0 and 100.
   * Returns 100 if ratio cannot be achieved with tone parameter.
   *
   * This method is unsafe because the returned value is guaranteed to be in
   * bounds for tone, i.e. between 0 and 100. However, that value may not reach
   * the ratio with tone. For example, there is no color lighter than T100.
   *
   * @param tone Tone return value must contrast with.
   * Range is 0 to 100. Invalid values will result in 100 being returned.
   * @param ratio Desired contrast ratio of return value and tone parameter.
   * Range is 1 to 21, invalid values have undefined behavior.
   */
  static lighterUnsafe(e, r) {
    const n = E.lighter(e, r);
    return n < 0 ? 100 : n;
  }
  /**
   * Returns a tone >= tone parameter that ensures ratio parameter.
   * Return value is between 0 and 100.
   * Returns 100 if ratio cannot be achieved with tone parameter.
   *
   * This method is unsafe because the returned value is guaranteed to be in
   * bounds for tone, i.e. between 0 and 100. However, that value may not reach
   * the [ratio with [tone]. For example, there is no color darker than T0.
   *
   * @param tone Tone return value must contrast with.
   * Range is 0 to 100. Invalid values will result in 0 being returned.
   * @param ratio Desired contrast ratio of return value and tone parameter.
   * Range is 1 to 21, invalid values have undefined behavior.
   */
  static darkerUnsafe(e, r) {
    const n = E.darker(e, r);
    return n < 0 ? 0 : n;
  }
}
/**
 * @license
 * Copyright 2023 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class ct {
  /**
   * Returns true if a color is disliked.
   *
   * @param hct A color to be judged.
   * @return Whether the color is disliked.
   *
   * Disliked is defined as a dark yellow-green that is not neutral.
   */
  static isDisliked(e) {
    const r = Math.round(e.hue) >= 90 && Math.round(e.hue) <= 111, n = Math.round(e.chroma) > 16, a = Math.round(e.tone) < 65;
    return r && n && a;
  }
  /**
   * If a color is disliked, lighten it to make it likable.
   *
   * @param hct A color to be judged.
   * @return A new color if the original color is disliked, or the original
   *   color if it is acceptable.
   */
  static fixIfDisliked(e) {
    return ct.isDisliked(e) ? _.from(e.hue, e.chroma, 70) : e;
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class P {
  /**
   * Create a DynamicColor defined by a TonalPalette and HCT tone.
   *
   * @param args Functions with DynamicScheme as input. Must provide a palette
   * and tone. May provide a background DynamicColor and ToneDeltaConstraint.
   */
  static fromPalette(e) {
    return new P(e.name ?? "", e.palette, e.tone, e.isBackground ?? !1, e.background, e.secondBackground, e.contrastCurve, e.toneDeltaPair);
  }
  /**
   * The base constructor for DynamicColor.
   *
   * _Strongly_ prefer using one of the convenience constructors. This class is
   * arguably too flexible to ensure it can support any scenario. Functional
   * arguments allow  overriding without risks that come with subclasses.
   *
   * For example, the default behavior of adjust tone at max contrast
   * to be at a 7.0 ratio with its background is principled and
   * matches accessibility guidance. That does not mean it's the desired
   * approach for _every_ design system, and every color pairing,
   * always, in every case.
   *
   * @param name The name of the dynamic color. Defaults to empty.
   * @param palette Function that provides a TonalPalette given
   * DynamicScheme. A TonalPalette is defined by a hue and chroma, so this
   * replaces the need to specify hue/chroma. By providing a tonal palette, when
   * contrast adjustments are made, intended chroma can be preserved.
   * @param tone Function that provides a tone, given a DynamicScheme.
   * @param isBackground Whether this dynamic color is a background, with
   * some other color as the foreground. Defaults to false.
   * @param background The background of the dynamic color (as a function of a
   *     `DynamicScheme`), if it exists.
   * @param secondBackground A second background of the dynamic color (as a
   *     function of a `DynamicScheme`), if it
   * exists.
   * @param contrastCurve A `ContrastCurve` object specifying how its contrast
   * against its background should behave in various contrast levels options.
   * @param toneDeltaPair A `ToneDeltaPair` object specifying a tone delta
   * constraint between two colors. One of them must be the color being
   * constructed.
   */
  constructor(e, r, n, a, i, u, l, m) {
    if (this.name = e, this.palette = r, this.tone = n, this.isBackground = a, this.background = i, this.secondBackground = u, this.contrastCurve = l, this.toneDeltaPair = m, this.hctCache = /* @__PURE__ */ new Map(), !i && u)
      throw new Error(`Color ${e} has secondBackgrounddefined, but background is not defined.`);
    if (!i && l)
      throw new Error(`Color ${e} has contrastCurvedefined, but background is not defined.`);
    if (i && !l)
      throw new Error(`Color ${e} has backgrounddefined, but contrastCurve is not defined.`);
  }
  /**
   * Return a ARGB integer (i.e. a hex code).
   *
   * @param scheme Defines the conditions of the user interface, for example,
   * whether or not it is dark mode or light mode, and what the desired
   * contrast level is.
   */
  getArgb(e) {
    return this.getHct(e).toInt();
  }
  /**
   * Return a color, expressed in the HCT color space, that this
   * DynamicColor is under the conditions in scheme.
   *
   * @param scheme Defines the conditions of the user interface, for example,
   * whether or not it is dark mode or light mode, and what the desired
   * contrast level is.
   */
  getHct(e) {
    const r = this.hctCache.get(e);
    if (r != null)
      return r;
    const n = this.getTone(e), a = this.palette(e).getHct(n);
    return this.hctCache.size > 4 && this.hctCache.clear(), this.hctCache.set(e, a), a;
  }
  /**
   * Return a tone, T in the HCT color space, that this DynamicColor is under
   * the conditions in scheme.
   *
   * @param scheme Defines the conditions of the user interface, for example,
   * whether or not it is dark mode or light mode, and what the desired
   * contrast level is.
   */
  getTone(e) {
    const r = e.contrastLevel < 0;
    if (this.toneDeltaPair) {
      const n = this.toneDeltaPair(e), a = n.roleA, i = n.roleB, u = n.delta, l = n.polarity, m = n.stayTogether, d = this.background(e).getTone(e), w = l === "nearer" || l === "lighter" && !e.isDark || l === "darker" && e.isDark, f = w ? a : i, c = w ? i : a, s = this.name === f.name, h = e.isDark ? 1 : -1, y = f.contrastCurve.get(e.contrastLevel), p = c.contrastCurve.get(e.contrastLevel), A = f.tone(e);
      let b = E.ratioOfTones(d, A) >= y ? A : P.foregroundTone(d, y);
      const R = c.tone(e);
      let g = E.ratioOfTones(d, R) >= p ? R : P.foregroundTone(d, p);
      return r && (b = P.foregroundTone(d, y), g = P.foregroundTone(d, p)), (g - b) * h >= u || (g = ht(0, 100, b + u * h), (g - b) * h >= u || (b = ht(0, 100, g - u * h))), 50 <= b && b < 60 ? h > 0 ? (b = 60, g = Math.max(g, b + u * h)) : (b = 49, g = Math.min(g, b + u * h)) : 50 <= g && g < 60 && (m ? h > 0 ? (b = 60, g = Math.max(g, b + u * h)) : (b = 49, g = Math.min(g, b + u * h)) : h > 0 ? g = 60 : g = 49), s ? b : g;
    } else {
      let n = this.tone(e);
      if (this.background == null)
        return n;
      const a = this.background(e).getTone(e), i = this.contrastCurve.get(e.contrastLevel);
      if (E.ratioOfTones(a, n) >= i || (n = P.foregroundTone(a, i)), r && (n = P.foregroundTone(a, i)), this.isBackground && 50 <= n && n < 60 && (E.ratioOfTones(49, a) >= i ? n = 49 : n = 60), this.secondBackground) {
        const [u, l] = [this.background, this.secondBackground], [m, M] = [u(e).getTone(e), l(e).getTone(e)], [d, w] = [Math.max(m, M), Math.min(m, M)];
        if (E.ratioOfTones(d, n) >= i && E.ratioOfTones(w, n) >= i)
          return n;
        const f = E.lighter(d, i), c = E.darker(w, i), s = [];
        return f !== -1 && s.push(f), c !== -1 && s.push(c), P.tonePrefersLightForeground(m) || P.tonePrefersLightForeground(M) ? f < 0 ? 100 : f : s.length === 1 ? s[0] : c < 0 ? 0 : c;
      }
      return n;
    }
  }
  /**
   * Given a background tone, find a foreground tone, while ensuring they reach
   * a contrast ratio that is as close to [ratio] as possible.
   *
   * @param bgTone Tone in HCT. Range is 0 to 100, undefined behavior when it
   *     falls outside that range.
   * @param ratio The contrast ratio desired between bgTone and the return
   *     value.
   */
  static foregroundTone(e, r) {
    const n = E.lighterUnsafe(e, r), a = E.darkerUnsafe(e, r), i = E.ratioOfTones(n, e), u = E.ratioOfTones(a, e);
    if (P.tonePrefersLightForeground(e)) {
      const m = Math.abs(i - u) < 0.1 && i < r && u < r;
      return i >= r || i >= u || m ? n : a;
    } else
      return u >= r || u >= i ? a : n;
  }
  /**
   * Returns whether [tone] prefers a light foreground.
   *
   * People prefer white foregrounds on ~T60-70. Observed over time, and also
   * by Andrew Somers during research for APCA.
   *
   * T60 used as to create the smallest discontinuity possible when skipping
   * down to T49 in order to ensure light foregrounds.
   * Since `tertiaryContainer` in dark monochrome scheme requires a tone of
   * 60, it should not be adjusted. Therefore, 60 is excluded here.
   */
  static tonePrefersLightForeground(e) {
    return Math.round(e) < 60;
  }
  /**
   * Returns whether [tone] can reach a contrast ratio of 4.5 with a lighter
   * color.
   */
  static toneAllowsLightForeground(e) {
    return Math.round(e) <= 49;
  }
  /**
   * Adjust a tone such that white has 4.5 contrast, if the tone is
   * reasonably close to supporting it.
   */
  static enableLightForeground(e) {
    return P.tonePrefersLightForeground(e) && !P.toneAllowsLightForeground(e) ? 49 : e;
  }
}
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class k {
  /**
   * @param argb ARGB representation of a color
   * @return Tones matching that color's hue and chroma.
   */
  static fromInt(e) {
    const r = _.fromInt(e);
    return k.fromHct(r);
  }
  /**
   * @param hct Hct
   * @return Tones matching that color's hue and chroma.
   */
  static fromHct(e) {
    return new k(e.hue, e.chroma, e);
  }
  /**
   * @param hue HCT hue
   * @param chroma HCT chroma
   * @return Tones matching hue and chroma.
   */
  static fromHueAndChroma(e, r) {
    const n = new Ht(e, r).create();
    return new k(e, r, n);
  }
  constructor(e, r, n) {
    this.hue = e, this.chroma = r, this.keyColor = n, this.cache = /* @__PURE__ */ new Map();
  }
  /**
   * @param tone HCT tone, measured from 0 to 100.
   * @return ARGB representation of a color with that tone.
   */
  tone(e) {
    let r = this.cache.get(e);
    return r === void 0 && (r = _.from(this.hue, this.chroma, e).toInt(), this.cache.set(e, r)), r;
  }
  /**
   * @param tone HCT tone.
   * @return HCT representation of a color with that tone.
   */
  getHct(e) {
    return _.fromInt(this.tone(e));
  }
}
class Ht {
  constructor(e, r) {
    this.hue = e, this.requestedChroma = r, this.chromaCache = /* @__PURE__ */ new Map(), this.maxChromaValue = 200;
  }
  /**
   * Creates a key color from a [hue] and a [chroma].
   * The key color is the first tone, starting from T50, matching the given hue
   * and chroma.
   *
   * @return Key color [Hct]
   */
  create() {
    let a = 0, i = 100;
    for (; a < i; ) {
      const u = Math.floor((a + i) / 2), l = this.maxChroma(u) < this.maxChroma(u + 1);
      if (this.maxChroma(u) >= this.requestedChroma - 0.01)
        if (Math.abs(a - 50) < Math.abs(i - 50))
          i = u;
        else {
          if (a === u)
            return _.from(this.hue, this.requestedChroma, a);
          a = u;
        }
      else
        l ? a = u + 1 : i = u;
    }
    return _.from(this.hue, this.requestedChroma, a);
  }
  // Find the maximum chroma for a given tone
  maxChroma(e) {
    if (this.chromaCache.has(e))
      return this.chromaCache.get(e);
    const r = _.from(this.hue, this.maxChromaValue, e).chroma;
    return this.chromaCache.set(e, r), r;
  }
}
/**
 * @license
 * Copyright 2023 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class I {
  /**
   * Creates a `ContrastCurve` object.
   *
   * @param low Value for contrast level -1.0
   * @param normal Value for contrast level 0.0
   * @param medium Value for contrast level 0.5
   * @param high Value for contrast level 1.0
   */
  constructor(e, r, n, a) {
    this.low = e, this.normal = r, this.medium = n, this.high = a;
  }
  /**
   * Returns the value at a given contrast level.
   *
   * @param contrastLevel The contrast level. 0.0 is the default (normal); -1.0
   *     is the lowest; 1.0 is the highest.
   * @return The value. For contrast ratios, a number between 1.0 and 21.0.
   */
  get(e) {
    return e <= -1 ? this.low : e < 0 ? st(this.low, this.normal, (e - -1) / 1) : e < 0.5 ? st(this.normal, this.medium, (e - 0) / 0.5) : e < 1 ? st(this.medium, this.high, (e - 0.5) / 0.5) : this.high;
  }
}
/**
 * @license
 * Copyright 2023 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class H {
  /**
   * Documents a constraint in tone distance between two DynamicColors.
   *
   * The polarity is an adjective that describes "A", compared to "B".
   *
   * For instance, ToneDeltaPair(A, B, 15, 'darker', stayTogether) states that
   * A's tone should be at least 15 darker than B's.
   *
   * 'nearer' and 'farther' describes closeness to the surface roles. For
   * instance, ToneDeltaPair(A, B, 10, 'nearer', stayTogether) states that A
   * should be 10 lighter than B in light mode, and 10 darker than B in dark
   * mode.
   *
   * @param roleA The first role in a pair.
   * @param roleB The second role in a pair.
   * @param delta Required difference between tones. Absolute value, negative
   * values have undefined behavior.
   * @param polarity The relative relation between tones of roleA and roleB,
   * as described above.
   * @param stayTogether Whether these two roles should stay on the same side of
   * the "awkward zone" (T50-59). This is necessary for certain cases where
   * one role has two backgrounds.
   */
  constructor(e, r, n, a, i) {
    this.roleA = e, this.roleB = r, this.delta = n, this.polarity = a, this.stayTogether = i;
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var q;
(function(t) {
  t[t.MONOCHROME = 0] = "MONOCHROME", t[t.NEUTRAL = 1] = "NEUTRAL", t[t.TONAL_SPOT = 2] = "TONAL_SPOT", t[t.VIBRANT = 3] = "VIBRANT", t[t.EXPRESSIVE = 4] = "EXPRESSIVE", t[t.FIDELITY = 5] = "FIDELITY", t[t.CONTENT = 6] = "CONTENT", t[t.RAINBOW = 7] = "RAINBOW", t[t.FRUIT_SALAD = 8] = "FRUIT_SALAD";
})(q || (q = {}));
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function ot(t) {
  return t.variant === q.FIDELITY || t.variant === q.CONTENT;
}
function L(t) {
  return t.variant === q.MONOCHROME;
}
function Ut(t, e, r, n) {
  let a = r, i = _.from(t, e, r);
  if (i.chroma < e) {
    let u = i.chroma;
    for (; i.chroma < e; ) {
      a += n ? -1 : 1;
      const l = _.from(t, e, a);
      if (u > l.chroma || Math.abs(l.chroma - e) < 0.4)
        break;
      const m = Math.abs(l.chroma - e), M = Math.abs(i.chroma - e);
      m < M && (i = l), u = Math.max(u, l.chroma);
    }
  }
  return a;
}
class o {
  static highestSurface(e) {
    return e.isDark ? o.surfaceBright : o.surfaceDim;
  }
}
o.contentAccentToneDelta = 15;
o.primaryPaletteKeyColor = P.fromPalette({
  name: "primary_palette_key_color",
  palette: (t) => t.primaryPalette,
  tone: (t) => t.primaryPalette.keyColor.tone
});
o.secondaryPaletteKeyColor = P.fromPalette({
  name: "secondary_palette_key_color",
  palette: (t) => t.secondaryPalette,
  tone: (t) => t.secondaryPalette.keyColor.tone
});
o.tertiaryPaletteKeyColor = P.fromPalette({
  name: "tertiary_palette_key_color",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => t.tertiaryPalette.keyColor.tone
});
o.neutralPaletteKeyColor = P.fromPalette({
  name: "neutral_palette_key_color",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.neutralPalette.keyColor.tone
});
o.neutralVariantPaletteKeyColor = P.fromPalette({
  name: "neutral_variant_palette_key_color",
  palette: (t) => t.neutralVariantPalette,
  tone: (t) => t.neutralVariantPalette.keyColor.tone
});
o.background = P.fromPalette({
  name: "background",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? 6 : 98,
  isBackground: !0
});
o.onBackground = P.fromPalette({
  name: "on_background",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? 90 : 10,
  background: (t) => o.background,
  contrastCurve: new I(3, 3, 4.5, 7)
});
o.surface = P.fromPalette({
  name: "surface",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? 6 : 98,
  isBackground: !0
});
o.surfaceDim = P.fromPalette({
  name: "surface_dim",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? 6 : new I(87, 87, 80, 75).get(t.contrastLevel),
  isBackground: !0
});
o.surfaceBright = P.fromPalette({
  name: "surface_bright",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? new I(24, 24, 29, 34).get(t.contrastLevel) : 98,
  isBackground: !0
});
o.surfaceContainerLowest = P.fromPalette({
  name: "surface_container_lowest",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? new I(4, 4, 2, 0).get(t.contrastLevel) : 100,
  isBackground: !0
});
o.surfaceContainerLow = P.fromPalette({
  name: "surface_container_low",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? new I(10, 10, 11, 12).get(t.contrastLevel) : new I(96, 96, 96, 95).get(t.contrastLevel),
  isBackground: !0
});
o.surfaceContainer = P.fromPalette({
  name: "surface_container",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? new I(12, 12, 16, 20).get(t.contrastLevel) : new I(94, 94, 92, 90).get(t.contrastLevel),
  isBackground: !0
});
o.surfaceContainerHigh = P.fromPalette({
  name: "surface_container_high",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? new I(17, 17, 21, 25).get(t.contrastLevel) : new I(92, 92, 88, 85).get(t.contrastLevel),
  isBackground: !0
});
o.surfaceContainerHighest = P.fromPalette({
  name: "surface_container_highest",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? new I(22, 22, 26, 30).get(t.contrastLevel) : new I(90, 90, 84, 80).get(t.contrastLevel),
  isBackground: !0
});
o.onSurface = P.fromPalette({
  name: "on_surface",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? 90 : 10,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.surfaceVariant = P.fromPalette({
  name: "surface_variant",
  palette: (t) => t.neutralVariantPalette,
  tone: (t) => t.isDark ? 30 : 90,
  isBackground: !0
});
o.onSurfaceVariant = P.fromPalette({
  name: "on_surface_variant",
  palette: (t) => t.neutralVariantPalette,
  tone: (t) => t.isDark ? 80 : 30,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(3, 4.5, 7, 11)
});
o.inverseSurface = P.fromPalette({
  name: "inverse_surface",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? 90 : 20
});
o.inverseOnSurface = P.fromPalette({
  name: "inverse_on_surface",
  palette: (t) => t.neutralPalette,
  tone: (t) => t.isDark ? 20 : 95,
  background: (t) => o.inverseSurface,
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.outline = P.fromPalette({
  name: "outline",
  palette: (t) => t.neutralVariantPalette,
  tone: (t) => t.isDark ? 60 : 50,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1.5, 3, 4.5, 7)
});
o.outlineVariant = P.fromPalette({
  name: "outline_variant",
  palette: (t) => t.neutralVariantPalette,
  tone: (t) => t.isDark ? 30 : 80,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5)
});
o.shadow = P.fromPalette({
  name: "shadow",
  palette: (t) => t.neutralPalette,
  tone: (t) => 0
});
o.scrim = P.fromPalette({
  name: "scrim",
  palette: (t) => t.neutralPalette,
  tone: (t) => 0
});
o.surfaceTint = P.fromPalette({
  name: "surface_tint",
  palette: (t) => t.primaryPalette,
  tone: (t) => t.isDark ? 80 : 40,
  isBackground: !0
});
o.primary = P.fromPalette({
  name: "primary",
  palette: (t) => t.primaryPalette,
  tone: (t) => L(t) ? t.isDark ? 100 : 0 : t.isDark ? 80 : 40,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(3, 4.5, 7, 7),
  toneDeltaPair: (t) => new H(o.primaryContainer, o.primary, 10, "nearer", !1)
});
o.onPrimary = P.fromPalette({
  name: "on_primary",
  palette: (t) => t.primaryPalette,
  tone: (t) => L(t) ? t.isDark ? 10 : 90 : t.isDark ? 20 : 100,
  background: (t) => o.primary,
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.primaryContainer = P.fromPalette({
  name: "primary_container",
  palette: (t) => t.primaryPalette,
  tone: (t) => ot(t) ? t.sourceColorHct.tone : L(t) ? t.isDark ? 85 : 25 : t.isDark ? 30 : 90,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.primaryContainer, o.primary, 10, "nearer", !1)
});
o.onPrimaryContainer = P.fromPalette({
  name: "on_primary_container",
  palette: (t) => t.primaryPalette,
  tone: (t) => ot(t) ? P.foregroundTone(o.primaryContainer.tone(t), 4.5) : L(t) ? t.isDark ? 0 : 100 : t.isDark ? 90 : 30,
  background: (t) => o.primaryContainer,
  contrastCurve: new I(3, 4.5, 7, 11)
});
o.inversePrimary = P.fromPalette({
  name: "inverse_primary",
  palette: (t) => t.primaryPalette,
  tone: (t) => t.isDark ? 40 : 80,
  background: (t) => o.inverseSurface,
  contrastCurve: new I(3, 4.5, 7, 7)
});
o.secondary = P.fromPalette({
  name: "secondary",
  palette: (t) => t.secondaryPalette,
  tone: (t) => t.isDark ? 80 : 40,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(3, 4.5, 7, 7),
  toneDeltaPair: (t) => new H(o.secondaryContainer, o.secondary, 10, "nearer", !1)
});
o.onSecondary = P.fromPalette({
  name: "on_secondary",
  palette: (t) => t.secondaryPalette,
  tone: (t) => L(t) ? t.isDark ? 10 : 100 : t.isDark ? 20 : 100,
  background: (t) => o.secondary,
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.secondaryContainer = P.fromPalette({
  name: "secondary_container",
  palette: (t) => t.secondaryPalette,
  tone: (t) => {
    const e = t.isDark ? 30 : 90;
    return L(t) ? t.isDark ? 30 : 85 : ot(t) ? Ut(t.secondaryPalette.hue, t.secondaryPalette.chroma, e, !t.isDark) : e;
  },
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.secondaryContainer, o.secondary, 10, "nearer", !1)
});
o.onSecondaryContainer = P.fromPalette({
  name: "on_secondary_container",
  palette: (t) => t.secondaryPalette,
  tone: (t) => L(t) ? t.isDark ? 90 : 10 : ot(t) ? P.foregroundTone(o.secondaryContainer.tone(t), 4.5) : t.isDark ? 90 : 30,
  background: (t) => o.secondaryContainer,
  contrastCurve: new I(3, 4.5, 7, 11)
});
o.tertiary = P.fromPalette({
  name: "tertiary",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => L(t) ? t.isDark ? 90 : 25 : t.isDark ? 80 : 40,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(3, 4.5, 7, 7),
  toneDeltaPair: (t) => new H(o.tertiaryContainer, o.tertiary, 10, "nearer", !1)
});
o.onTertiary = P.fromPalette({
  name: "on_tertiary",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => L(t) ? t.isDark ? 10 : 90 : t.isDark ? 20 : 100,
  background: (t) => o.tertiary,
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.tertiaryContainer = P.fromPalette({
  name: "tertiary_container",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => {
    if (L(t))
      return t.isDark ? 60 : 49;
    if (!ot(t))
      return t.isDark ? 30 : 90;
    const e = t.tertiaryPalette.getHct(t.sourceColorHct.tone);
    return ct.fixIfDisliked(e).tone;
  },
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.tertiaryContainer, o.tertiary, 10, "nearer", !1)
});
o.onTertiaryContainer = P.fromPalette({
  name: "on_tertiary_container",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => L(t) ? t.isDark ? 0 : 100 : ot(t) ? P.foregroundTone(o.tertiaryContainer.tone(t), 4.5) : t.isDark ? 90 : 30,
  background: (t) => o.tertiaryContainer,
  contrastCurve: new I(3, 4.5, 7, 11)
});
o.error = P.fromPalette({
  name: "error",
  palette: (t) => t.errorPalette,
  tone: (t) => t.isDark ? 80 : 40,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(3, 4.5, 7, 7),
  toneDeltaPair: (t) => new H(o.errorContainer, o.error, 10, "nearer", !1)
});
o.onError = P.fromPalette({
  name: "on_error",
  palette: (t) => t.errorPalette,
  tone: (t) => t.isDark ? 20 : 100,
  background: (t) => o.error,
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.errorContainer = P.fromPalette({
  name: "error_container",
  palette: (t) => t.errorPalette,
  tone: (t) => t.isDark ? 30 : 90,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.errorContainer, o.error, 10, "nearer", !1)
});
o.onErrorContainer = P.fromPalette({
  name: "on_error_container",
  palette: (t) => t.errorPalette,
  tone: (t) => L(t) ? t.isDark ? 90 : 10 : t.isDark ? 90 : 30,
  background: (t) => o.errorContainer,
  contrastCurve: new I(3, 4.5, 7, 11)
});
o.primaryFixed = P.fromPalette({
  name: "primary_fixed",
  palette: (t) => t.primaryPalette,
  tone: (t) => L(t) ? 40 : 90,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.primaryFixed, o.primaryFixedDim, 10, "lighter", !0)
});
o.primaryFixedDim = P.fromPalette({
  name: "primary_fixed_dim",
  palette: (t) => t.primaryPalette,
  tone: (t) => L(t) ? 30 : 80,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.primaryFixed, o.primaryFixedDim, 10, "lighter", !0)
});
o.onPrimaryFixed = P.fromPalette({
  name: "on_primary_fixed",
  palette: (t) => t.primaryPalette,
  tone: (t) => L(t) ? 100 : 10,
  background: (t) => o.primaryFixedDim,
  secondBackground: (t) => o.primaryFixed,
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.onPrimaryFixedVariant = P.fromPalette({
  name: "on_primary_fixed_variant",
  palette: (t) => t.primaryPalette,
  tone: (t) => L(t) ? 90 : 30,
  background: (t) => o.primaryFixedDim,
  secondBackground: (t) => o.primaryFixed,
  contrastCurve: new I(3, 4.5, 7, 11)
});
o.secondaryFixed = P.fromPalette({
  name: "secondary_fixed",
  palette: (t) => t.secondaryPalette,
  tone: (t) => L(t) ? 80 : 90,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.secondaryFixed, o.secondaryFixedDim, 10, "lighter", !0)
});
o.secondaryFixedDim = P.fromPalette({
  name: "secondary_fixed_dim",
  palette: (t) => t.secondaryPalette,
  tone: (t) => L(t) ? 70 : 80,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.secondaryFixed, o.secondaryFixedDim, 10, "lighter", !0)
});
o.onSecondaryFixed = P.fromPalette({
  name: "on_secondary_fixed",
  palette: (t) => t.secondaryPalette,
  tone: (t) => 10,
  background: (t) => o.secondaryFixedDim,
  secondBackground: (t) => o.secondaryFixed,
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.onSecondaryFixedVariant = P.fromPalette({
  name: "on_secondary_fixed_variant",
  palette: (t) => t.secondaryPalette,
  tone: (t) => L(t) ? 25 : 30,
  background: (t) => o.secondaryFixedDim,
  secondBackground: (t) => o.secondaryFixed,
  contrastCurve: new I(3, 4.5, 7, 11)
});
o.tertiaryFixed = P.fromPalette({
  name: "tertiary_fixed",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => L(t) ? 40 : 90,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.tertiaryFixed, o.tertiaryFixedDim, 10, "lighter", !0)
});
o.tertiaryFixedDim = P.fromPalette({
  name: "tertiary_fixed_dim",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => L(t) ? 30 : 80,
  isBackground: !0,
  background: (t) => o.highestSurface(t),
  contrastCurve: new I(1, 1, 3, 4.5),
  toneDeltaPair: (t) => new H(o.tertiaryFixed, o.tertiaryFixedDim, 10, "lighter", !0)
});
o.onTertiaryFixed = P.fromPalette({
  name: "on_tertiary_fixed",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => L(t) ? 100 : 10,
  background: (t) => o.tertiaryFixedDim,
  secondBackground: (t) => o.tertiaryFixed,
  contrastCurve: new I(4.5, 7, 11, 21)
});
o.onTertiaryFixedVariant = P.fromPalette({
  name: "on_tertiary_fixed_variant",
  palette: (t) => t.tertiaryPalette,
  tone: (t) => L(t) ? 90 : 30,
  background: (t) => o.tertiaryFixedDim,
  secondBackground: (t) => o.tertiaryFixed,
  contrastCurve: new I(3, 4.5, 7, 11)
});
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class V {
  constructor(e) {
    this.sourceColorArgb = e.sourceColorArgb, this.variant = e.variant, this.contrastLevel = e.contrastLevel, this.isDark = e.isDark, this.sourceColorHct = _.fromInt(e.sourceColorArgb), this.primaryPalette = e.primaryPalette, this.secondaryPalette = e.secondaryPalette, this.tertiaryPalette = e.tertiaryPalette, this.neutralPalette = e.neutralPalette, this.neutralVariantPalette = e.neutralVariantPalette, this.errorPalette = k.fromHueAndChroma(25, 84);
  }
  /**
   * Support design spec'ing Dynamic Color by schemes that specify hue
   * rotations that should be applied at certain breakpoints.
   * @param sourceColor the source color of the theme, in HCT.
   * @param hues The "breakpoints", i.e. the hues at which a rotation should
   * be apply.
   * @param rotations The rotation that should be applied when source color's
   * hue is >= the same index in hues array, and <= the hue at the next index
   * in hues array.
   */
  static getRotatedHue(e, r, n) {
    const a = e.hue;
    if (r.length !== n.length)
      throw new Error(`mismatch between hue length ${r.length} & rotations ${n.length}`);
    if (n.length === 1)
      return W(e.hue + n[0]);
    const i = r.length;
    for (let u = 0; u <= i - 2; u++) {
      const l = r[u], m = r[u + 1];
      if (l < a && a < m)
        return W(a + n[u]);
    }
    return a;
  }
  getArgb(e) {
    return e.getArgb(this);
  }
  getHct(e) {
    return e.getHct(this);
  }
  get primaryPaletteKeyColor() {
    return this.getArgb(o.primaryPaletteKeyColor);
  }
  get secondaryPaletteKeyColor() {
    return this.getArgb(o.secondaryPaletteKeyColor);
  }
  get tertiaryPaletteKeyColor() {
    return this.getArgb(o.tertiaryPaletteKeyColor);
  }
  get neutralPaletteKeyColor() {
    return this.getArgb(o.neutralPaletteKeyColor);
  }
  get neutralVariantPaletteKeyColor() {
    return this.getArgb(o.neutralVariantPaletteKeyColor);
  }
  get background() {
    return this.getArgb(o.background);
  }
  get onBackground() {
    return this.getArgb(o.onBackground);
  }
  get surface() {
    return this.getArgb(o.surface);
  }
  get surfaceDim() {
    return this.getArgb(o.surfaceDim);
  }
  get surfaceBright() {
    return this.getArgb(o.surfaceBright);
  }
  get surfaceContainerLowest() {
    return this.getArgb(o.surfaceContainerLowest);
  }
  get surfaceContainerLow() {
    return this.getArgb(o.surfaceContainerLow);
  }
  get surfaceContainer() {
    return this.getArgb(o.surfaceContainer);
  }
  get surfaceContainerHigh() {
    return this.getArgb(o.surfaceContainerHigh);
  }
  get surfaceContainerHighest() {
    return this.getArgb(o.surfaceContainerHighest);
  }
  get onSurface() {
    return this.getArgb(o.onSurface);
  }
  get surfaceVariant() {
    return this.getArgb(o.surfaceVariant);
  }
  get onSurfaceVariant() {
    return this.getArgb(o.onSurfaceVariant);
  }
  get inverseSurface() {
    return this.getArgb(o.inverseSurface);
  }
  get inverseOnSurface() {
    return this.getArgb(o.inverseOnSurface);
  }
  get outline() {
    return this.getArgb(o.outline);
  }
  get outlineVariant() {
    return this.getArgb(o.outlineVariant);
  }
  get shadow() {
    return this.getArgb(o.shadow);
  }
  get scrim() {
    return this.getArgb(o.scrim);
  }
  get surfaceTint() {
    return this.getArgb(o.surfaceTint);
  }
  get primary() {
    return this.getArgb(o.primary);
  }
  get onPrimary() {
    return this.getArgb(o.onPrimary);
  }
  get primaryContainer() {
    return this.getArgb(o.primaryContainer);
  }
  get onPrimaryContainer() {
    return this.getArgb(o.onPrimaryContainer);
  }
  get inversePrimary() {
    return this.getArgb(o.inversePrimary);
  }
  get secondary() {
    return this.getArgb(o.secondary);
  }
  get onSecondary() {
    return this.getArgb(o.onSecondary);
  }
  get secondaryContainer() {
    return this.getArgb(o.secondaryContainer);
  }
  get onSecondaryContainer() {
    return this.getArgb(o.onSecondaryContainer);
  }
  get tertiary() {
    return this.getArgb(o.tertiary);
  }
  get onTertiary() {
    return this.getArgb(o.onTertiary);
  }
  get tertiaryContainer() {
    return this.getArgb(o.tertiaryContainer);
  }
  get onTertiaryContainer() {
    return this.getArgb(o.onTertiaryContainer);
  }
  get error() {
    return this.getArgb(o.error);
  }
  get onError() {
    return this.getArgb(o.onError);
  }
  get errorContainer() {
    return this.getArgb(o.errorContainer);
  }
  get onErrorContainer() {
    return this.getArgb(o.onErrorContainer);
  }
  get primaryFixed() {
    return this.getArgb(o.primaryFixed);
  }
  get primaryFixedDim() {
    return this.getArgb(o.primaryFixedDim);
  }
  get onPrimaryFixed() {
    return this.getArgb(o.onPrimaryFixed);
  }
  get onPrimaryFixedVariant() {
    return this.getArgb(o.onPrimaryFixedVariant);
  }
  get secondaryFixed() {
    return this.getArgb(o.secondaryFixed);
  }
  get secondaryFixedDim() {
    return this.getArgb(o.secondaryFixedDim);
  }
  get onSecondaryFixed() {
    return this.getArgb(o.onSecondaryFixed);
  }
  get onSecondaryFixedVariant() {
    return this.getArgb(o.onSecondaryFixedVariant);
  }
  get tertiaryFixed() {
    return this.getArgb(o.tertiaryFixed);
  }
  get tertiaryFixedDim() {
    return this.getArgb(o.tertiaryFixedDim);
  }
  get onTertiaryFixed() {
    return this.getArgb(o.onTertiaryFixed);
  }
  get onTertiaryFixedVariant() {
    return this.getArgb(o.onTertiaryFixedVariant);
  }
}
/**
 * @license
 * Copyright 2023 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class at {
  constructor(e) {
    this.input = e, this.hctsByTempCache = [], this.hctsByHueCache = [], this.tempsByHctCache = /* @__PURE__ */ new Map(), this.inputRelativeTemperatureCache = -1, this.complementCache = null;
  }
  get hctsByTemp() {
    if (this.hctsByTempCache.length > 0)
      return this.hctsByTempCache;
    const e = this.hctsByHue.concat([this.input]), r = this.tempsByHct;
    return e.sort((n, a) => r.get(n) - r.get(a)), this.hctsByTempCache = e, e;
  }
  get warmest() {
    return this.hctsByTemp[this.hctsByTemp.length - 1];
  }
  get coldest() {
    return this.hctsByTemp[0];
  }
  /**
   * A set of colors with differing hues, equidistant in temperature.
   *
   * In art, this is usually described as a set of 5 colors on a color wheel
   * divided into 12 sections. This method allows provision of either of those
   * values.
   *
   * Behavior is undefined when [count] or [divisions] is 0.
   * When divisions < count, colors repeat.
   *
   * [count] The number of colors to return, includes the input color.
   * [divisions] The number of divisions on the color wheel.
   */
  analogous(e = 5, r = 12) {
    const n = Math.round(this.input.hue), a = this.hctsByHue[n];
    let i = this.relativeTemperature(a);
    const u = [a];
    let l = 0;
    for (let s = 0; s < 360; s++) {
      const h = kt(n + s), y = this.hctsByHue[h], p = this.relativeTemperature(y), A = Math.abs(p - i);
      i = p, l += A;
    }
    let m = 1;
    const M = l / r;
    let d = 0;
    for (i = this.relativeTemperature(a); u.length < r; ) {
      const s = kt(n + m), h = this.hctsByHue[s], y = this.relativeTemperature(h), p = Math.abs(y - i);
      d += p;
      const A = u.length * M;
      let b = d >= A, R = 1;
      for (; b && u.length < r; ) {
        u.push(h);
        const g = (u.length + R) * M;
        b = d >= g, R++;
      }
      if (i = y, m++, m > 360) {
        for (; u.length < r; )
          u.push(h);
        break;
      }
    }
    const w = [this.input], f = Math.floor((e - 1) / 2);
    for (let s = 1; s < f + 1; s++) {
      let h = 0 - s;
      for (; h < 0; )
        h = u.length + h;
      h >= u.length && (h = h % u.length), w.splice(0, 0, u[h]);
    }
    const c = e - f - 1;
    for (let s = 1; s < c + 1; s++) {
      let h = s;
      for (; h < 0; )
        h = u.length + h;
      h >= u.length && (h = h % u.length), w.push(u[h]);
    }
    return w;
  }
  /**
   * A color that complements the input color aesthetically.
   *
   * In art, this is usually described as being across the color wheel.
   * History of this shows intent as a color that is just as cool-warm as the
   * input color is warm-cool.
   */
  get complement() {
    if (this.complementCache != null)
      return this.complementCache;
    const e = this.coldest.hue, r = this.tempsByHct.get(this.coldest), n = this.warmest.hue, i = this.tempsByHct.get(this.warmest) - r, u = at.isBetween(this.input.hue, e, n), l = u ? n : e, m = u ? e : n, M = 1;
    let d = 1e3, w = this.hctsByHue[Math.round(this.input.hue)];
    const f = 1 - this.inputRelativeTemperature;
    for (let c = 0; c <= 360; c += 1) {
      const s = W(l + M * c);
      if (!at.isBetween(s, l, m))
        continue;
      const h = this.hctsByHue[Math.round(s)], y = (this.tempsByHct.get(h) - r) / i, p = Math.abs(f - y);
      p < d && (d = p, w = h);
    }
    return this.complementCache = w, this.complementCache;
  }
  /**
   * Temperature relative to all colors with the same chroma and tone.
   * Value on a scale from 0 to 1.
   */
  relativeTemperature(e) {
    const r = this.tempsByHct.get(this.warmest) - this.tempsByHct.get(this.coldest), n = this.tempsByHct.get(e) - this.tempsByHct.get(this.coldest);
    return r === 0 ? 0.5 : n / r;
  }
  /** Relative temperature of the input color. See [relativeTemperature]. */
  get inputRelativeTemperature() {
    return this.inputRelativeTemperatureCache >= 0 ? this.inputRelativeTemperatureCache : (this.inputRelativeTemperatureCache = this.relativeTemperature(this.input), this.inputRelativeTemperatureCache);
  }
  /** A Map with keys of HCTs in [hctsByTemp], values of raw temperature. */
  get tempsByHct() {
    if (this.tempsByHctCache.size > 0)
      return this.tempsByHctCache;
    const e = this.hctsByHue.concat([this.input]), r = /* @__PURE__ */ new Map();
    for (const n of e)
      r.set(n, at.rawTemperature(n));
    return this.tempsByHctCache = r, r;
  }
  /**
   * HCTs for all hues, with the same chroma/tone as the input.
   * Sorted ascending, hue 0 to 360.
   */
  get hctsByHue() {
    if (this.hctsByHueCache.length > 0)
      return this.hctsByHueCache;
    const e = [];
    for (let r = 0; r <= 360; r += 1) {
      const n = _.from(r, this.input.chroma, this.input.tone);
      e.push(n);
    }
    return this.hctsByHueCache = e, this.hctsByHueCache;
  }
  /** Determines if an angle is between two other angles, rotating clockwise. */
  static isBetween(e, r, n) {
    return r < n ? r <= e && e <= n : r <= e || e <= n;
  }
  /**
   * Value representing cool-warm factor of a color.
   * Values below 0 are considered cool, above, warm.
   *
   * Color science has researched emotion and harmony, which art uses to select
   * colors. Warm-cool is the foundation of analogous and complementary colors.
   * See:
   * - Li-Chen Ou's Chapter 19 in Handbook of Color Psychology (2015).
   * - Josef Albers' Interaction of Color chapters 19 and 21.
   *
   * Implementation of Ou, Woodcock and Wright's algorithm, which uses
   * L*a*b* / LCH color space.
   * Return value has these properties:
   * - Values below 0 are cool, above 0 are warm.
   * - Lower bound: -0.52 - (chroma ^ 1.07 / 20). L*a*b* chroma is infinite.
   *   Assuming max of 130 chroma, -9.66.
   * - Upper bound: -0.52 + (chroma ^ 1.07 / 20). L*a*b* chroma is infinite.
   *   Assuming max of 130 chroma, 8.61.
   */
  static rawTemperature(e) {
    const r = _t(e.toInt()), n = W(Math.atan2(r[2], r[1]) * 180 / Math.PI), a = Math.sqrt(r[1] * r[1] + r[2] * r[2]);
    return -0.5 + 0.02 * Math.pow(a, 1.07) * Math.cos(W(n - 50) * Math.PI / 180);
  }
}
/**
 * @license
 * Copyright 2023 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class Yt extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.CONTENT,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(e.hue, e.chroma),
      secondaryPalette: k.fromHueAndChroma(e.hue, Math.max(e.chroma - 32, e.chroma * 0.5)),
      tertiaryPalette: k.fromInt(ct.fixIfDisliked(new at(e).analogous(3, 6)[2]).toInt()),
      neutralPalette: k.fromHueAndChroma(e.hue, e.chroma / 8),
      neutralVariantPalette: k.fromHueAndChroma(e.hue, e.chroma / 8 + 4)
    });
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class $ extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.EXPRESSIVE,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(W(e.hue + 240), 40),
      secondaryPalette: k.fromHueAndChroma(V.getRotatedHue(e, $.hues, $.secondaryRotations), 24),
      tertiaryPalette: k.fromHueAndChroma(V.getRotatedHue(e, $.hues, $.tertiaryRotations), 32),
      neutralPalette: k.fromHueAndChroma(e.hue + 15, 8),
      neutralVariantPalette: k.fromHueAndChroma(e.hue + 15, 12)
    });
  }
}
$.hues = [
  0,
  21,
  51,
  121,
  151,
  191,
  271,
  321,
  360
];
$.secondaryRotations = [
  45,
  95,
  45,
  20,
  45,
  90,
  45,
  45,
  45
];
$.tertiaryRotations = [
  120,
  120,
  20,
  45,
  20,
  15,
  20,
  120,
  120
];
/**
 * @license
 * Copyright 2023 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class It extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.FIDELITY,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(e.hue, e.chroma),
      secondaryPalette: k.fromHueAndChroma(e.hue, Math.max(e.chroma - 32, e.chroma * 0.5)),
      tertiaryPalette: k.fromInt(ct.fixIfDisliked(new at(e).complement).toInt()),
      neutralPalette: k.fromHueAndChroma(e.hue, e.chroma / 8),
      neutralVariantPalette: k.fromHueAndChroma(e.hue, e.chroma / 8 + 4)
    });
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class Gt extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.FRUIT_SALAD,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(W(e.hue - 50), 48),
      secondaryPalette: k.fromHueAndChroma(W(e.hue - 50), 36),
      tertiaryPalette: k.fromHueAndChroma(e.hue, 36),
      neutralPalette: k.fromHueAndChroma(e.hue, 10),
      neutralVariantPalette: k.fromHueAndChroma(e.hue, 16)
    });
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class Kt extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.MONOCHROME,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(e.hue, 0),
      secondaryPalette: k.fromHueAndChroma(e.hue, 0),
      tertiaryPalette: k.fromHueAndChroma(e.hue, 0),
      neutralPalette: k.fromHueAndChroma(e.hue, 0),
      neutralVariantPalette: k.fromHueAndChroma(e.hue, 0)
    });
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class jt extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.NEUTRAL,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(e.hue, 12),
      secondaryPalette: k.fromHueAndChroma(e.hue, 8),
      tertiaryPalette: k.fromHueAndChroma(e.hue, 16),
      neutralPalette: k.fromHueAndChroma(e.hue, 2),
      neutralVariantPalette: k.fromHueAndChroma(e.hue, 2)
    });
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class Wt extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.RAINBOW,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(e.hue, 48),
      secondaryPalette: k.fromHueAndChroma(e.hue, 16),
      tertiaryPalette: k.fromHueAndChroma(W(e.hue + 60), 24),
      neutralPalette: k.fromHueAndChroma(e.hue, 0),
      neutralVariantPalette: k.fromHueAndChroma(e.hue, 0)
    });
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class Xt extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.TONAL_SPOT,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(e.hue, 36),
      secondaryPalette: k.fromHueAndChroma(e.hue, 16),
      tertiaryPalette: k.fromHueAndChroma(W(e.hue + 60), 24),
      neutralPalette: k.fromHueAndChroma(e.hue, 6),
      neutralVariantPalette: k.fromHueAndChroma(e.hue, 8)
    });
  }
}
/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class Q extends V {
  constructor(e, r, n) {
    super({
      sourceColorArgb: e.toInt(),
      variant: q.VIBRANT,
      contrastLevel: n,
      isDark: r,
      primaryPalette: k.fromHueAndChroma(e.hue, 200),
      secondaryPalette: k.fromHueAndChroma(V.getRotatedHue(e, Q.hues, Q.secondaryRotations), 24),
      tertiaryPalette: k.fromHueAndChroma(V.getRotatedHue(e, Q.hues, Q.tertiaryRotations), 32),
      neutralPalette: k.fromHueAndChroma(e.hue, 10),
      neutralVariantPalette: k.fromHueAndChroma(e.hue, 12)
    });
  }
}
Q.hues = [
  0,
  41,
  61,
  101,
  131,
  181,
  251,
  301,
  360
];
Q.secondaryRotations = [
  18,
  15,
  10,
  12,
  15,
  18,
  15,
  12,
  12
];
Q.tertiaryRotations = [
  35,
  30,
  20,
  25,
  30,
  35,
  30,
  25,
  25
];
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function Jt(t) {
  const e = bt(t), r = Pt(t), n = Mt(t), a = [e.toString(16), r.toString(16), n.toString(16)];
  for (const [i, u] of a.entries())
    u.length === 1 && (a[i] = "0" + u);
  return "#" + a.join("");
}
function $t(t) {
  t = t.replace("#", "");
  const e = t.length === 3, r = t.length === 6, n = t.length === 8;
  if (!e && !r && !n)
    throw new Error("unexpected hex " + t);
  let a = 0, i = 0, u = 0;
  return e ? (a = J(t.slice(0, 1).repeat(2)), i = J(t.slice(1, 2).repeat(2)), u = J(t.slice(2, 3).repeat(2))) : r ? (a = J(t.slice(0, 2)), i = J(t.slice(2, 4)), u = J(t.slice(4, 6))) : n && (a = J(t.slice(2, 4)), i = J(t.slice(4, 6)), u = J(t.slice(6, 8))), (255 << 24 | (a & 255) << 16 | (i & 255) << 8 | u & 255) >>> 0;
}
function J(t) {
  return parseInt(t, 16);
}
const Qt = {
  default: 0,
  medium: 0.5,
  high: 1,
  reduced: -1
};
function Zt(t, e, r, n, a) {
  switch (e) {
    case "monochrome":
      return new Kt(t, r, n);
    case "neutral":
      return new jt(t, r, n);
    case "tonal_spot":
      return new Xt(t, r, n);
    case "vibrant":
      return new Q(t, r, n);
    case "expressive":
      return new $(t, r, n);
    case "fidelity":
      return new It(t, r, n);
    case "content":
      return new Yt(t, r, n);
    case "rainbow":
      return new Wt(t, r, n);
    case "fruit_salad":
      return new Gt(t, r, n);
    case "image_fidelity":
      const i = new It(
        t,
        r,
        n
      );
      return new V({
        sourceColorArgb: i.sourceColorArgb,
        variant: i.variant,
        isDark: i.isDark,
        contrastLevel: i.contrastLevel,
        primaryPalette: k.fromInt(
          a[0] ?? i.primaryPaletteKeyColor
        ),
        secondaryPalette: k.fromInt(
          a[1] ?? i.secondaryPaletteKeyColor
        ),
        tertiaryPalette: k.fromInt(
          a[2] ?? i.tertiaryPaletteKeyColor
        ),
        neutralPalette: i.neutralPalette,
        neutralVariantPalette: i.neutralVariantPalette
      });
  }
}
const te = [
  "primary",
  "onPrimary",
  "primaryContainer",
  "onPrimaryContainer",
  "secondary",
  "onSecondary",
  "secondaryContainer",
  "onSecondaryContainer",
  "tertiary",
  "onTertiary",
  "tertiaryContainer",
  "onTertiaryContainer",
  "error",
  "onError",
  "errorContainer",
  "onErrorContainer",
  "background",
  "onBackground",
  "surface",
  "onSurface",
  "surfaceVariant",
  "onSurfaceVariant",
  "outline",
  "outlineVariant",
  "shadow",
  "scrim",
  "inverseSurface",
  "inverseOnSurface",
  "inversePrimary"
];
var rt = {
  naturalOrder: function(e, r) {
    return e < r ? -1 : e > r ? 1 : 0;
  },
  sum: function(e) {
    return e.reduce(function(r, n) {
      return r + n;
    }, 0);
  },
  max: function(e) {
    return Math.max.apply(null, e);
  }
}, ee = /* @__PURE__ */ function() {
  function t(r) {
    this.colors = r;
  }
  var e = t.prototype;
  return e.palette = function() {
    return this.colors;
  }, e.map = function(n) {
    return n;
  }, t;
}(), re = function() {
  var t = 5, e = 8 - t, r = 1e3, n = 0.75;
  function a(f, c, s) {
    return (f << 2 * t) + (c << t) + s;
  }
  function i(f) {
    var c = [], s = !1;
    function h() {
      c.sort(f), s = !0;
    }
    return {
      push: function(p) {
        c.push(p), s = !1;
      },
      peek: function(p) {
        return s || h(), p === void 0 && (p = c.length - 1), c[p];
      },
      pop: function() {
        return s || h(), c.pop();
      },
      size: function() {
        return c.length;
      },
      map: function(p) {
        return c.map(p);
      },
      debug: function() {
        return s || h(), c;
      }
    };
  }
  function u(f, c, s, h, y, p, A) {
    var b = this;
    b.r1 = f, b.r2 = c, b.g1 = s, b.g2 = h, b.b1 = y, b.b2 = p, b.histo = A;
  }
  u.prototype = {
    volume: function(c) {
      var s = this;
      return (!s._volume || c) && (s._volume = (s.r2 - s.r1 + 1) * (s.g2 - s.g1 + 1) * (s.b2 - s.b1 + 1)), s._volume;
    },
    count: function(c) {
      var s = this, h = s.histo;
      if (!s._count_set || c) {
        var y = 0, p, A, b, R;
        for (p = s.r1; p <= s.r2; p++)
          for (A = s.g1; A <= s.g2; A++)
            for (b = s.b1; b <= s.b2; b++)
              R = a(p, A, b), y += h[R] || 0;
        s._count = y, s._count_set = !0;
      }
      return s._count;
    },
    copy: function() {
      var c = this;
      return new u(c.r1, c.r2, c.g1, c.g2, c.b1, c.b2, c.histo);
    },
    avg: function(c) {
      var s = this, h = s.histo;
      if (!s._avg || c) {
        var y = 0, p = 1 << 8 - t, A = 0, b = 0, R = 0, g, T, C, F, B;
        if (s.r1 === s.r2 && s.g1 === s.g2 && s.b1 === s.b2)
          s._avg = [s.r1 << e, s.g1 << e, s.b1 << e];
        else {
          for (T = s.r1; T <= s.r2; T++)
            for (C = s.g1; C <= s.g2; C++)
              for (F = s.b1; F <= s.b2; F++)
                B = a(T, C, F), g = h[B] || 0, y += g, A += g * (T + 0.5) * p, b += g * (C + 0.5) * p, R += g * (F + 0.5) * p;
          y ? s._avg = [~~(A / y), ~~(b / y), ~~(R / y)] : s._avg = [~~(p * (s.r1 + s.r2 + 1) / 2), ~~(p * (s.g1 + s.g2 + 1) / 2), ~~(p * (s.b1 + s.b2 + 1) / 2)];
        }
      }
      return s._avg;
    },
    contains: function(c) {
      var s = this, h = c[0] >> e;
      return gval = c[1] >> e, bval = c[2] >> e, h >= s.r1 && h <= s.r2 && gval >= s.g1 && gval <= s.g2 && bval >= s.b1 && bval <= s.b2;
    }
  };
  function l() {
    this.vboxes = new i(function(f, c) {
      return rt.naturalOrder(f.vbox.count() * f.vbox.volume(), c.vbox.count() * c.vbox.volume());
    });
  }
  l.prototype = {
    push: function(c) {
      this.vboxes.push({
        vbox: c,
        color: c.avg()
      });
    },
    palette: function() {
      return this.vboxes.map(function(c) {
        return c.color;
      });
    },
    size: function() {
      return this.vboxes.size();
    },
    map: function(c) {
      for (var s = this.vboxes, h = 0; h < s.size(); h++)
        if (s.peek(h).vbox.contains(c))
          return s.peek(h).color;
      return this.nearest(c);
    },
    nearest: function(c) {
      for (var s = this.vboxes, h, y, p, A = 0; A < s.size(); A++)
        y = Math.sqrt(Math.pow(c[0] - s.peek(A).color[0], 2) + Math.pow(c[1] - s.peek(A).color[1], 2) + Math.pow(c[2] - s.peek(A).color[2], 2)), (y < h || h === void 0) && (h = y, p = s.peek(A).color);
      return p;
    },
    forcebw: function() {
      var c = this.vboxes;
      c.sort(function(p, A) {
        return rt.naturalOrder(rt.sum(p.color), rt.sum(A.color));
      });
      var s = c[0].color;
      s[0] < 5 && s[1] < 5 && s[2] < 5 && (c[0].color = [0, 0, 0]);
      var h = c.length - 1, y = c[h].color;
      y[0] > 251 && y[1] > 251 && y[2] > 251 && (c[h].color = [255, 255, 255]);
    }
  };
  function m(f) {
    var c = 1 << 3 * t, s = new Array(c), h, y, p, A;
    return f.forEach(function(b) {
      y = b[0] >> e, p = b[1] >> e, A = b[2] >> e, h = a(y, p, A), s[h] = (s[h] || 0) + 1;
    }), s;
  }
  function M(f, c) {
    var s = 1e6, h = 0, y = 1e6, p = 0, A = 1e6, b = 0, R, g, T;
    return f.forEach(function(C) {
      R = C[0] >> e, g = C[1] >> e, T = C[2] >> e, R < s ? s = R : R > h && (h = R), g < y ? y = g : g > p && (p = g), T < A ? A = T : T > b && (b = T);
    }), new u(s, h, y, p, A, b, c);
  }
  function d(f, c) {
    if (!c.count()) return;
    var s = c.r2 - c.r1 + 1, h = c.g2 - c.g1 + 1, y = c.b2 - c.b1 + 1, p = rt.max([s, h, y]);
    if (c.count() == 1)
      return [c.copy()];
    var A = 0, b = [], R = [], g, T, C, F, B;
    if (p == s)
      for (g = c.r1; g <= c.r2; g++) {
        for (F = 0, T = c.g1; T <= c.g2; T++)
          for (C = c.b1; C <= c.b2; C++)
            B = a(g, T, C), F += f[B] || 0;
        A += F, b[g] = A;
      }
    else if (p == h)
      for (g = c.g1; g <= c.g2; g++) {
        for (F = 0, T = c.r1; T <= c.r2; T++)
          for (C = c.b1; C <= c.b2; C++)
            B = a(T, g, C), F += f[B] || 0;
        A += F, b[g] = A;
      }
    else
      for (g = c.b1; g <= c.b2; g++) {
        for (F = 0, T = c.r1; T <= c.r2; T++)
          for (C = c.g1; C <= c.g2; C++)
            B = a(T, C, g), F += f[B] || 0;
        A += F, b[g] = A;
      }
    b.forEach(function(z, O) {
      R[O] = A - z;
    });
    function x(z) {
      var O = z + "1", S = z + "2", v, j, G, K, U, et = 0;
      for (g = c[O]; g <= c[S]; g++)
        if (b[g] > A / 2) {
          for (G = c.copy(), K = c.copy(), v = g - c[O], j = c[S] - g, v <= j ? U = Math.min(c[S] - 1, ~~(g + j / 2)) : U = Math.max(c[O], ~~(g - 1 - v / 2)); !b[U]; ) U++;
          for (et = R[U]; !et && b[U - 1]; ) et = R[--U];
          return G[S] = U, K[O] = G[S] + 1, [G, K];
        }
    }
    return p == s ? x("r") : p == h ? x("g") : x("b");
  }
  function w(f, c) {
    if (!Number.isInteger(c) || c < 1 || c > 256)
      throw new Error("Invalid maximum color count. It must be an integer between 1 and 256.");
    if (!f.length || c < 2 || c > 256 || !f.length || c < 2 || c > 256)
      return !1;
    for (var s = [], h = /* @__PURE__ */ new Set(), y = 0; y < f.length; y++) {
      var p = f[y], A = p.join(",");
      h.has(A) || (h.add(A), s.push(p));
    }
    if (s.length <= c)
      return new ee(s);
    var b = m(f);
    b.forEach(function() {
    });
    var R = M(f, b), g = new i(function(B, x) {
      return rt.naturalOrder(B.count(), x.count());
    });
    g.push(R);
    function T(B, x) {
      for (var z = B.size(), O = 0, S; O < r; ) {
        if (z >= x || O++ > r)
          return;
        if (S = B.pop(), !S.count()) {
          B.push(S), O++;
          continue;
        }
        var v = d(b, S), j = v[0], G = v[1];
        if (!j)
          return;
        B.push(j), G && (B.push(G), z++);
      }
    }
    T(g, n * c);
    for (var C = new i(function(B, x) {
      return rt.naturalOrder(B.count() * B.volume(), x.count() * x.volume());
    }); g.size(); )
      C.push(g.pop());
    T(C, c);
    for (var F = new l(); C.size(); )
      F.push(C.pop());
    return F;
  }
  return {
    quantize: w
  };
}(), ne = re.quantize;
function ae(t, e = 3) {
  const r = [];
  for (let n = 0; n < t.length; n += 4) {
    const a = t[n], i = t[n + 1], u = t[n + 2];
    t[n + 3] < 255 || r.push([a, i, u]);
  }
  try {
    const n = ne(r, e);
    return n ? n.palette().map(([i, u, l]) => lt(i, u, l)).slice(0, e) : [];
  } catch (n) {
    return console.error(n), [];
  }
}
async function oe(t, e = 3, r) {
  const n = r && r.length > 0 && r.length < 9, a = await new Promise((i, u) => {
    const l = document.createElement("canvas"), m = l.getContext("2d", {
      willReadFrequently: n
    });
    if (!m) {
      u(new Error("Could not get canvas context"));
      return;
    }
    const M = () => {
      if (l.width = t.width, l.height = t.height, m.drawImage(t, 0, 0), n) {
        const p = t.width / 3, A = t.height / 3, b = [];
        for (const R of r) {
          const g = Math.floor((R - 1) / 3), C = (R - 1) % 3 * p, F = g * A, B = m.getImageData(C, F, p, A).data;
          for (let x = 0; x < B.length; x++)
            b.push(B[x]);
        }
        i(new Uint8ClampedArray(b));
        return;
      }
      let w = [0, 0, t.width, t.height];
      const f = t.dataset.area;
      f && /^\d+(\s*,\s*\d+){3}$/.test(f) && (w = f.split(/\s*,\s*/).map((p) => parseInt(p, 10)));
      const [c, s, h, y] = w;
      i(m.getImageData(c, s, h, y).data);
    }, d = () => {
      u(new Error("Image load failed"));
    };
    t.complete ? M() : (t.onload = M, t.onerror = d);
  });
  return ae(a, e);
}
function se() {
  return typeof window != "object" ? !1 : !!window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
}
function ie(t) {
  return "#" + t.replace(/^rgba?\(|\s+|\)$/g, "").split(",").map((e) => parseFloat(e)).map((e, r) => r === 3 ? Math.round(e * 255) : e).map((e) => e.toString(16)).map((e) => e.length === 1 ? "0" + e : e).join("");
}
const ce = /(http|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])/, ue = /^rgba?/i;
async function he({
  source: t,
  ...e
}) {
  const r = e.variant ?? "fidelity", n = Qt[e.contrastLevel ?? "default"], a = e.isDark ?? se();
  let i, u = [];
  if (typeof t == "number")
    i = t;
  else if (ce.test(t)) {
    const w = await (e.imageFetcher ?? (() => {
      if (typeof window > "u" || typeof document > "u")
        throw new Error(
          "Image URLs can only be processed on the client-side unless a custom `imageFetcher` is provided."
        );
      return async (f) => {
        const s = await (await fetch(f)).blob(), h = document.createElement("img");
        h.src = URL.createObjectURL(s);
        try {
          return await oe(h, 3, e.grid);
        } finally {
          URL.revokeObjectURL(h.src);
        }
      };
    })())(t);
    i = w[0], u = w;
  } else {
    let d = t;
    ue.test(t) && (d = ie(t)), d.startsWith("#") && (i = $t(d));
  }
  if (i === void 0)
    return null;
  const l = _.fromInt(i), m = Zt(
    l,
    r,
    a,
    n,
    u
  );
  return te.reduce((d, w) => (d[w] = Jt(
    m[w]
  ), d), {});
}
function le(t, e) {
  const [r, n] = gt.useState(
    ""
  ), [a, i] = gt.useState(null), u = JSON.stringify(e);
  return gt.useEffect(() => {
    let l = !1;
    return n("loading"), he({ source: t, ...e }).then((m) => {
      l || (i(m), n(m ? "done" : ""));
    }).catch((m) => {
      l || (n("error"), i(null));
    }), () => {
      l = !0;
    };
  }, [t, u]), [a, r];
}
export {
  ae as findDominantColorsFromPixelData,
  he as getMaterialYouScheme,
  le as useMaterialYou
};
//# sourceMappingURL=index.es.js.map