UNPKG

@iconsets/svg-morpheus-ts

Version:

ESM TypeScript library enabling SVG icons to morph from one to the other. It implements Material Design's Delightful Details transitions. Refactored with modern TypeScript + Vite + pnpm stack. Supports both Chinese and English documentation.

1,502 lines 131 kB
/*! * SVG Morpheus TypeScript * Version: v1.3.1 * Build Date: 2025-08-08T22:48:47.755Z * Repository: https://github.com/caixw/SVG-Morpheus-ts */ const vt = ` \v\f\r   ᠎              \u2028\u2029`, Er = new RegExp("([a-z])[" + vt + ",]*((-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?[" + vt + "]*,?[" + vt + "]*)+)", "ig"), Nr = new RegExp("(-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?)[" + vt + "]*,?[" + vt + "]*", "ig"); function qn(t) { if (!t) return null; if (Array.isArray(t)) return t; { const e = { a: 7, c: 6, o: 2, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, u: 3, z: 0 }, n = []; return String(t).replace(Er, function(r, s, a) { const o = []; let i = s.toLowerCase(); if (a.replace(Nr, function(c, l) { return l && o.push(+l), ""; }), i === "m" && o.length > 2 && (n.push([s.charCodeAt(0)].concat(o.splice(0, 2))), i = "l", s = s === "m" ? "l" : "L"), i === "o" && o.length === 1 && n.push([s.charCodeAt(0), o[0]]), i === "r") n.push([s.charCodeAt(0)].concat(o)); else for (; o.length >= e[i] && (n.push([s.charCodeAt(0)].concat(o.splice(0, e[i]))), !!e[i]); ) ; return ""; }), n; } } function pe(t) { const e = qn(t); if (!e || !e.length) return [["M", 0, 0]]; const n = []; let r = 0, s = 0, a = 0, o = 0, i = 0; e[0][0] === 77 && (r = +e[0][1], s = +e[0][2], a = r, o = s, i++, n[0] = ["M", r, s]); for (let c = i, l = e.length; c < l; c++) { const u = [], f = e[c], d = f[0], h = String.fromCharCode(d); if (h !== h.toUpperCase()) switch (u[0] = h.toUpperCase(), u[0]) { case "A": u[1] = f[1], u[2] = f[2], u[3] = f[3], u[4] = f[4], u[5] = f[5], u[6] = +f[6] + r, u[7] = +f[7] + s; break; case "V": u[1] = +f[1] + s; break; case "H": u[1] = +f[1] + r; break; case "M": a = +f[1] + r, o = +f[2] + s; // Intentional fallthrough to default case // eslint-disable-next-line no-fallthrough default: for (let m = 1, g = f.length; m < g; m++) u[m] = +f[m] + (m % 2 ? r : s); break; } else { u[0] = h; for (let m = 1, g = f.length; m < g; m++) u[m] = f[m]; } switch (u[0]) { case "Z": r = a, s = o; break; case "H": r = u[1]; break; case "V": s = u[1]; break; case "M": a = u[1], o = u[2], r = u[1], s = u[2]; break; default: r = u[u.length - 2], s = u[u.length - 1]; } n.push(u); } return n; } function se(t, e) { const n = pe(t), r = e && pe(e), s = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null }, a = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null }, o = function(h, m, g) { let p, M; if (!h) return ["C", m.x, m.y, m.x, m.y, m.x, m.y]; switch (!(h[0] in { T: 1, Q: 1 }) && (m.qx = m.qy = null), h[0]) { case "M": m.X = h[1], m.Y = h[2]; break; case "A": h = ["C"].concat(Tn.apply(0, [m.x, m.y].concat(h.slice(1)))); break; case "S": g == "C" || g == "S" ? (p = m.x * 2 - m.bx, M = m.y * 2 - m.by) : (p = m.x, M = m.y), h = ["C", p, M].concat(h.slice(1)); break; case "T": g == "Q" || g == "T" ? (m.qx = m.x * 2 - m.qx, m.qy = m.y * 2 - m.qy) : (m.qx = m.x, m.qy = m.y), h = ["C"].concat(De(m.x, m.y, m.qx, m.qy, h[1], h[2])); break; case "Q": m.qx = h[1], m.qy = h[2], h = ["C"].concat(De(m.x, m.y, h[1], h[2], h[3], h[4])); break; case "L": h = ["C"].concat(Dt(m.x, m.y, h[1], h[2])); break; case "H": h = ["C"].concat(Dt(m.x, m.y, h[1], m.y)); break; case "V": h = ["C"].concat(Dt(m.x, m.y, m.x, h[1])); break; case "Z": h = ["C"].concat(Dt(m.x, m.y, m.X, m.Y)); break; } return h; }, i = function(h, m) { if (h[m].length > 7) { h[m].shift(); const g = h[m]; for (; g.length; ) l[m] = "A", r && (u[m] = "A"), h.splice(m++, 0, ["C"].concat(g.splice(0, 6))); h.splice(m, 1); } }, c = function(h, m, g, p, M) { h && m && h[M][0] == "M" && m[M][0] != "M" && (m.splice(M, 0, ["M", p.x, p.y]), g.bx = 0, g.by = 0, g.x = h[M][1], g.y = h[M][2]); }, l = [], u = []; let f = "", d = ""; for (let h = 0, m = Math.max(n.length, r && r.length || 0); h < m; h++) { n[h] && (f = n[h][0]), f != "C" && (l[h] = f, h && (d = l[h - 1])), n[h] = o(n[h], s, d), l[h] != "A" && f == "C" && (l[h] = "C"), i(n, h), r && (r[h] && (f = r[h][0]), f != "C" && (u[h] = f, h && (d = u[h - 1])), r[h] = o(r[h], a, d), u[h] != "A" && f == "C" && (u[h] = "C"), i(r, h)), c(n, r, s, a, h), c(r, n, a, s, h); const g = n[h], p = r && r[h], M = g.length, w = r && p.length; s.x = g[M - 2], s.y = g[M - 1], s.bx = parseFloat(g[M - 4]) || s.x, s.by = parseFloat(g[M - 3]) || s.y, a.bx = r && (parseFloat(p[w - 4]) || a.x), a.by = r && (parseFloat(p[w - 3]) || a.y), a.x = r && p[w - 2], a.y = r && p[w - 1]; } return r ? [n, r] : n; } function Dt(t, e, n, r) { return [t, e, n, r, n, r]; } function De(t, e, n, r, s, a) { var o = 0.3333333333333333, i = 2 / 3; return [ o * t + i * n, o * e + i * r, o * s + i * n, o * a + i * r, s, a ]; } function Tn(t, e, n, r, s, a, o, i, c, l) { var u = Math.PI * 120 / 180, f = Math.PI / 180 * (+s || 0), d = [], h, m = function(At, Bt, ft) { return { x: At * Math.cos(ft) - Bt * Math.sin(ft), y: At * Math.sin(ft) + Bt * Math.cos(ft) }; }; if (l) x = l[0], v = l[1], I = l[2], B = l[3]; else { h = m(t, e, -f), t = h.x, e = h.y, h = m(i, c, -f), i = h.x, c = h.y; var g = (t - i) / 2, p = (e - c) / 2, M = g * g / (n * n) + p * p / (r * r); M > 1 && (M = Math.sqrt(M), n = M * n, r = M * r); var w = n * n, _ = r * r, y = (a == o ? -1 : 1) * Math.sqrt(Math.abs((w * _ - w * p * p - _ * g * g) / (w * p * p + _ * g * g))), I = y * n * p / r + (t + i) / 2, B = y * -r * g / n + (e + c) / 2, x = Math.asin(+((e - B) / r).toFixed(9)), v = Math.asin(+((c - B) / r).toFixed(9)); x = t < I ? Math.PI - x : x, v = i < I ? Math.PI - v : v, x < 0 && (x = Math.PI * 2 + x), v < 0 && (v = Math.PI * 2 + v), o && x > v && (x = x - Math.PI * 2), !o && v > x && (v = v - Math.PI * 2); } var E = v - x; if (Math.abs(E) > u) { var G = v, Z = i, lt = c; v = x + u * (o && v > x ? 1 : -1), i = I + n * Math.cos(v), c = B + r * Math.sin(v), d = Tn(i, c, n, r, s, 0, o, Z, lt, [v, G, I, B]); } E = v - x; var V = Math.cos(x), U = Math.sin(x), H = Math.cos(v), O = Math.sin(v), K = Math.tan(E / 4), W = 4 / 3 * n * K, J = 4 / 3 * r * K, N = [t, e], R = [t + W * U, e - J * V], _t = [i + W * O, c - J * H], It = [i, c]; if (R[0] = 2 * N[0] - R[0], R[1] = 2 * N[1] - R[1], l) return [R, _t, It].concat(d); d = [R, _t, It].concat(d).join().split(","); for (var ot = [], D = 0, ut = d.length; D < ut; D++) ot[D] = D % 2 ? m(d[D - 1], d[D], f).y : m(d[D], d[D + 1], f).x; return ot; } const Rr = /,?([a-z]),?/gi; function Yn(t) { return t.join(",").replace(Rr, "$1"); } function zt(t) { if (!t || !Array.isArray(t) || t.length === 0) return Ot(0, 0, 0, 0); let e = 0, n = 0; const r = [], s = []; let a; for (let u = 0, f = t.length; u < f; u++) if (a = t[u], a[0] == "M") e = isFinite(a[1]) ? a[1] : 0, n = isFinite(a[2]) ? a[2] : 0, r.push(e), s.push(n); else { const d = e, h = n, m = isFinite(a[1]) ? a[1] : 0, g = isFinite(a[2]) ? a[2] : 0, p = isFinite(a[3]) ? a[3] : 0, M = isFinite(a[4]) ? a[4] : 0, w = isFinite(a[5]) ? a[5] : 0, _ = isFinite(a[6]) ? a[6] : 0, y = Lr(d, h, m, g, p, M, w, _); isFinite(y.min.x) && isFinite(y.max.x) && isFinite(y.min.y) && isFinite(y.max.y) && (r.push(y.min.x, y.max.x), s.push(y.min.y, y.max.y)), e = w, n = _; } if (r.length === 0 || s.length === 0) return Ot(0, 0, 0, 0); const o = Math.min(...r), i = Math.min(...s), c = Math.max(...r), l = Math.max(...s); return !isFinite(o) || !isFinite(i) || !isFinite(c) || !isFinite(l) ? Ot(0, 0, 0, 0) : Ot(o, i, c - o, l - i); } function Ot(t, e, n, r) { return t = isFinite(t) ? t : 0, e = isFinite(e) ? e : 0, n = isFinite(n) ? n : 0, r = isFinite(r) ? r : 0, { x: t, y: e, w: n, h: r, cx: t + n / 2, cy: e + r / 2 }; } function Lr(t, e, n, r, s, a, o, i) { for (var c = [], l = [[], []], u, f, d, h, m, g, p, M, w = 0; w < 2; ++w) { if (w == 0 ? (f = 6 * t - 12 * n + 6 * s, u = -3 * t + 9 * n - 9 * s + 3 * o, d = 3 * n - 3 * t) : (f = 6 * e - 12 * r + 6 * a, u = -3 * e + 9 * r - 9 * a + 3 * i, d = 3 * r - 3 * e), Math.abs(u) < 1e-12) { if (Math.abs(f) < 1e-12) continue; h = -d / f, 0 < h && h < 1 && c.push(h); continue; } p = f * f - 4 * d * u, M = Math.sqrt(p), !(p < 0) && (m = (-f + M) / (2 * u), 0 < m && m < 1 && c.push(m), g = (-f - M) / (2 * u), 0 < g && g < 1 && c.push(g)); } for (var _ = c.length, y = _, I; _--; ) h = c[_], I = 1 - h, l[0][_] = I * I * I * t + 3 * I * I * h * n + 3 * I * h * h * s + h * h * h * o, l[1][_] = I * I * I * e + 3 * I * I * h * r + 3 * I * h * h * a + h * h * h * i; return l[0][y] = t, l[1][y] = e, l[0][y + 1] = o, l[1][y + 1] = i, l[0].length = l[1].length = y + 2, { min: { x: Math.min.apply(0, l[0]), y: Math.min.apply(0, l[1]) }, max: { x: Math.max.apply(0, l[0]), y: Math.max.apply(0, l[1]) } }; } function ze(t, e) { const [n, r, s, a] = t.values, [o, i, c, l] = e.values, u = c / s, f = l / a, d = o - n * u, h = i - r * f; return { scaleX: u, scaleY: f, translateX: d, translateY: h }; } function tt(t, e, n) { return [ t * n.scaleX + n.translateX, e * n.scaleY + n.translateY ]; } function Ar(t, e) { if (!t || !t.trim()) return t; try { const n = qn(t), s = pe(n).map((a) => { const o = a[0], i = a.slice(1), c = [o]; switch (o) { case "M": // MoveTo case "L": if (i.length >= 2) { const [l, u] = tt(i[0], i[1], e); c.push(l, u); for (let f = 2; f < i.length; f += 2) if (f + 1 < i.length) { const [d, h] = tt(i[f], i[f + 1], e); c.push(d, h); } } break; case "C": if (i.length >= 6) { for (let l = 0; l < i.length; l += 2) if (l + 1 < i.length) { const [u, f] = tt(i[l], i[l + 1], e); c.push(u, f); } } break; case "Q": if (i.length >= 4) { for (let l = 0; l < i.length; l += 2) if (l + 1 < i.length) { const [u, f] = tt(i[l], i[l + 1], e); c.push(u, f); } } break; case "A": if (i.length >= 7) { const l = i[0] * e.scaleX, u = i[1] * e.scaleY, [f, d] = tt(i[5], i[6], e); c.push(l, u, i[2], i[3], i[4], f, d); } break; case "H": if (i.length >= 1) { const [l] = tt(i[0], 0, e); c.push(l); } break; case "V": if (i.length >= 1) { const [, l] = tt(0, i[0], e); c.push(l); } break; case "Z": // ClosePath case "z": break; default: for (let l = 0; l < i.length; l += 2) if (l + 1 < i.length) { const [u, f] = tt(i[l], i[l + 1], e); c.push(u, f); } else c.push(i[l]); } return c; }); return Yn(s); } catch (n) { return console.warn("Path transformation failed:", n), t; } } function Oe(t, e = "", n) { const r = { gradients: {}, patterns: {}, others: {} }; for (const [s, a] of Object.entries(t.gradients)) { const o = e + s; let i = a; i = i.replace(new RegExp(`id="${s}"`, "g"), `id="${o}"`), i = i.replace(new RegExp(`id='${s}'`, "g"), `id='${o}'`), n && (i = Br(i, n)), r.gradients[o] = i; } for (const [s, a] of Object.entries(t.patterns)) { const o = e + s; let i = a; i = i.replace(new RegExp(`id="${s}"`, "g"), `id="${o}"`), i = i.replace(new RegExp(`id='${s}'`, "g"), `id='${o}'`), n && (i = Pr(i, n)), r.patterns[o] = i; } for (const [s, a] of Object.entries(t.others)) { const o = e + s; let i = a; i = i.replace(new RegExp(`id="${s}"`, "g"), `id="${o}"`), i = i.replace(new RegExp(`id='${s}'`, "g"), `id='${o}'`), r.others[o] = i; } return r; } function Br(t, e) { let n = t; return t.includes("linearGradient") && (n = n.replace( /\b(x1|y1|x2|y2)=["']([^"']+)["']/g, (r, s, a) => { const o = be(s, a, e); return `${s}="${o}"`; } )), t.includes("radialGradient") && (n = n.replace( /\b(cx|cy|fx|fy|r)=["']([^"']+)["']/g, (r, s, a) => { const o = be(s, a, e); return `${s}="${o}"`; } )), n; } function Pr(t, e) { let n = t; return n = n.replace( /\b(x|y|width|height)=["']([^"']+)["']/g, (r, s, a) => { const o = be(s, a, e); return `${s}="${o}"`; } ), n; } function be(t, e, n) { if (e.endsWith("%")) return e; const r = parseFloat(e); if (isNaN(r)) return e; let s; switch (t) { case "x1": case "x2": case "cx": case "fx": case "x": s = r * n.scaleX + n.translateX; break; case "y1": case "y2": case "cy": case "fy": case "y": s = r * n.scaleY + n.translateY; break; case "r": s = r * Math.sqrt(n.scaleX * n.scaleY); break; case "width": s = r * n.scaleX; break; case "height": s = r * n.scaleY; break; default: s = r; } return s.toFixed(3); } function qt(t, e, n) { let r = { ...e }; for (const [s, a] of Object.entries(r)) if (typeof a == "string" && a.startsWith("url(#")) { const o = a.match(/url\(#([^)]+)\)/); o && n[o[1]] && (r[s] = `url(#${n[o[1]]})`); } return { pathData: t, attrs: r }; } const ae = { "circ-in": (t) => -1 * (Math.sqrt(1 - t * t) - 1), "circ-out": (t) => Math.sqrt(1 - (t = t - 1) * t), "circ-in-out": (t) => (t /= 1 / 2) < 1 ? -1 / 2 * (Math.sqrt(1 - t * t) - 1) : 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1), "cubic-in": (t) => t * t * t, "cubic-out": (t) => --t * t * t + 1, "cubic-in-out": (t) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1, "elastic-in": (t) => { var r = 1.70158, e = 0, n = 1; if (t == 0) return 0; if (t == 1) return 1; if (e || (e = 0.3), n < Math.abs(1)) { n = 1; var r = e / 4; } else var r = e / (2 * Math.PI) * Math.asin(1 / n); return -(n * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - r) * (2 * Math.PI) / e)); }, "elastic-out": (t) => { var r = 1.70158, e = 0, n = 1; if (t == 0) return 0; if (t == 1) return 1; if (e || (e = 0.3), n < Math.abs(1)) { n = 1; var r = e / 4; } else var r = e / (2 * Math.PI) * Math.asin(1 / n); return n * Math.pow(2, -10 * t) * Math.sin((t - r) * (2 * Math.PI) / e) + 1; }, "elastic-in-out": (t) => { var r = 1.70158, e = 0, n = 1; if (t == 0) return 0; if ((t /= 1 / 2) == 2) return 1; if (e || (e = 1 * (0.3 * 1.5)), n < Math.abs(1)) { n = 1; var r = e / 4; } else var r = e / (2 * Math.PI) * Math.asin(1 / n); return t < 1 ? -0.5 * (n * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - r) * (2 * Math.PI) / e)) : n * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - r) * (2 * Math.PI) / e) * 0.5 + 1; }, "expo-in": (t) => t == 0 ? 0 : Math.pow(2, 10 * (t - 1)), "expo-out": (t) => t == 1 ? 1 : 1 - Math.pow(2, -10 * t), "expo-in-out": (t) => t == 0 ? 0 : t == 1 ? 1 : (t /= 1 / 2) < 1 ? 1 / 2 * Math.pow(2, 10 * (t - 1)) : 1 / 2 * (-Math.pow(2, -10 * --t) + 2), linear: (t) => t, "quad-in": (t) => t * t, "quad-out": (t) => t * (2 - t), "quad-in-out": (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t, "quart-in": (t) => t * t * t * t, "quart-out": (t) => 1 - --t * t * t * t, "quart-in-out": (t) => t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t, "quint-in": (t) => t * t * t * t * t, "quint-out": (t) => 1 + --t * t * t * t * t, "quint-in-out": (t) => t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t, "sine-in": (t) => 1 - Math.cos(t * (Math.PI / 2)), "sine-out": (t) => Math.sin(t * (Math.PI / 2)), "sine-in-out": (t) => 1 / 2 * (1 - Math.cos(Math.PI * t)) }; function k(t, e) { let n = t.length; Array.isArray(t[0]) || (t = [t]), Array.isArray(e[0]) || (e = e.map((o) => [o])); let r = e[0].length, s = e[0].map((o, i) => e.map((c) => c[i])), a = t.map((o) => s.map((i) => { let c = 0; if (!Array.isArray(o)) { for (let l of i) c += o * l; return c; } for (let l = 0; l < o.length; l++) c += o[l] * (i[l] || 0); return c; })); return n === 1 && (a = a[0]), r === 1 ? a.map((o) => o[0]) : a; } function Nt(t) { return et(t) === "string"; } function et(t) { return (Object.prototype.toString.call(t).match(/^\[object\s+(.*?)\]$/)[1] || "").toLowerCase(); } function Jt(t, { precision: e, unit: n }) { return nt(t) ? "none" : jn(t, e) + (n ?? ""); } function nt(t) { return Number.isNaN(t) || t instanceof Number && t?.none; } function L(t) { return nt(t) ? 0 : t; } function jn(t, e) { if (t === 0) return 0; let n = ~~t, r = 0; n && e && (r = ~~Math.log10(Math.abs(n)) + 1); const s = 10 ** (e - r); return Math.floor(t * s + 0.5) / s; } const Dr = { deg: 1, grad: 0.9, rad: 180 / Math.PI, turn: 360 }; function Gn(t) { if (!t) return; t = t.trim(); const e = /^([a-z]+)\((.+?)\)$/i, n = /^-?[\d.]+$/, r = /%|deg|g?rad|turn$/, s = /\/?\s*(none|[-\w.]+(?:%|deg|g?rad|turn)?)/g; let a = t.match(e); if (a) { let o = []; return a[2].replace(s, (i, c) => { let l = c.match(r), u = c; if (l) { let f = l[0], d = u.slice(0, -f.length); f === "%" ? (u = new Number(d / 100), u.type = "<percentage>") : (u = new Number(d * Dr[f]), u.type = "<angle>", u.unit = f); } else n.test(u) ? (u = new Number(u), u.type = "<number>") : u === "none" && (u = new Number(NaN), u.none = !0); i.startsWith("/") && (u = u instanceof Number ? u : new Number(u), u.alpha = !0), typeof u == "object" && u instanceof Number && (u.raw = c), o.push(u); }), { name: a[1].toLowerCase(), rawName: a[1], rawArgs: a[2], // An argument could be (as of css-color-4): // a number, percentage, degrees (hue), ident (in color()) args: o }; } } function Hn(t) { return t[t.length - 1]; } function St(t, e, n) { return isNaN(t) ? e : isNaN(e) ? t : t + (e - t) * n; } function Fn(t, e, n) { return (n - t) / (e - t); } function ke(t, e, n) { return St(e[0], e[1], Fn(t[0], t[1], n)); } function Xn(t) { return t.map((e) => e.split("|").map((n) => { n = n.trim(); let r = n.match(/^(<[a-z]+>)\[(-?[.\d]+),\s*(-?[.\d]+)\]?$/); if (r) { let s = new String(r[1]); return s.range = [+r[2], +r[3]], s; } return n; })); } function Zn(t, e, n) { return Math.max(Math.min(n, e), t); } function te(t, e) { return Math.sign(t) === Math.sign(e) ? t : -t; } function F(t, e) { return te(Math.abs(t) ** e, t); } function Ee(t, e) { return e === 0 ? 0 : t / e; } function Vn(t, e, n = 0, r = t.length) { for (; n < r; ) { const s = n + r >> 1; t[s] < e ? n = s + 1 : r = s; } return n; } var zr = /* @__PURE__ */ Object.freeze({ __proto__: null, bisectLeft: Vn, clamp: Zn, copySign: te, interpolate: St, interpolateInv: Fn, isNone: nt, isString: Nt, last: Hn, mapRange: ke, multiplyMatrices: k, parseCoordGrammar: Xn, parseFunction: Gn, serializeNumber: Jt, skipNone: L, spow: F, toPrecision: jn, type: et, zdiv: Ee }); class Or { add(e, n, r) { if (typeof arguments[0] != "string") { for (var e in arguments[0]) this.add(e, arguments[0][e], arguments[1]); return; } (Array.isArray(e) ? e : [e]).forEach(function(s) { this[s] = this[s] || [], n && this[s][r ? "unshift" : "push"](n); }, this); } run(e, n) { this[e] = this[e] || [], this[e].forEach(function(r) { r.call(n && n.context ? n.context : n, n); }); } } const rt = new Or(); var j = { gamut_mapping: "css", precision: 5, deltaE: "76", // Default deltaE method verbose: globalThis?.process?.env?.NODE_ENV?.toLowerCase() !== "test", warn: function(e) { this.verbose && globalThis?.console?.warn?.(e); } }; const z = { // for compatibility, the four-digit chromaticity-derived ones everyone else uses D50: [0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585], D65: [0.3127 / 0.329, 1, (1 - 0.3127 - 0.329) / 0.329] }; function Me(t) { return Array.isArray(t) ? t : z[t]; } function Qt(t, e, n, r = {}) { if (t = Me(t), e = Me(e), !t || !e) throw new TypeError(`Missing white point to convert ${t ? "" : "from"}${!t && !e ? "/" : ""}${e ? "" : "to"}`); if (t === e) return n; let s = { W1: t, W2: e, XYZ: n, options: r }; if (rt.run("chromatic-adaptation-start", s), s.M || (s.W1 === z.D65 && s.W2 === z.D50 ? s.M = [ [1.0479297925449969, 0.022946870601609652, -0.05019226628920524], [0.02962780877005599, 0.9904344267538799, -0.017073799063418826], [-0.009243040646204504, 0.015055191490298152, 0.7518742814281371] ] : s.W1 === z.D50 && s.W2 === z.D65 && (s.M = [ [0.955473421488075, -0.02309845494876471, 0.06325924320057072], [-0.0283697093338637, 1.0099953980813041, 0.021041441191917323], [0.012314014864481998, -0.020507649298898964, 1.330365926242124] ])), rt.run("chromatic-adaptation-end", s), s.M) return k(s.M, s.XYZ); throw new TypeError("Only Bradford CAT with white points D50 and D65 supported for now."); } const qr = /* @__PURE__ */ new Set(["<number>", "<percentage>", "<angle>"]); function qe(t, e, n, r) { return Object.entries(t.coords).map(([a, o], i) => { let c = e.coordGrammar[i], l = r[i], u = l?.type, f; if (l.none ? f = c.find((m) => qr.has(m)) : f = c.find((m) => m == u), !f) { let m = o.name || a; throw new TypeError(`${u ?? l.raw} not allowed for ${m} in ${n}()`); } let d = f.range; u === "<percentage>" && (d ||= [0, 1]); let h = o.range || o.refRange; return d && h && (r[i] = ke(d, h, r[i])), f; }); } function Wn(t, { meta: e } = {}) { let n = { str: String(t)?.trim() }; if (rt.run("parse-start", n), n.color) return n.color; if (n.parsed = Gn(n.str), n.parsed) { let r = n.parsed.name; if (r === "color") { let s = n.parsed.args.shift(), a = s.startsWith("--") ? s.substring(2) : `--${s}`, o = [s, a], i = n.parsed.rawArgs.indexOf("/") > 0 ? n.parsed.args.pop() : 1; for (let u of b.all) { let f = u.getFormat("color"); if (f && (o.includes(f.id) || f.ids?.filter((d) => o.includes(d)).length)) { const d = Object.keys(u.coords).map((m, g) => n.parsed.args[g] || 0); let h; return f.coordGrammar && (h = qe(u, f, "color", d)), e && Object.assign(e, { formatId: "color", types: h }), f.id.startsWith("--") && !s.startsWith("--") && j.warn(`${u.name} is a non-standard space and not currently supported in the CSS spec. Use prefixed color(${f.id}) instead of color(${s}).`), s.startsWith("--") && !f.id.startsWith("--") && j.warn(`${u.name} is a standard space and supported in the CSS spec. Use color(${f.id}) instead of prefixed color(${s}).`), { spaceId: u.id, coords: d, alpha: i }; } } let c = "", l = s in b.registry ? s : a; if (l in b.registry) { let u = b.registry[l].formats?.color?.id; u && (c = `Did you mean color(${u})?`); } throw new TypeError(`Cannot parse color(${s}). ` + (c || "Missing a plugin?")); } else for (let s of b.all) { let a = s.getFormat(r); if (a && a.type === "function") { let o = 1; (a.lastAlpha || Hn(n.parsed.args).alpha) && (o = n.parsed.args.pop()); let i = n.parsed.args, c; return a.coordGrammar && (c = qe(s, a, r, i)), e && Object.assign(e, { formatId: a.name, types: c }), { spaceId: s.id, coords: i, alpha: o }; } } } else for (let r of b.all) for (let s in r.formats) { let a = r.formats[s]; if (a.type !== "custom" || a.test && !a.test(n.str)) continue; let o = a.parse(n.str); if (o) return o.alpha ??= 1, e && (e.formatId = s), o; } throw new TypeError(`Could not parse ${t} as a color. Missing a plugin?`); } function C(t) { if (Array.isArray(t)) return t.map(C); if (!t) throw new TypeError("Empty color reference"); Nt(t) && (t = Wn(t)); let e = t.space || t.spaceId; return e instanceof b || (t.space = b.get(e)), t.alpha === void 0 && (t.alpha = 1), t; } const Tr = 75e-6; class b { constructor(e) { this.id = e.id, this.name = e.name, this.base = e.base ? b.get(e.base) : null, this.aliases = e.aliases, this.base && (this.fromBase = e.fromBase, this.toBase = e.toBase); let n = e.coords ?? this.base.coords; for (let s in n) "name" in n[s] || (n[s].name = s); this.coords = n; let r = e.white ?? this.base.white ?? "D65"; this.white = Me(r), this.formats = e.formats ?? {}; for (let s in this.formats) { let a = this.formats[s]; a.type ||= "function", a.name ||= s; } this.formats.color?.id || (this.formats.color = { ...this.formats.color ?? {}, id: e.cssId || this.id }), e.gamutSpace ? this.gamutSpace = e.gamutSpace === "self" ? this : b.get(e.gamutSpace) : this.isPolar ? this.gamutSpace = this.base : this.gamutSpace = this, this.gamutSpace.isUnbounded && (this.inGamut = (s, a) => !0), this.referred = e.referred, Object.defineProperty(this, "path", { value: Yr(this).reverse(), writable: !1, enumerable: !0, configurable: !0 }), rt.run("colorspace-init-end", this); } inGamut(e, { epsilon: n = Tr } = {}) { if (!this.equals(this.gamutSpace)) return e = this.to(this.gamutSpace, e), this.gamutSpace.inGamut(e, { epsilon: n }); let r = Object.values(this.coords); return e.every((s, a) => { let o = r[a]; if (o.type !== "angle" && o.range) { if (Number.isNaN(s)) return !0; let [i, c] = o.range; return (i === void 0 || s >= i - n) && (c === void 0 || s <= c + n); } return !0; }); } get isUnbounded() { return Object.values(this.coords).every((e) => !("range" in e)); } get cssId() { return this.formats?.color?.id || this.id; } get isPolar() { for (let e in this.coords) if (this.coords[e].type === "angle") return !0; return !1; } getFormat(e) { if (typeof e == "object") return e = Te(e, this), e; let n; return e === "default" ? n = Object.values(this.formats)[0] : n = this.formats[e], n ? (n = Te(n, this), n) : null; } /** * Check if this color space is the same as another color space reference. * Allows proxying color space objects and comparing color spaces with ids. * @param {string | ColorSpace} space ColorSpace object or id to compare to * @returns {boolean} */ equals(e) { return e ? this === e || this.id === e || this.id === e.id : !1; } to(e, n) { if (arguments.length === 1) { const i = C(e); [e, n] = [i.space, i.coords]; } if (e = b.get(e), this.equals(e)) return n; n = n.map((i) => Number.isNaN(i) ? 0 : i); let r = this.path, s = e.path, a, o; for (let i = 0; i < r.length && r[i].equals(s[i]); i++) a = r[i], o = i; if (!a) throw new Error(`Cannot convert between color spaces ${this} and ${e}: no connection space was found`); for (let i = r.length - 1; i > o; i--) n = r[i].toBase(n); for (let i = o + 1; i < s.length; i++) n = s[i].fromBase(n); return n; } from(e, n) { if (arguments.length === 1) { const r = C(e); [e, n] = [r.space, r.coords]; } return e = b.get(e), e.to(this, n); } toString() { return `${this.name} (${this.id})`; } getMinCoords() { let e = []; for (let n in this.coords) { let r = this.coords[n], s = r.range || r.refRange; e.push(s?.min ?? 0); } return e; } static registry = {}; // Returns array of unique color spaces static get all() { return [...new Set(Object.values(b.registry))]; } static register(e, n) { if (arguments.length === 1 && (n = arguments[0], e = n.id), n = this.get(n), this.registry[e] && this.registry[e] !== n) throw new Error(`Duplicate color space registration: '${e}'`); if (this.registry[e] = n, arguments.length === 1 && n.aliases) for (let r of n.aliases) this.register(r, n); return n; } /** * Lookup ColorSpace object by name * @param {ColorSpace | string} name */ static get(e, ...n) { if (!e || e instanceof b) return e; if (et(e) === "string") { let s = b.registry[e.toLowerCase()]; if (!s) throw new TypeError(`No color space found with id = "${e}"`); return s; } if (n.length) return b.get(...n); throw new TypeError(`${e} is not a valid color space`); } /** * Get metadata about a coordinate of a color space * * @static * @param {Array | string} ref * @param {ColorSpace | string} [workingSpace] * @return {Object} */ static resolveCoord(e, n) { let r = et(e), s, a; if (r === "string" ? e.includes(".") ? [s, a] = e.split(".") : [s, a] = [, e] : Array.isArray(e) ? [s, a] = e : (s = e.space, a = e.coordId), s = b.get(s), s || (s = n), !s) throw new TypeError(`Cannot resolve coordinate reference ${e}: No color space specified and relative references are not allowed here`); if (r = et(a), r === "number" || r === "string" && a >= 0) { let c = Object.entries(s.coords)[a]; if (c) return { space: s, id: c[0], index: a, ...c[1] }; } s = b.get(s); let o = a.toLowerCase(), i = 0; for (let c in s.coords) { let l = s.coords[c]; if (c.toLowerCase() === o || l.name?.toLowerCase() === o) return { space: s, id: c, index: i, ...l }; i++; } throw new TypeError(`No "${a}" coordinate found in ${s.name}. Its coordinates are: ${Object.keys(s.coords).join(", ")}`); } static DEFAULT_FORMAT = { type: "functions", name: "color" }; } function Yr(t) { let e = [t]; for (let n = t; n = n.base; ) e.push(n); return e; } function Te(t, { coords: e } = {}) { if (t.coords && !t.coordGrammar) { t.type ||= "function", t.name ||= "color", t.coordGrammar = Xn(t.coords); let n = Object.entries(e).map(([r, s], a) => { let o = t.coordGrammar[a][0], i = s.range || s.refRange, c = o.range, l = ""; return o == "<percentage>" ? (c = [0, 100], l = "%") : o == "<angle>" && (l = "deg"), { fromRange: i, toRange: c, suffix: l }; }); t.serializeCoords = (r, s) => r.map((a, o) => { let { fromRange: i, toRange: c, suffix: l } = n[o]; return i && c && (a = ke(i, c, a)), a = Jt(a, { precision: s, unit: l }), a; }); } return t; } var P = new b({ id: "xyz-d65", name: "XYZ D65", coords: { x: { name: "X" }, y: { name: "Y" }, z: { name: "Z" } }, white: "D65", formats: { color: { ids: ["xyz-d65", "xyz"] } }, aliases: ["xyz"] }); class q extends b { /** * Creates a new RGB ColorSpace. * If coords are not specified, they will use the default RGB coords. * Instead of `fromBase()` and `toBase()` functions, * you can specify to/from XYZ matrices and have `toBase()` and `fromBase()` automatically generated. * @param {*} options - Same options as {@link ColorSpace} plus: * @param {number[][]} options.toXYZ_M - Matrix to convert to XYZ * @param {number[][]} options.fromXYZ_M - Matrix to convert from XYZ */ constructor(e) { e.coords || (e.coords = { r: { range: [0, 1], name: "Red" }, g: { range: [0, 1], name: "Green" }, b: { range: [0, 1], name: "Blue" } }), e.base || (e.base = P), e.toXYZ_M && e.fromXYZ_M && (e.toBase ??= (n) => { let r = k(e.toXYZ_M, n); return this.white !== this.base.white && (r = Qt(this.white, this.base.white, r)), r; }, e.fromBase ??= (n) => (n = Qt(this.base.white, this.white, n), k(e.fromXYZ_M, n))), e.referred ??= "display", super(e); } } function Rt(t, e) { return t = C(t), !e || t.space.equals(e) ? t.coords.slice() : (e = b.get(e), e.from(t)); } function T(t, e) { t = C(t); let { space: n, index: r } = b.resolveCoord(e, t.space); return Rt(t, n)[r]; } function Ne(t, e, n) { return t = C(t), e = b.get(e), t.coords = e.to(t.space, n), t; } Ne.returns = "color"; function Q(t, e, n) { if (t = C(t), arguments.length === 2 && et(arguments[1]) === "object") { let r = arguments[1]; for (let s in r) Q(t, s, r[s]); } else { typeof n == "function" && (n = n(T(t, e))); let { space: r, index: s } = b.resolveCoord(e, t.space), a = Rt(t, r); a[s] = n, Ne(t, r, a); } return t; } Q.returns = "color"; var Re = new b({ id: "xyz-d50", name: "XYZ D50", white: "D50", base: P, fromBase: (t) => Qt(P.white, "D50", t), toBase: (t) => Qt("D50", P.white, t) }); const jr = 216 / 24389, Ye = 24 / 116, Tt = 24389 / 27; let oe = z.D50; var Y = new b({ id: "lab", name: "Lab", coords: { l: { refRange: [0, 100], name: "Lightness" }, a: { refRange: [-125, 125] }, b: { refRange: [-125, 125] } }, // Assuming XYZ is relative to D50, convert to CIE Lab // from CIE standard, which now defines these as a rational fraction white: oe, base: Re, // Convert D50-adapted XYX to Lab // CIE 15.3:2004 section 8.2.1.1 fromBase(t) { let n = t.map((r, s) => r / oe[s]).map((r) => r > jr ? Math.cbrt(r) : (Tt * r + 16) / 116); return [ 116 * n[1] - 16, // L 500 * (n[0] - n[1]), // a 200 * (n[1] - n[2]) // b ]; }, // Convert Lab to D50-adapted XYZ // Same result as CIE 15.3:2004 Appendix D although the derivation is different // http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html toBase(t) { let e = []; return e[1] = (t[0] + 16) / 116, e[0] = t[1] / 500 + e[1], e[2] = e[1] - t[2] / 200, [ e[0] > Ye ? Math.pow(e[0], 3) : (116 * e[0] - 16) / Tt, t[0] > 8 ? Math.pow((t[0] + 16) / 116, 3) : t[0] / Tt, e[2] > Ye ? Math.pow(e[2], 3) : (116 * e[2] - 16) / Tt ].map((r, s) => r * oe[s]); }, formats: { lab: { coords: ["<number> | <percentage>", "<number> | <percentage>[-1,1]", "<number> | <percentage>[-1,1]"] } } }); function X(t) { return (t % 360 + 360) % 360; } function Gr(t, e) { if (t === "raw") return e; let [n, r] = e.map(X), s = r - n; return t === "increasing" ? s < 0 && (r += 360) : t === "decreasing" ? s > 0 && (n += 360) : t === "longer" ? -180 < s && s < 180 && (s > 0 ? n += 360 : r += 360) : t === "shorter" && (s > 180 ? n += 360 : s < -180 && (r += 360)), [n, r]; } var kt = new b({ id: "lch", name: "LCH", coords: { l: { refRange: [0, 100], name: "Lightness" }, c: { refRange: [0, 150], name: "Chroma" }, h: { refRange: [0, 360], type: "angle", name: "Hue" } }, base: Y, fromBase(t) { let [e, n, r] = t, s; const a = 0.02; return Math.abs(n) < a && Math.abs(r) < a ? s = NaN : s = Math.atan2(r, n) * 180 / Math.PI, [ e, // L is still L Math.sqrt(n ** 2 + r ** 2), // Chroma X(s) // Hue, in degrees [0 to 360) ]; }, toBase(t) { let [e, n, r] = t; return n < 0 && (n = 0), isNaN(r) && (r = 0), [ e, // L is still L n * Math.cos(r * Math.PI / 180), // a n * Math.sin(r * Math.PI / 180) // b ]; }, formats: { lch: { coords: ["<number> | <percentage>", "<number> | <percentage>", "<number> | <angle>"] } } }); const je = 25 ** 7, Ut = Math.PI, Ge = 180 / Ut, ht = Ut / 180; function He(t) { const e = t * t; return e * e * e * t; } function Jn(t, e, { kL: n = 1, kC: r = 1, kH: s = 1 } = {}) { [t, e] = C([t, e]); let [a, o, i] = Y.from(t), c = kt.from(Y, [a, o, i])[1], [l, u, f] = Y.from(e), d = kt.from(Y, [l, u, f])[1]; c < 0 && (c = 0), d < 0 && (d = 0); let h = (c + d) / 2, m = He(h), g = 0.5 * (1 - Math.sqrt(m / (m + je))), p = (1 + g) * o, M = (1 + g) * u, w = Math.sqrt(p ** 2 + i ** 2), _ = Math.sqrt(M ** 2 + f ** 2), y = p === 0 && i === 0 ? 0 : Math.atan2(i, p), I = M === 0 && f === 0 ? 0 : Math.atan2(f, M); y < 0 && (y += 2 * Ut), I < 0 && (I += 2 * Ut), y *= Ge, I *= Ge; let B = l - a, x = _ - w, v = I - y, E = y + I, G = Math.abs(v), Z; w * _ === 0 ? Z = 0 : G <= 180 ? Z = v : v > 180 ? Z = v - 360 : v < -180 ? Z = v + 360 : j.warn("the unthinkable has happened"); let lt = 2 * Math.sqrt(_ * w) * Math.sin(Z * ht / 2), V = (a + l) / 2, U = (w + _) / 2, H = He(U), O; w * _ === 0 ? O = E : G <= 180 ? O = E / 2 : E < 360 ? O = (E + 360) / 2 : O = (E - 360) / 2; let K = (V - 50) ** 2, W = 1 + 0.015 * K / Math.sqrt(20 + K), J = 1 + 0.045 * U, N = 1; N -= 0.17 * Math.cos((O - 30) * ht), N += 0.24 * Math.cos(2 * O * ht), N += 0.32 * Math.cos((3 * O + 6) * ht), N -= 0.2 * Math.cos((4 * O - 63) * ht); let R = 1 + 0.015 * U * N, _t = 30 * Math.exp(-1 * ((O - 275) / 25) ** 2), It = 2 * Math.sqrt(H / (H + je)), ot = -1 * Math.sin(2 * _t * ht) * It, D = (B / (n * W)) ** 2; return D += (x / (r * J)) ** 2, D += (lt / (s * R)) ** 2, D += ot * (x / (r * J)) * (lt / (s * R)), Math.sqrt(D); } const Hr = [ [0.819022437996703, 0.3619062600528904, -0.1288737815209879], [0.0329836539323885, 0.9292868615863434, 0.0361446663506424], [0.0481771893596242, 0.2642395317527308, 0.6335478284694309] ], Fr = [ [1.2268798758459243, -0.5578149944602171, 0.2813910456659647], [-0.0405757452148008, 1.112286803280317, -0.0717110580655164], [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816] ], Xr = [ [0.210454268309314, 0.7936177747023054, -0.0040720430116193], [1.9779985324311684, -2.42859224204858, 0.450593709617411], [0.0259040424655478, 0.7827717124575296, -0.8086757549230774] ], Zr = [ [1, 0.3963377773761749, 0.2158037573099136], [1, -0.1055613458156586, -0.0638541728258133], [1, -0.0894841775298119, -1.2914855480194092] ]; var bt = new b({ id: "oklab", name: "Oklab", coords: { l: { refRange: [0, 1], name: "Lightness" }, a: { refRange: [-0.4, 0.4] }, b: { refRange: [-0.4, 0.4] } }, // Note that XYZ is relative to D65 white: "D65", base: P, fromBase(t) { let n = k(Hr, t).map((r) => Math.cbrt(r)); return k(Xr, n); }, toBase(t) { let n = k(Zr, t).map((r) => r ** 3); return k(Fr, n); }, formats: { oklab: { coords: ["<percentage> | <number>", "<number> | <percentage>[-1,1]", "<number> | <percentage>[-1,1]"] } } }); function we(t, e) { [t, e] = C([t, e]); let [n, r, s] = bt.from(t), [a, o, i] = bt.from(e), c = n - a, l = r - o, u = s - i; return Math.sqrt(c ** 2 + l ** 2 + u ** 2); } const Vr = 75e-6; function ct(t, e, { epsilon: n = Vr } = {}) { t = C(t), e || (e = t.space), e = b.get(e); let r = t.coords; return e !== t.space && (r = e.from(t)), e.inGamut(r, { epsilon: n }); } function Mt(t) { return { space: t.space, coords: t.coords.slice(), alpha: t.alpha }; } function Qn(t, e, n = "lab") { n = b.get(n); let r = n.from(t), s = n.from(e); return Math.sqrt(r.reduce((a, o, i) => { let c = s[i]; return isNaN(o) || isNaN(c) ? a : a + (c - o) ** 2; }, 0)); } function Wr(t, e) { return Qn(t, e, "lab"); } const Jr = Math.PI, Fe = Jr / 180; function Qr(t, e, { l: n = 2, c: r = 1 } = {}) { [t, e] = C([t, e]); let [s, a, o] = Y.from(t), [, i, c] = kt.from(Y, [s, a, o]), [l, u, f] = Y.from(e), d = kt.from(Y, [l, u, f])[1]; i < 0 && (i = 0), d < 0 && (d = 0); let h = s - l, m = i - d, g = a - u, p = o - f, M = g ** 2 + p ** 2 - m ** 2, w = 0.511; s >= 16 && (w = 0.040975 * s / (1 + 0.01765 * s)); let _ = 0.0638 * i / (1 + 0.0131 * i) + 0.638, y; Number.isNaN(c) && (c = 0), c >= 164 && c <= 345 ? y = 0.56 + Math.abs(0.2 * Math.cos((c + 168) * Fe)) : y = 0.36 + Math.abs(0.4 * Math.cos((c + 35) * Fe)); let I = Math.pow(i, 4), B = Math.sqrt(I / (I + 1900)), x = _ * (B * y + 1 - B), v = (h / (n * w)) ** 2; return v += (m / (r * _)) ** 2, v += M / x ** 2, Math.sqrt(v); } const Xe = 203; var Le = new b({ // Absolute CIE XYZ, with a D65 whitepoint, // as used in most HDR colorspaces as a starting point. // SDR spaces are converted per BT.2048 // so that diffuse, media white is 203 cd/m² id: "xyz-abs-d65", cssId: "--xyz-abs-d65", name: "Absolute XYZ D65", coords: { x: { refRange: [0, 9504.7], name: "Xa" }, y: { refRange: [0, 1e4], name: "Ya" }, z: { refRange: [0, 10888.3], name: "Za" } }, base: P, fromBase(t) { return t.map((e) => Math.max(e * Xe, 0)); }, toBase(t) { return t.map((e) => Math.max(e / Xe, 0)); } }); const Yt = 1.15, jt = 0.66, Ze = 2610 / 2 ** 14, Ur = 2 ** 14 / 2610, Ve = 3424 / 2 ** 12, We = 2413 / 2 ** 7, Je = 2392 / 2 ** 7, Kr = 1.7 * 2523 / 2 ** 5, Qe = 2 ** 5 / (1.7 * 2523), Gt = -0.56, ie = 16295499532821565e-27, ts = [ [0.41478972, 0.579999, 0.014648], [-0.20151, 1.120649, 0.0531008], [-0.0166008, 0.2648, 0.6684799] ], es = [ [1.9242264357876067, -1.0047923125953657, 0.037651404030618], [0.35031676209499907, 0.7264811939316552, -0.06538442294808501], [-0.09098281098284752, -0.3127282905230739, 1.5227665613052603] ], ns = [ [0.5, 0.5, 0], [3.524, -4.066708, 0.542708], [0.199076, 1.096799, -1.295875] ], rs = [ [1, 0.1386050432715393, 0.05804731615611886], [0.9999999999999999, -0.1386050432715393, -0.05804731615611886], [0.9999999999999998, -0.09601924202631895, -0.8118918960560388] ]; var Un = new b({ id: "jzazbz", name: "Jzazbz", coords: { jz: { refRange: [0, 1], name: "Jz" }, az: { refRange: [-0.5, 0.5] }, bz: { refRange: [-0.5, 0.5] } }, base: Le, fromBase(t) { let [e, n, r] = t, s = Yt * e - (Yt - 1) * r, a = jt * n - (jt - 1) * e, i = k(ts, [s, a, r]).map(function(d) { let h = Ve + We * (d / 1e4) ** Ze, m = 1 + Je * (d / 1e4) ** Ze; return (h / m) ** Kr; }), [c, l, u] = k(ns, i); return [(1 + Gt) * c / (1 + Gt * c) - ie, l, u]; }, toBase(t) { let [e, n, r] = t, s = (e + ie) / (1 + Gt - Gt * (e + ie)), o = k(rs, [s, n, r]).map(function(d) { let h = Ve - d ** Qe, m = Je * d ** Qe - We; return 1e4 * (h / m) ** Ur; }), [i, c, l] = k(es, o), u = (i + (Yt - 1) * l) / Yt, f = (c + (jt - 1) * u) / jt; return [u, f, l]; }, formats: { // https://drafts.csswg.org/css-color-hdr/#Jzazbz color: { coords: ["<number> | <percentage>", "<number> | <percentage>[-1,1]", "<number> | <percentage>[-1,1]"] } } }), ye = new b({ id: "jzczhz", name: "JzCzHz", coords: { jz: { refRange: [0, 1], name: "Jz" }, cz: { refRange: [0, 1], name: "Chroma" }, hz: { refRange: [0, 360], type: "angle", name: "Hue" } }, base: Un, fromBase(t) { let [e, n, r] = t, s; const a = 2e-4; return Math.abs(n) < a && Math.abs(r) < a ? s = NaN : s = Math.atan2(r, n) * 180 / Math.PI, [ e, // Jz is still Jz Math.sqrt(n ** 2 + r ** 2), // Chroma X(s) // Hue, in degrees [0 to 360) ]; }, toBase(t) { return [ t[0], // Jz is still Jz t[1] * Math.cos(t[2] * Math.PI / 180), // az t[1] * Math.sin(t[2] * Math.PI / 180) // bz ]; } }); function ss(t, e) { [t, e] = C([t, e]); let [n, r, s] = ye.from(t), [a, o, i] = ye.from(e), c = n - a, l = r - o; Number.isNaN(s) && Number.isNaN(i) ? (s = 0, i = 0) : Number.isNaN(s) ? s = i : Number.isNaN(i) && (i = s); let u = s - i, f = 2 * Math.sqrt(r * o) * Math.sin(u / 2 * (Math.PI / 180)); return Math.sqrt(c ** 2 + l ** 2 + f ** 2); } const Kn = 3424 / 4096, tr = 2413 / 128, er = 2392 / 128, Ue = 2610 / 16384, as = 2523 / 32, os = 16384 / 2610, Ke = 32 / 2523, is = [ [0.3592832590121217, 0.6976051147779502, -0.035891593232029], [-0.1920808463704993, 1.100476797037432, 0.0753748658519118], [0.0070797844607479, 0.0748396662186362, 0.8433265453898765] ], cs = [ [2048 / 4096, 2048 / 4096, 0], [6610 / 4096, -13613 / 4096, 7003 / 4096], [17933 / 4096, -17390 / 4096, -543 / 4096] ], ls = [ [0.9999999999999998, 0.0086090370379328, 0.111029625003026], [0.9999999999999998, -0.0086090370379328, -0.1110296250030259], [0.9999999999999998, 0.5600313357106791, -0.3206271749873188] ], us = [ [2.0701522183894223, -1.3263473389671563, 0.2066510476294053], [0.3647385209748072, 0.6805660249472273, -0.0453045459220347], [-0.0497472075358123, -0.0492609666966131, 1.1880659249923042] ]; var _e = new b({ id: "ictcp", name: "ICTCP", // From BT.2100-2 page 7: // During production, signal values are expected to exceed the // range E′ = [0.0 : 1.0]. This provides processing headroom and avoids // signal degradation during cascaded processing. Such values of E′, // below 0.0 or exceeding 1.0, should not be clipped during production // and exchange. // Values below 0.0 should not be clipped in reference displays (even // though they represent “negative” light) to allow the black level of // the signal (LB) to be properly set using test signals known as “PLUGE” coords: { i: { refRange: [0, 1], // Constant luminance, name: "I" }, ct: { refRange: [-0.5, 0.5], // Full BT.2020 gamut in range [-0.5, 0.5] name: "CT" }, cp: { refRange: [-0.5, 0.5], name: "CP" } }, base: Le, fromBase(t) { let e = k(is, t); return fs(e); }, toBase(t) { let e = hs(t); return k(us, e); } }); function fs(t) { let e = t.map(function(n) { let r = Kn + tr * (n / 1e4) ** Ue, s = 1 + er * (n / 1e4) ** Ue; return (r / s) ** as; }); return k(cs, e); } function hs(t) { return k(ls, t).map(function(r) { let s = Math.max(r ** Ke - Kn, 0), a = tr - er * r ** Ke; return 1e4 * (s / a) ** os; }); } function ms(t, e) { [t, e] = C([t, e]); let [n, r, s] = _e.from(t), [a, o, i] = _e.from(e); return 720 * Math.sqrt((n - a) ** 2 + 0.25 * (r - o) ** 2 + (s - i) ** 2); } const ds = z.D65, nr = 0.42, tn = 1 / nr, ce = 2 * Math.PI, rr = [ [0.401288, 0.650173, -0.051461], [-0.250268, 1.204414, 0.045854], [-2079e-6, 0.048952, 0.953127] ], gs = [ [1.8620678550872327, -1.0112546305316843, 0.14918677544445175], [0.38752654323613717, 0.6214474419314753, -0.008973985167612518], [-0.015841498849333856, -0.03412293802851557, 1.0499644368778496] ], ps = [ [460, 451, 288], [460, -891, -261], [460, -220, -6300] ], bs = { dark: [0.8, 0.525, 0.8], dim: [0.9, 0.59, 0.9], average: [1, 0.69, 1] }, it = { // Red, Yellow, Green, Blue, Red h: [20.14, 90, 164.25, 237.53, 380.14], e: [0.8, 0.7, 1, 1.2, 0.8], H: [0, 100, 200, 300, 400] }, Ms = 180 / Math.PI, en = Math.PI / 180; function sr(t, e) { return t.map((r) => { const s = F(e * Math.abs(r) * 0.01, nr); return 400 * te(s, r) / (s + 27.13); }); } function ws(t, e) { const n = 100 / e * 27.13 ** tn; return t.map((r) => { const s = Math.abs(r); return te(n * F(s / (400 - s), tn), r); }); } function ys(t) { let e = X(t); e <= it.h[0] && (e += 360); const n = Vn(it.h, e) - 1, [r, s] = it.h.slice(n, n + 2), [a, o] = it.e.slice(n, n + 2), i = it.H[n], c = (e - r) / a; return i + 100 * c / (c + (s - e) / o); } function _s(t) { let e = (t % 400 + 400) % 400; const n = Math.floor(0.01 * e); e = e % 100; const [r, s] = it.h.slice(n, n + 2), [a, o] = it.e.slice(n, n + 2); return X( (e * (o * r - a * s) - 100 * r * o) / (e * (o - a) - 100 * o) ); } function ar(t, e, n, r, s) { const a = {}; a.discounting = s, a.refWhite = t, a.surround = r; const o = t.map((g) => g * 100); a.la = e, a.yb = n; const i = o[1], c = k(rr, o); r = bs[a.surround]; const l = r[0]; a.c = r[1], a.nc = r[2]; const f = (1 / (5 * a.la + 1)) ** 4; a.fl = f * a.la + 0.1 * (1 - f) * (1 - f) * Math.cbrt(5 * a.la), a.flRoot = a.fl ** 0.25, a.n = a.yb / i, a.z = 1.48 + Math.sqrt(a.n), a.nbb = 0.725 * a.n ** -0.2, a.ncb = a.nbb; const d = Math.max( Math.min(l * (1 - 1 / 3.6 * Math.exp((-a.la - 42) / 92)), 1), 0 ); a.dRgb = c.map((g) => St(1, i / g, d)), a.dRgbInv = a.dRgb.map((g) => 1 / g); const h = c.map((g, p) => g * a.dRgb[p]), m = sr(h, a.fl); return a.aW = a.nbb * (2 * m[0] + m[1] + 0.05 * m[2]), a; } const nn = ar( ds, 64 / Math.PI * 0.2, 20, "average", !1 ); function Ie(t, e) { if (!(t.J !== void 0 ^ t.Q !== void 0)) throw new Error("Conversion requires one and only one: 'J' or 'Q'"); if (!(t.C !== void 0 ^ t.M !== void 0 ^ t.s !== void 0)) throw new Error("Conversion requires one and only one: 'C', 'M' or 's'"); if (!(t.h !== void 0 ^ t.H !== void 0)) throw new Error("Conversion requires one and only one: 'h' or 'H'"); if (t.J === 0 || t.Q === 0) return [0, 0, 0]; let n = 0; t.h !== void 0 ? n = X(t.h) * en : n = _s(t.H) * en; const r = Math.cos(n),