PluginProbe
Gutenberg / 23.6.2
Gutenberg v23.6.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / theme / index.js

index.js in Gutenberg 23.6.2, at build/scripts/theme/index.js

4,440 lines 134.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var wp;
2 (wp ||= {}).theme = (() => {
3 var __create = Object.create;
4 var __defProp = Object.defineProperty;
5 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6 var __getOwnPropNames = Object.getOwnPropertyNames;
7 var __getProtoOf = Object.getPrototypeOf;
8 var __hasOwnProp = Object.prototype.hasOwnProperty;
9 var __commonJS = (cb, mod) => function __require() {
10 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11 };
12 var __export = (target, all) => {
13 for (var name in all)
14 __defProp(target, name, { get: all[name], enumerable: true });
15 };
16 var __copyProps = (to2, from, except, desc) => {
17 if (from && typeof from === "object" || typeof from === "function") {
18 for (let key of __getOwnPropNames(from))
19 if (!__hasOwnProp.call(to2, key) && key !== except)
20 __defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21 }
22 return to2;
23 };
24 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25 // If the importer is in node compatibility mode or this is not an ESM
26 // file that has been converted to a CommonJS file using a Babel-
27 // compatible transform (i.e. "__esModule" has not been set), then set
28 // "default" to the CommonJS "module.exports" for node compatibility.
29 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30 mod
31 ));
32 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
34 // package-external:@wordpress/deprecated
35 var require_deprecated = __commonJS({
36 "package-external:@wordpress/deprecated"(exports, module) {
37 module.exports = window.wp.deprecated;
38 }
39 });
40
41 // package-external:@wordpress/private-apis
42 var require_private_apis = __commonJS({
43 "package-external:@wordpress/private-apis"(exports, module) {
44 module.exports = window.wp.privateApis;
45 }
46 });
47
48 // package-external:@wordpress/element
49 var require_element = __commonJS({
50 "package-external:@wordpress/element"(exports, module) {
51 module.exports = window.wp.element;
52 }
53 });
54
55 // package-external:@wordpress/compose
56 var require_compose = __commonJS({
57 "package-external:@wordpress/compose"(exports, module) {
58 module.exports = window.wp.compose;
59 }
60 });
61
62 // vendor-external:react/jsx-runtime
63 var require_jsx_runtime = __commonJS({
64 "vendor-external:react/jsx-runtime"(exports, module) {
65 module.exports = window.ReactJSXRuntime;
66 }
67 });
68
69 // packages/theme/build-module/index.mjs
70 var index_exports = {};
71 __export(index_exports, {
72 ThemeProvider: () => ThemeProvider,
73 privateApis: () => privateApis
74 });
75
76 // packages/theme/build-module/private-apis.mjs
77 var import_deprecated = __toESM(require_deprecated(), 1);
78
79 // packages/theme/build-module/lock-unlock.mjs
80 var import_private_apis = __toESM(require_private_apis(), 1);
81 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
82 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
83 "@wordpress/theme"
84 );
85
86 // packages/theme/build-module/theme-provider.mjs
87 var import_element3 = __toESM(require_element(), 1);
88 var import_compose = __toESM(require_compose(), 1);
89
90 // packages/theme/build-module/context.mjs
91 var import_element = __toESM(require_element(), 1);
92 var ThemeContext = (0, import_element.createContext)({
93 resolvedSettings: {
94 color: {},
95 cursor: void 0,
96 cornerRadius: void 0
97 }
98 });
99
100 // packages/theme/node_modules/colorjs.io/src/multiply-matrices.js
101 function dot3(a, b2) {
102 return a[0] * b2[0] + a[1] * b2[1] + a[2] * b2[2];
103 }
104 function multiply_v3_m3x3(input, matrix, out = [0, 0, 0]) {
105 const x = dot3(input, matrix[0]);
106 const y = dot3(input, matrix[1]);
107 const z = dot3(input, matrix[2]);
108 out[0] = x;
109 out[1] = y;
110 out[2] = z;
111 return out;
112 }
113
114 // packages/theme/node_modules/colorjs.io/src/util.js
115 function isString(str) {
116 return type(str) === "string";
117 }
118 function type(o) {
119 let str = Object.prototype.toString.call(o);
120 return (str.match(/^\[object\s+(.*?)\]$/)[1] || "").toLowerCase();
121 }
122 function serializeNumber(n2, { precision = 16, unit }) {
123 if (isNone(n2)) {
124 return "none";
125 }
126 n2 = +toPrecision(n2, precision);
127 return n2 + (unit ?? "");
128 }
129 function isNone(n2) {
130 return n2 === null;
131 }
132 function toPrecision(n2, precision) {
133 if (n2 === 0) {
134 return 0;
135 }
136 let integer = ~~n2;
137 let digits = 0;
138 if (integer && precision) {
139 digits = ~~Math.log10(Math.abs(integer)) + 1;
140 }
141 const multiplier = 10 ** (precision - digits);
142 return Math.floor(n2 * multiplier + 0.5) / multiplier;
143 }
144 function interpolate(start, end, p2) {
145 if (isNaN(start)) {
146 return end;
147 }
148 if (isNaN(end)) {
149 return start;
150 }
151 return start + (end - start) * p2;
152 }
153 function interpolateInv(start, end, value) {
154 return (value - start) / (end - start);
155 }
156 function mapRange(from, to2, value) {
157 if (!from || !to2 || from === to2 || from[0] === to2[0] && from[1] === to2[1] || isNaN(value) || value === null) {
158 return value;
159 }
160 return interpolate(to2[0], to2[1], interpolateInv(from[0], from[1], value));
161 }
162 function clamp(min, val, max) {
163 return Math.max(Math.min(max, val), min);
164 }
165 function copySign(to2, from) {
166 return Math.sign(to2) === Math.sign(from) ? to2 : -to2;
167 }
168 function spow(base, exp) {
169 return copySign(Math.abs(base) ** exp, base);
170 }
171 function zdiv(n2, d2) {
172 return d2 === 0 ? 0 : n2 / d2;
173 }
174 function bisectLeft(arr, value, lo = 0, hi = arr.length) {
175 while (lo < hi) {
176 const mid = lo + hi >> 1;
177 if (arr[mid] < value) {
178 lo = mid + 1;
179 } else {
180 hi = mid;
181 }
182 }
183 return lo;
184 }
185 function isInstance(arg, constructor) {
186 if (arg instanceof constructor) {
187 return true;
188 }
189 const targetName = constructor.name;
190 while (arg) {
191 const proto = Object.getPrototypeOf(arg);
192 const constructorName = proto?.constructor?.name;
193 if (constructorName === targetName) {
194 return true;
195 }
196 if (!constructorName || constructorName === "Object") {
197 return false;
198 }
199 arg = proto;
200 }
201 return false;
202 }
203
204 // packages/theme/node_modules/colorjs.io/src/Type.js
205 var Type = class {
206 // Class properties - declared here so that type inference works
207 type;
208 coordMeta;
209 coordRange;
210 /** @type {[number, number]} */
211 range;
212 /**
213 * @param {any} type
214 * @param {import("./types.js").CoordMeta} coordMeta
215 */
216 constructor(type2, coordMeta) {
217 if (typeof type2 === "object") {
218 this.coordMeta = type2;
219 }
220 if (coordMeta) {
221 this.coordMeta = coordMeta;
222 this.coordRange = coordMeta.range ?? coordMeta.refRange;
223 }
224 if (typeof type2 === "string") {
225 let params = type2.trim().match(/^(?<type><[a-z]+>)(\[(?<min>-?[.\d]+),\s*(?<max>-?[.\d]+)\])?$/);
226 if (!params) {
227 throw new TypeError(`Cannot parse ${type2} as a type definition.`);
228 }
229 this.type = params.groups.type;
230 let { min, max } = params.groups;
231 if (min || max) {
232 this.range = [+min, +max];
233 }
234 }
235 }
236 /** @returns {[number, number]} */
237 get computedRange() {
238 if (this.range) {
239 return this.range;
240 }
241 if (this.type === "<percentage>") {
242 return this.percentageRange();
243 } else if (this.type === "<angle>") {
244 return [0, 360];
245 }
246 return null;
247 }
248 get unit() {
249 if (this.type === "<percentage>") {
250 return "%";
251 } else if (this.type === "<angle>") {
252 return "deg";
253 }
254 return "";
255 }
256 /**
257 * Map a number to the internal representation
258 * @param {number} number
259 */
260 resolve(number) {
261 if (this.type === "<angle>") {
262 return number;
263 }
264 let fromRange = this.computedRange;
265 let toRange = this.coordRange;
266 if (this.type === "<percentage>") {
267 toRange ??= this.percentageRange();
268 }
269 return mapRange(fromRange, toRange, number);
270 }
271 /**
272 * Serialize a number from the internal representation to a string
273 * @param {number} number
274 * @param {number} [precision]
275 */
276 serialize(number, precision) {
277 let toRange = this.type === "<percentage>" ? this.percentageRange(100) : this.computedRange;
278 let unit = this.unit;
279 number = mapRange(this.coordRange, toRange, number);
280 return serializeNumber(number, { unit, precision });
281 }
282 toString() {
283 let ret = this.type;
284 if (this.range) {
285 let [min = "", max = ""] = this.range;
286 ret += `[${min},${max}]`;
287 }
288 return ret;
289 }
290 /**
291 * Returns a percentage range for values of this type
292 * @param {number} scale
293 * @returns {[number, number]}
294 */
295 percentageRange(scale = 1) {
296 let range;
297 if (this.coordMeta && this.coordMeta.range || this.coordRange && this.coordRange[0] >= 0) {
298 range = [0, 1];
299 } else {
300 range = [-1, 1];
301 }
302 return [range[0] * scale, range[1] * scale];
303 }
304 static get(type2, coordMeta) {
305 if (isInstance(type2, this)) {
306 return type2;
307 }
308 return new this(type2, coordMeta);
309 }
310 };
311
312 // packages/theme/node_modules/colorjs.io/src/Format.js
313 var instance = /* @__PURE__ */ Symbol("instance");
314 var Format = class _Format {
315 // Class properties - declared here so that type inference works
316 type;
317 name;
318 spaceCoords;
319 /** @type {Type[][]} */
320 coords;
321 /** @type {string | undefined} */
322 id;
323 /** @type {boolean | undefined} */
324 alpha;
325 /**
326 * @param {FormatInterface} format
327 * @param {ColorSpace} space
328 */
329 constructor(format, space = format.space) {
330 format[instance] = this;
331 this.type = "function";
332 this.name = "color";
333 Object.assign(this, format);
334 this.space = space;
335 if (this.type === "custom") {
336 return;
337 }
338 this.spaceCoords = Object.values(space.coords);
339 if (!this.coords) {
340 this.coords = this.spaceCoords.map((coordMeta) => {
341 let ret = ["<number>", "<percentage>"];
342 if (coordMeta.type === "angle") {
343 ret.push("<angle>");
344 }
345 return ret;
346 });
347 }
348 this.coords = this.coords.map(
349 /** @param {string | string[] | Type[]} types */
350 (types, i) => {
351 let coordMeta = this.spaceCoords[i];
352 if (typeof types === "string") {
353 types = types.trim().split(/\s*\|\s*/);
354 }
355 return types.map((type2) => Type.get(type2, coordMeta));
356 }
357 );
358 }
359 /**
360 * @param {Coords} coords
361 * @param {number} precision
362 * @param {Type[]} types
363 */
364 serializeCoords(coords, precision, types) {
365 types = coords.map((_, i) => Type.get(types?.[i] ?? this.coords[i][0], this.spaceCoords[i]));
366 return coords.map((c, i) => types[i].serialize(c, precision));
367 }
368 /**
369 * Validates the coordinates of a color against a format's coord grammar and
370 * maps the coordinates to the range or refRange of the coordinates.
371 * @param {Coords} coords
372 * @param {[string, string, string]} types
373 */
374 coerceCoords(coords, types) {
375 return Object.entries(this.space.coords).map(([id, coordMeta], i) => {
376 let arg = coords[i];
377 if (isNone(arg) || isNaN(arg)) {
378 return arg;
379 }
380 let providedType = types[i];
381 let type2 = this.coords[i].find((c) => c.type == providedType);
382 if (!type2) {
383 let coordName = coordMeta.name || id;
384 throw new TypeError(
385 `${providedType ?? /** @type {any} */
386 arg?.raw ?? arg} not allowed for ${coordName} in ${this.name}()`
387 );
388 }
389 arg = type2.resolve(arg);
390 if (type2.range) {
391 types[i] = type2.toString();
392 }
393 return arg;
394 });
395 }
396 /**
397 * @returns {boolean | Required<FormatInterface>["serialize"]}
398 */
399 canSerialize() {
400 return this.type === "function" || /** @type {any} */
401 this.serialize;
402 }
403 /**
404 * @param {string} str
405 * @returns {(import("./types.js").ColorConstructor) | undefined | null}
406 */
407 parse(str) {
408 return null;
409 }
410 /**
411 * @param {Format | FormatInterface} format
412 * @param {RemoveFirstElement<ConstructorParameters<typeof Format>>} args
413 * @returns {Format}
414 */
415 static get(format, ...args) {
416 if (!format || isInstance(format, this)) {
417 return (
418 /** @type {Format} */
419 format
420 );
421 }
422 if (format[instance]) {
423 return format[instance];
424 }
425 return new _Format(format, ...args);
426 }
427 };
428
429 // packages/theme/node_modules/colorjs.io/src/hooks.js
430 var Hooks = class {
431 add(name, callback, first) {
432 if (typeof arguments[0] != "string") {
433 for (var name in arguments[0]) {
434 this.add(name, arguments[0][name], arguments[1]);
435 }
436 return;
437 }
438 (Array.isArray(name) ? name : [name]).forEach(function(name2) {
439 this[name2] = this[name2] || [];
440 if (callback) {
441 this[name2][first ? "unshift" : "push"](callback);
442 }
443 }, this);
444 }
445 run(name, env) {
446 this[name] = this[name] || [];
447 this[name].forEach(function(callback) {
448 callback.call(env && env.context ? env.context : env, env);
449 });
450 }
451 };
452 var hooks = new Hooks();
453 var hooks_default = hooks;
454
455 // packages/theme/node_modules/colorjs.io/src/adapt.js
456 var WHITES = {
457 // for compatibility, the four-digit chromaticity-derived ones everyone else uses
458 D50: [0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585],
459 D65: [0.3127 / 0.329, 1, (1 - 0.3127 - 0.329) / 0.329]
460 };
461 function getWhite(name) {
462 if (Array.isArray(name)) {
463 return name;
464 }
465 return WHITES[name];
466 }
467 function adapt(W1, W2, XYZ, options = {}) {
468 W1 = getWhite(W1);
469 W2 = getWhite(W2);
470 if (!W1 || !W2) {
471 throw new TypeError(
472 `Missing white point to convert ${!W1 ? "from" : ""}${!W1 && !W2 ? "/" : ""}${!W2 ? "to" : ""}`
473 );
474 }
475 if (W1 === W2) {
476 return XYZ;
477 }
478 let env = { W1, W2, XYZ, options };
479 hooks_default.run("chromatic-adaptation-start", env);
480 if (!env.M) {
481 if (env.W1 === WHITES.D65 && env.W2 === WHITES.D50) {
482 env.M = [
483 [1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
484 [0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
485 [-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]
486 ];
487 } else if (env.W1 === WHITES.D50 && env.W2 === WHITES.D65) {
488 env.M = [
489 [0.955473421488075, -0.02309845494876471, 0.06325924320057072],
490 [-0.0283697093338637, 1.0099953980813041, 0.021041441191917323],
491 [0.012314014864481998, -0.020507649298898964, 1.330365926242124]
492 ];
493 }
494 }
495 hooks_default.run("chromatic-adaptation-end", env);
496 if (env.M) {
497 return multiply_v3_m3x3(env.XYZ, env.M);
498 } else {
499 throw new TypeError("Only Bradford CAT with white points D50 and D65 supported for now.");
500 }
501 }
502
503 // packages/theme/node_modules/colorjs.io/src/defaults.js
504 var defaults_default = {
505 gamut_mapping: "css",
506 precision: 5,
507 deltaE: "76",
508 // Default deltaE method
509 verbose: globalThis?.process?.env?.NODE_ENV?.toLowerCase() !== "test",
510 warn: function warn(msg) {
511 if (this.verbose) {
512 globalThis?.console?.warn?.(msg);
513 }
514 }
515 };
516
517 // packages/theme/node_modules/colorjs.io/src/parse.js
518 function parse(str, options) {
519 let env = {
520 str: String(str)?.trim(),
521 options
522 };
523 hooks_default.run("parse-start", env);
524 if (env.color) {
525 return env.color;
526 }
527 env.parsed = parseFunction(env.str);
528 let ret;
529 let meta = env.options ? env.options.parseMeta ?? env.options.meta : null;
530 if (env.parsed) {
531 let name = env.parsed.name;
532 let format;
533 let space;
534 let coords = env.parsed.args;
535 let types = coords.map((c, i) => env.parsed.argMeta[i]?.type);
536 if (name === "color") {
537 let id = coords.shift();
538 types.shift();
539 let alternateId = id.startsWith("--") ? id.substring(2) : `--${id}`;
540 let ids = [id, alternateId];
541 format = ColorSpace.findFormat({ name, id: ids, type: "function" });
542 if (!format) {
543 let didYouMean;
544 let registryId = id in ColorSpace.registry ? id : alternateId;
545 if (registryId in ColorSpace.registry) {
546 let cssId = ColorSpace.registry[registryId].formats?.color?.id;
547 if (cssId) {
548 let altColor = str.replace("color(" + id, "color(" + cssId);
549 didYouMean = `Did you mean ${altColor}?`;
550 }
551 }
552 throw new TypeError(
553 `Cannot parse ${env.str}. ` + (didYouMean ?? "Missing a plugin?")
554 );
555 }
556 space = format.space;
557 if (format.id.startsWith("--") && !id.startsWith("--")) {
558 defaults_default.warn(
559 `${space.name} is a non-standard space and not currently supported in the CSS spec. Use prefixed color(${format.id}) instead of color(${id}).`
560 );
561 }
562 if (id.startsWith("--") && !format.id.startsWith("--")) {
563 defaults_default.warn(
564 `${space.name} is a standard space and supported in the CSS spec. Use color(${format.id}) instead of prefixed color(${id}).`
565 );
566 }
567 } else {
568 format = ColorSpace.findFormat({ name, type: "function" });
569 space = format.space;
570 }
571 if (meta) {
572 Object.assign(meta, {
573 format,
574 formatId: format.name,
575 types,
576 commas: env.parsed.commas
577 });
578 }
579 let alpha = 1;
580 if (env.parsed.lastAlpha) {
581 alpha = env.parsed.args.pop();
582 if (meta) {
583 meta.alphaType = types.pop();
584 }
585 }
586 let coordCount = format.coords.length;
587 if (coords.length !== coordCount) {
588 throw new TypeError(
589 `Expected ${coordCount} coordinates for ${space.id} in ${env.str}), got ${coords.length}`
590 );
591 }
592 coords = format.coerceCoords(coords, types);
593 ret = { spaceId: space.id, coords, alpha };
594 } else {
595 spaceloop: for (let space of ColorSpace.all) {
596 for (let formatId in space.formats) {
597 let format = space.formats[formatId];
598 if (format.type !== "custom") {
599 continue;
600 }
601 if (format.test && !format.test(env.str)) {
602 continue;
603 }
604 let formatObject = space.getFormat(format);
605 let color = formatObject.parse(env.str);
606 if (color) {
607 if (meta) {
608 Object.assign(meta, { format: formatObject, formatId });
609 }
610 ret = color;
611 break spaceloop;
612 }
613 }
614 }
615 }
616 if (!ret) {
617 throw new TypeError(`Could not parse ${str} as a color. Missing a plugin?`);
618 }
619 ret.alpha = isNone(ret.alpha) ? ret.alpha : ret.alpha === void 0 ? 1 : clamp(0, ret.alpha, 1);
620 return ret;
621 }
622 var units = {
623 "%": 0.01,
624 deg: 1,
625 grad: 0.9,
626 rad: 180 / Math.PI,
627 turn: 360
628 };
629 var regex = {
630 // Need to list calc(NaN) explicitly as otherwise its ending paren would terminate the function call
631 function: /^([a-z]+)\(((?:calc\(NaN\)|.)+?)\)$/i,
632 number: /^([-+]?(?:[0-9]*\.)?[0-9]+(e[-+]?[0-9]+)?)$/i,
633 unitValue: RegExp(`(${Object.keys(units).join("|")})$`),
634 // NOTE The -+ are not just for prefix, but also for idents, and e+N notation!
635 singleArgument: /\/?\s*(none|NaN|calc\(NaN\)|[-+\w.]+(?:%|deg|g?rad|turn)?)/g
636 };
637 function parseArgument(rawArg) {
638 let meta = {};
639 let unit = rawArg.match(regex.unitValue)?.[0];
640 let value = meta.raw = rawArg;
641 if (unit) {
642 meta.type = unit === "%" ? "<percentage>" : "<angle>";
643 meta.unit = unit;
644 meta.unitless = Number(value.slice(0, -unit.length));
645 value = meta.unitless * units[unit];
646 } else if (regex.number.test(value)) {
647 value = Number(value);
648 meta.type = "<number>";
649 } else if (value === "none") {
650 value = null;
651 } else if (value === "NaN" || value === "calc(NaN)") {
652 value = NaN;
653 meta.type = "<number>";
654 } else {
655 meta.type = "<ident>";
656 }
657 return { value: (
658 /** @type {number} */
659 value
660 ), meta: (
661 /** @type {ArgumentMeta} */
662 meta
663 ) };
664 }
665 function parseFunction(str) {
666 if (!str) {
667 return;
668 }
669 str = str.trim();
670 let parts = str.match(regex.function);
671 if (parts) {
672 let args = [];
673 let argMeta = [];
674 let lastAlpha = false;
675 let name = parts[1].toLowerCase();
676 let separators = parts[2].replace(regex.singleArgument, ($0, rawArg) => {
677 let { value, meta } = parseArgument(rawArg);
678 if (
679 // If there's a slash here, it's modern syntax
680 $0.startsWith("/") || // If there's still elements to process after there's already 3 in `args` (and the we're not dealing with "color()"), it's likely to be a legacy color like "hsl(0, 0%, 0%, 0.5)"
681 name !== "color" && args.length === 3
682 ) {
683 lastAlpha = true;
684 }
685 args.push(value);
686 argMeta.push(meta);
687 return "";
688 });
689 return {
690 name,
691 args,
692 argMeta,
693 lastAlpha,
694 commas: separators.includes(","),
695 rawName: parts[1],
696 rawArgs: parts[2]
697 };
698 }
699 }
700
701 // packages/theme/node_modules/colorjs.io/src/getColor.js
702 function getColor(color, options) {
703 if (Array.isArray(color)) {
704 return color.map((c) => getColor(c, options));
705 }
706 if (!color) {
707 throw new TypeError("Empty color reference");
708 }
709 if (isString(color)) {
710 color = parse(color, options);
711 }
712 let space = color.space || color.spaceId;
713 if (typeof space === "string") {
714 color.space = ColorSpace.get(space);
715 }
716 if (color.alpha === void 0) {
717 color.alpha = 1;
718 }
719 return color;
720 }
721
722 // packages/theme/node_modules/colorjs.io/src/ColorSpace.js
723 var \u03B5 = 75e-6;
724 var ColorSpace = class _ColorSpace {
725 constructor(options) {
726 this.id = options.id;
727 this.name = options.name;
728 this.base = options.base ? _ColorSpace.get(options.base) : null;
729 this.aliases = options.aliases;
730 if (this.base) {
731 this.fromBase = options.fromBase;
732 this.toBase = options.toBase;
733 }
734 let coords = options.coords ?? this.base.coords;
735 for (let name in coords) {
736 if (!("name" in coords[name])) {
737 coords[name].name = name;
738 }
739 }
740 this.coords = coords;
741 let white4 = options.white ?? this.base.white ?? "D65";
742 this.white = getWhite(white4);
743 this.formats = options.formats ?? {};
744 for (let name in this.formats) {
745 let format = this.formats[name];
746 format.type ||= "function";
747 format.name ||= name;
748 }
749 if (!this.formats.color?.id) {
750 this.formats.color = {
751 ...this.formats.color ?? {},
752 id: options.cssId || this.id
753 };
754 }
755 if (options.gamutSpace) {
756 this.gamutSpace = options.gamutSpace === "self" ? this : _ColorSpace.get(options.gamutSpace);
757 } else {
758 if (this.isPolar) {
759 this.gamutSpace = this.base;
760 } else {
761 this.gamutSpace = this;
762 }
763 }
764 if (this.gamutSpace.isUnbounded) {
765 this.inGamut = (coords2, options2) => {
766 return true;
767 };
768 }
769 this.referred = options.referred;
770 Object.defineProperty(this, "path", {
771 value: getPath(this).reverse(),
772 writable: false,
773 enumerable: true,
774 configurable: true
775 });
776 hooks_default.run("colorspace-init-end", this);
777 }
778 inGamut(coords, { epsilon = \u03B5 } = {}) {
779 if (!this.equals(this.gamutSpace)) {
780 coords = this.to(this.gamutSpace, coords);
781 return this.gamutSpace.inGamut(coords, { epsilon });
782 }
783 let coordMeta = Object.values(this.coords);
784 return coords.every((c, i) => {
785 let meta = coordMeta[i];
786 if (meta.type !== "angle" && meta.range) {
787 if (isNone(c)) {
788 return true;
789 }
790 let [min, max] = meta.range;
791 return (min === void 0 || c >= min - epsilon) && (max === void 0 || c <= max + epsilon);
792 }
793 return true;
794 });
795 }
796 get isUnbounded() {
797 return Object.values(this.coords).every((coord) => !("range" in coord));
798 }
799 get cssId() {
800 return this.formats?.color?.id || this.id;
801 }
802 get isPolar() {
803 for (let id in this.coords) {
804 if (this.coords[id].type === "angle") {
805 return true;
806 }
807 }
808 return false;
809 }
810 /**
811 * Lookup a format in this color space
812 * @param {string | object | Format} format - Format id if string. If object, it's converted to a `Format` object and returned.
813 * @returns {Format}
814 */
815 getFormat(format) {
816 if (!format) {
817 return null;
818 }
819 if (format === "default") {
820 format = Object.values(this.formats)[0];
821 } else if (typeof format === "string") {
822 format = this.formats[format];
823 }
824 let ret = Format.get(format, this);
825 if (ret !== format && format.name in this.formats) {
826 this.formats[format.name] = ret;
827 }
828 return ret;
829 }
830 /**
831 * Check if this color space is the same as another color space reference.
832 * Allows proxying color space objects and comparing color spaces with ids.
833 * @param {string | ColorSpace} space ColorSpace object or id to compare to
834 * @returns {boolean}
835 */
836 equals(space) {
837 if (!space) {
838 return false;
839 }
840 return this === space || this.id === space || this.id === space.id;
841 }
842 to(space, coords) {
843 if (arguments.length === 1) {
844 const color = getColor(space);
845 [space, coords] = [color.space, color.coords];
846 }
847 space = _ColorSpace.get(space);
848 if (this.equals(space)) {
849 return coords;
850 }
851 coords = coords.map((c) => isNone(c) ? 0 : c);
852 let myPath = this.path;
853 let otherPath = space.path;
854 let connectionSpace, connectionSpaceIndex;
855 for (let i = 0; i < myPath.length; i++) {
856 if (myPath[i].equals(otherPath[i])) {
857 connectionSpace = myPath[i];
858 connectionSpaceIndex = i;
859 } else {
860 break;
861 }
862 }
863 if (!connectionSpace) {
864 throw new Error(
865 `Cannot convert between color spaces ${this} and ${space}: no connection space was found`
866 );
867 }
868 for (let i = myPath.length - 1; i > connectionSpaceIndex; i--) {
869 coords = myPath[i].toBase(coords);
870 }
871 for (let i = connectionSpaceIndex + 1; i < otherPath.length; i++) {
872 coords = otherPath[i].fromBase(coords);
873 }
874 return coords;
875 }
876 from(space, coords) {
877 if (arguments.length === 1) {
878 const color = getColor(space);
879 [space, coords] = [color.space, color.coords];
880 }
881 space = _ColorSpace.get(space);
882 return space.to(this, coords);
883 }
884 toString() {
885 return `${this.name} (${this.id})`;
886 }
887 getMinCoords() {
888 let ret = [];
889 for (let id in this.coords) {
890 let meta = this.coords[id];
891 let range = meta.range || meta.refRange;
892 ret.push(range?.min ?? 0);
893 }
894 return ret;
895 }
896 static registry = {};
897 // Returns array of unique color spaces
898 static get all() {
899 return [...new Set(Object.values(_ColorSpace.registry))];
900 }
901 static register(id, space) {
902 if (arguments.length === 1) {
903 space = arguments[0];
904 id = space.id;
905 }
906 space = this.get(space);
907 if (this.registry[id] && this.registry[id] !== space) {
908 throw new Error(`Duplicate color space registration: '${id}'`);
909 }
910 this.registry[id] = space;
911 if (arguments.length === 1 && space.aliases) {
912 for (let alias of space.aliases) {
913 this.register(alias, space);
914 }
915 }
916 return space;
917 }
918 /**
919 * Lookup ColorSpace object by name
920 * @param {ColorSpace | string} name
921 */
922 static get(space, ...alternatives) {
923 if (!space || isInstance(space, this)) {
924 return space;
925 }
926 let argType = type(space);
927 if (argType === "string") {
928 let ret = _ColorSpace.registry[space.toLowerCase()];
929 if (!ret) {
930 throw new TypeError(`No color space found with id = "${space}"`);
931 }
932 return ret;
933 }
934 if (alternatives.length) {
935 return _ColorSpace.get(...alternatives);
936 }
937 throw new TypeError(`${space} is not a valid color space`);
938 }
939 /**
940 * Look up all color spaces for a format that matches certain criteria
941 * @param {object | string} filters
942 * @param {Array<ColorSpace>} [spaces=ColorSpace.all]
943 * @returns {Format | null}
944 */
945 static findFormat(filters, spaces = _ColorSpace.all) {
946 if (!filters) {
947 return null;
948 }
949 if (typeof filters === "string") {
950 filters = { name: filters };
951 }
952 for (let space of spaces) {
953 for (let [name, format] of Object.entries(space.formats)) {
954 format.name ??= name;
955 format.type ??= "function";
956 let matches = (!filters.name || format.name === filters.name) && (!filters.type || format.type === filters.type);
957 if (filters.id) {
958 let ids = format.ids || [format.id];
959 let filterIds = Array.isArray(filters.id) ? filters.id : [filters.id];
960 matches &&= filterIds.some((id) => ids.includes(id));
961 }
962 if (matches) {
963 let ret = Format.get(format, space);
964 if (ret !== format) {
965 space.formats[format.name] = ret;
966 }
967 return ret;
968 }
969 }
970 }
971 return null;
972 }
973 /**
974 * Get metadata about a coordinate of a color space
975 *
976 * @static
977 * @param {Array | string} ref
978 * @param {ColorSpace | string} [workingSpace]
979 * @return {Object}
980 */
981 static resolveCoord(ref, workingSpace) {
982 let coordType = type(ref);
983 let space, coord;
984 if (coordType === "string") {
985 if (ref.includes(".")) {
986 [space, coord] = ref.split(".");
987 } else {
988 [space, coord] = [, ref];
989 }
990 } else if (Array.isArray(ref)) {
991 [space, coord] = ref;
992 } else {
993 space = ref.space;
994 coord = ref.coordId;
995 }
996 space = _ColorSpace.get(space);
997 if (!space) {
998 space = workingSpace;
999 }
1000 if (!space) {
1001 throw new TypeError(
1002 `Cannot resolve coordinate reference ${ref}: No color space specified and relative references are not allowed here`
1003 );
1004 }
1005 coordType = type(coord);
1006 if (coordType === "number" || coordType === "string" && coord >= 0) {
1007 let meta = Object.entries(space.coords)[coord];
1008 if (meta) {
1009 return { space, id: meta[0], index: coord, ...meta[1] };
1010 }
1011 }
1012 space = _ColorSpace.get(space);
1013 let normalizedCoord = coord.toLowerCase();
1014 let i = 0;
1015 for (let id in space.coords) {
1016 let meta = space.coords[id];
1017 if (id.toLowerCase() === normalizedCoord || meta.name?.toLowerCase() === normalizedCoord) {
1018 return { space, id, index: i, ...meta };
1019 }
1020 i++;
1021 }
1022 throw new TypeError(
1023 `No "${coord}" coordinate found in ${space.name}. Its coordinates are: ${Object.keys(space.coords).join(", ")}`
1024 );
1025 }
1026 static DEFAULT_FORMAT = {
1027 type: "functions",
1028 name: "color"
1029 };
1030 };
1031 function getPath(space) {
1032 let ret = [space];
1033 for (let s = space; s = s.base; ) {
1034 ret.push(s);
1035 }
1036 return ret;
1037 }
1038
1039 // packages/theme/node_modules/colorjs.io/src/spaces/xyz-d65.js
1040 var xyz_d65_default = new ColorSpace({
1041 id: "xyz-d65",
1042 name: "XYZ D65",
1043 coords: {
1044 x: {
1045 refRange: [0, 1],
1046 name: "X"
1047 },
1048 y: {
1049 refRange: [0, 1],
1050 name: "Y"
1051 },
1052 z: {
1053 refRange: [0, 1],
1054 name: "Z"
1055 }
1056 },
1057 white: "D65",
1058 formats: {
1059 color: {
1060 ids: ["xyz-d65", "xyz"]
1061 }
1062 },
1063 aliases: ["xyz"]
1064 });
1065
1066 // packages/theme/node_modules/colorjs.io/src/RGBColorSpace.js
1067 var RGBColorSpace = class extends ColorSpace {
1068 /**
1069 * Creates a new RGB ColorSpace.
1070 * If coords are not specified, they will use the default RGB coords.
1071 * Instead of `fromBase()` and `toBase()` functions,
1072 * you can specify to/from XYZ matrices and have `toBase()` and `fromBase()` automatically generated.
1073 * @param {RGBOptions} options
1074 */
1075 constructor(options) {
1076 if (!options.coords) {
1077 options.coords = {
1078 r: {
1079 range: [0, 1],
1080 name: "Red"
1081 },
1082 g: {
1083 range: [0, 1],
1084 name: "Green"
1085 },
1086 b: {
1087 range: [0, 1],
1088 name: "Blue"
1089 }
1090 };
1091 }
1092 if (!options.base) {
1093 options.base = xyz_d65_default;
1094 }
1095 if (options.toXYZ_M && options.fromXYZ_M) {
1096 options.toBase ??= (rgb) => {
1097 let xyz = multiply_v3_m3x3(rgb, options.toXYZ_M);
1098 if (this.white !== this.base.white) {
1099 xyz = adapt(this.white, this.base.white, xyz);
1100 }
1101 return xyz;
1102 };
1103 options.fromBase ??= (xyz) => {
1104 xyz = adapt(this.base.white, this.white, xyz);
1105 return multiply_v3_m3x3(xyz, options.fromXYZ_M);
1106 };
1107 }
1108 options.referred ??= "display";
1109 super(options);
1110 }
1111 };
1112
1113 // packages/theme/node_modules/colorjs.io/src/getAll.js
1114 function getAll(color, options) {
1115 color = getColor(color);
1116 let space = ColorSpace.get(options, options?.space);
1117 let precision = options?.precision;
1118 let coords;
1119 if (!space || color.space.equals(space)) {
1120 coords = color.coords.slice();
1121 } else {
1122 coords = space.from(color);
1123 }
1124 return precision === void 0 ? coords : coords.map((coord) => toPrecision(coord, precision));
1125 }
1126
1127 // packages/theme/node_modules/colorjs.io/src/get.js
1128 function get(color, prop) {
1129 color = getColor(color);
1130 if (prop === "alpha") {
1131 return color.alpha ?? 1;
1132 }
1133 let { space, index } = ColorSpace.resolveCoord(prop, color.space);
1134 let coords = getAll(color, space);
1135 return coords[index];
1136 }
1137
1138 // packages/theme/node_modules/colorjs.io/src/setAll.js
1139 function setAll(color, space, coords, alpha) {
1140 color = getColor(color);
1141 if (Array.isArray(space)) {
1142 [space, coords, alpha] = [color.space, space, coords];
1143 }
1144 space = ColorSpace.get(space);
1145 color.coords = space === color.space ? coords.slice() : space.to(color.space, coords);
1146 if (alpha !== void 0) {
1147 color.alpha = alpha;
1148 }
1149 return color;
1150 }
1151 setAll.returns = "color";
1152
1153 // packages/theme/node_modules/colorjs.io/src/set.js
1154 function set(color, prop, value) {
1155 color = getColor(color);
1156 if (arguments.length === 2 && type(arguments[1]) === "object") {
1157 let object = arguments[1];
1158 for (let p2 in object) {
1159 set(color, p2, object[p2]);
1160 }
1161 } else {
1162 if (typeof value === "function") {
1163 value = value(get(color, prop));
1164 }
1165 if (prop === "alpha") {
1166 color.alpha = value;
1167 } else {
1168 let { space, index } = ColorSpace.resolveCoord(prop, color.space);
1169 let coords = getAll(color, space);
1170 coords[index] = value;
1171 setAll(color, space, coords);
1172 }
1173 }
1174 return color;
1175 }
1176 set.returns = "color";
1177
1178 // packages/theme/node_modules/colorjs.io/src/spaces/xyz-d50.js
1179 var xyz_d50_default = new ColorSpace({
1180 id: "xyz-d50",
1181 name: "XYZ D50",
1182 white: "D50",
1183 base: xyz_d65_default,
1184 fromBase: (coords) => adapt(xyz_d65_default.white, "D50", coords),
1185 toBase: (coords) => adapt("D50", xyz_d65_default.white, coords)
1186 });
1187
1188 // packages/theme/node_modules/colorjs.io/src/spaces/lab.js
1189 var \u03B52 = 216 / 24389;
1190 var \u03B53 = 24 / 116;
1191 var \u03BA = 24389 / 27;
1192 var white = WHITES.D50;
1193 var lab_default = new ColorSpace({
1194 id: "lab",
1195 name: "Lab",
1196 coords: {
1197 l: {
1198 refRange: [0, 100],
1199 name: "Lightness"
1200 },
1201 a: {
1202 refRange: [-125, 125]
1203 },
1204 b: {
1205 refRange: [-125, 125]
1206 }
1207 },
1208 // Assuming XYZ is relative to D50, convert to CIE Lab
1209 // from CIE standard, which now defines these as a rational fraction
1210 white,
1211 base: xyz_d50_default,
1212 // Convert D50-adapted XYX to Lab
1213 // CIE 15.3:2004 section 8.2.1.1
1214 fromBase(XYZ) {
1215 let xyz = XYZ.map((value, i) => value / white[i]);
1216 let f = xyz.map((value) => value > \u03B52 ? Math.cbrt(value) : (\u03BA * value + 16) / 116);
1217 let L = 116 * f[1] - 16;
1218 let a = 500 * (f[0] - f[1]);
1219 let b2 = 200 * (f[1] - f[2]);
1220 return [L, a, b2];
1221 },
1222 // Convert Lab to D50-adapted XYZ
1223 // Same result as CIE 15.3:2004 Appendix D although the derivation is different
1224 // http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
1225 toBase(Lab) {
1226 let [L, a, b2] = Lab;
1227 let f = [];
1228 f[1] = (L + 16) / 116;
1229 f[0] = a / 500 + f[1];
1230 f[2] = f[1] - b2 / 200;
1231 let xyz = [
1232 f[0] > \u03B53 ? Math.pow(f[0], 3) : (116 * f[0] - 16) / \u03BA,
1233 Lab[0] > 8 ? Math.pow((Lab[0] + 16) / 116, 3) : Lab[0] / \u03BA,
1234 f[2] > \u03B53 ? Math.pow(f[2], 3) : (116 * f[2] - 16) / \u03BA
1235 ];
1236 return xyz.map((value, i) => value * white[i]);
1237 },
1238 formats: {
1239 lab: {
1240 coords: [
1241 "<percentage> | <number>",
1242 "<number> | <percentage>",
1243 "<number> | <percentage>"
1244 ]
1245 }
1246 }
1247 });
1248
1249 // packages/theme/node_modules/colorjs.io/src/angles.js
1250 function constrain(angle) {
1251 if (typeof angle !== "number") {
1252 return angle;
1253 }
1254 return (angle % 360 + 360) % 360;
1255 }
1256
1257 // packages/theme/node_modules/colorjs.io/src/spaces/lch.js
1258 var lch_default = new ColorSpace({
1259 id: "lch",
1260 name: "LCH",
1261 coords: {
1262 l: {
1263 refRange: [0, 100],
1264 name: "Lightness"
1265 },
1266 c: {
1267 refRange: [0, 150],
1268 name: "Chroma"
1269 },
1270 h: {
1271 refRange: [0, 360],
1272 type: "angle",
1273 name: "Hue"
1274 }
1275 },
1276 base: lab_default,
1277 fromBase(Lab) {
1278 if (this.\u03B5 === void 0) {
1279 let range = Object.values(this.base.coords)[1].refRange;
1280 let extent = range[1] - range[0];
1281 this.\u03B5 = extent / 1e5;
1282 }
1283 let [L, a, b2] = Lab;
1284 let isAchromatic = Math.abs(a) < this.\u03B5 && Math.abs(b2) < this.\u03B5;
1285 let h = isAchromatic ? null : constrain(Math.atan2(b2, a) * 180 / Math.PI);
1286 let C = isAchromatic ? 0 : Math.sqrt(a ** 2 + b2 ** 2);
1287 return [L, C, h];
1288 },
1289 toBase(lch) {
1290 let [L, C, h] = lch;
1291 let a = null, b2 = null;
1292 if (!isNone(h)) {
1293 C = C < 0 ? 0 : C;
1294 a = C * Math.cos(h * Math.PI / 180);
1295 b2 = C * Math.sin(h * Math.PI / 180);
1296 }
1297 return [L, a, b2];
1298 },
1299 formats: {
1300 lch: {
1301 coords: ["<percentage> | <number>", "<number> | <percentage>", "<number> | <angle>"]
1302 }
1303 }
1304 });
1305
1306 // packages/theme/node_modules/colorjs.io/src/deltaE/deltaE2000.js
1307 var Gfactor = 25 ** 7;
1308 var \u03C0 = Math.PI;
1309 var r2d = 180 / \u03C0;
1310 var d2r = \u03C0 / 180;
1311 function pow7(x) {
1312 const x2 = x * x;
1313 const x7 = x2 * x2 * x2 * x;
1314 return x7;
1315 }
1316 function deltaE2000_default(color, sample, { kL = 1, kC = 1, kH = 1 } = {}) {
1317 [color, sample] = getColor([color, sample]);
1318 let [L1, a1, b1] = lab_default.from(color);
1319 let C1 = lch_default.from(lab_default, [L1, a1, b1])[1];
1320 let [L2, a2, b2] = lab_default.from(sample);
1321 let C2 = lch_default.from(lab_default, [L2, a2, b2])[1];
1322 if (C1 < 0) {
1323 C1 = 0;
1324 }
1325 if (C2 < 0) {
1326 C2 = 0;
1327 }
1328 let Cbar = (C1 + C2) / 2;
1329 let C7 = pow7(Cbar);
1330 let G = 0.5 * (1 - Math.sqrt(C7 / (C7 + Gfactor)));
1331 let adash1 = (1 + G) * a1;
1332 let adash2 = (1 + G) * a2;
1333 let Cdash1 = Math.sqrt(adash1 ** 2 + b1 ** 2);
1334 let Cdash2 = Math.sqrt(adash2 ** 2 + b2 ** 2);
1335 let h1 = adash1 === 0 && b1 === 0 ? 0 : Math.atan2(b1, adash1);
1336 let h2 = adash2 === 0 && b2 === 0 ? 0 : Math.atan2(b2, adash2);
1337 if (h1 < 0) {
1338 h1 += 2 * \u03C0;
1339 }
1340 if (h2 < 0) {
1341 h2 += 2 * \u03C0;
1342 }
1343 h1 *= r2d;
1344 h2 *= r2d;
1345 let \u0394L = L2 - L1;
1346 let \u0394C = Cdash2 - Cdash1;
1347 let hdiff = h2 - h1;
1348 let hsum = h1 + h2;
1349 let habs = Math.abs(hdiff);
1350 let \u0394h;
1351 if (Cdash1 * Cdash2 === 0) {
1352 \u0394h = 0;
1353 } else if (habs <= 180) {
1354 \u0394h = hdiff;
1355 } else if (hdiff > 180) {
1356 \u0394h = hdiff - 360;
1357 } else if (hdiff < -180) {
1358 \u0394h = hdiff + 360;
1359 } else {
1360 defaults_default.warn("the unthinkable has happened");
1361 }
1362 let \u0394H = 2 * Math.sqrt(Cdash2 * Cdash1) * Math.sin(\u0394h * d2r / 2);
1363 let Ldash = (L1 + L2) / 2;
1364 let Cdash = (Cdash1 + Cdash2) / 2;
1365 let Cdash7 = pow7(Cdash);
1366 let hdash;
1367 if (Cdash1 * Cdash2 === 0) {
1368 hdash = hsum;
1369 } else if (habs <= 180) {
1370 hdash = hsum / 2;
1371 } else if (hsum < 360) {
1372 hdash = (hsum + 360) / 2;
1373 } else {
1374 hdash = (hsum - 360) / 2;
1375 }
1376 let lsq = (Ldash - 50) ** 2;
1377 let SL = 1 + 0.015 * lsq / Math.sqrt(20 + lsq);
1378 let SC = 1 + 0.045 * Cdash;
1379 let T = 1;
1380 T -= 0.17 * Math.cos((hdash - 30) * d2r);
1381 T += 0.24 * Math.cos(2 * hdash * d2r);
1382 T += 0.32 * Math.cos((3 * hdash + 6) * d2r);
1383 T -= 0.2 * Math.cos((4 * hdash - 63) * d2r);
1384 let SH = 1 + 0.015 * Cdash * T;
1385 let \u0394\u03B8 = 30 * Math.exp(-1 * ((hdash - 275) / 25) ** 2);
1386 let RC = 2 * Math.sqrt(Cdash7 / (Cdash7 + Gfactor));
1387 let RT = -1 * Math.sin(2 * \u0394\u03B8 * d2r) * RC;
1388 let dE = (\u0394L / (kL * SL)) ** 2;
1389 dE += (\u0394C / (kC * SC)) ** 2;
1390 dE += (\u0394H / (kH * SH)) ** 2;
1391 dE += RT * (\u0394C / (kC * SC)) * (\u0394H / (kH * SH));
1392 return Math.sqrt(dE);
1393 }
1394
1395 // packages/theme/node_modules/colorjs.io/src/spaces/oklab.js
1396 var XYZtoLMS_M = [
1397 [0.819022437996703, 0.3619062600528904, -0.1288737815209879],
1398 [0.0329836539323885, 0.9292868615863434, 0.0361446663506424],
1399 [0.0481771893596242, 0.2642395317527308, 0.6335478284694309]
1400 ];
1401 var LMStoXYZ_M = [
1402 [1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
1403 [-0.0405757452148008, 1.112286803280317, -0.0717110580655164],
1404 [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]
1405 ];
1406 var LMStoLab_M = [
1407 [0.210454268309314, 0.7936177747023054, -0.0040720430116193],
1408 [1.9779985324311684, -2.42859224204858, 0.450593709617411],
1409 [0.0259040424655478, 0.7827717124575296, -0.8086757549230774]
1410 ];
1411 var LabtoLMS_M = [
1412 [1, 0.3963377773761749, 0.2158037573099136],
1413 [1, -0.1055613458156586, -0.0638541728258133],
1414 [1, -0.0894841775298119, -1.2914855480194092]
1415 ];
1416 var oklab_default = new ColorSpace({
1417 id: "oklab",
1418 name: "Oklab",
1419 coords: {
1420 l: {
1421 refRange: [0, 1],
1422 name: "Lightness"
1423 },
1424 a: {
1425 refRange: [-0.4, 0.4]
1426 },
1427 b: {
1428 refRange: [-0.4, 0.4]
1429 }
1430 },
1431 // Note that XYZ is relative to D65
1432 white: "D65",
1433 base: xyz_d65_default,
1434 fromBase(XYZ) {
1435 let LMS = multiply_v3_m3x3(XYZ, XYZtoLMS_M);
1436 LMS[0] = Math.cbrt(LMS[0]);
1437 LMS[1] = Math.cbrt(LMS[1]);
1438 LMS[2] = Math.cbrt(LMS[2]);
1439 return multiply_v3_m3x3(LMS, LMStoLab_M, LMS);
1440 },
1441 toBase(OKLab) {
1442 let LMSg = multiply_v3_m3x3(OKLab, LabtoLMS_M);
1443 LMSg[0] = LMSg[0] ** 3;
1444 LMSg[1] = LMSg[1] ** 3;
1445 LMSg[2] = LMSg[2] ** 3;
1446 return multiply_v3_m3x3(LMSg, LMStoXYZ_M, LMSg);
1447 },
1448 formats: {
1449 oklab: {
1450 coords: [
1451 "<percentage> | <number>",
1452 "<number> | <percentage>",
1453 "<number> | <percentage>"
1454 ]
1455 }
1456 }
1457 });
1458
1459 // packages/theme/node_modules/colorjs.io/src/deltaE/deltaEOK.js
1460 function deltaEOK_default(color, sample) {
1461 [color, sample] = getColor([color, sample]);
1462 let [L1, a1, b1] = oklab_default.from(color);
1463 let [L2, a2, b2] = oklab_default.from(sample);
1464 let \u0394L = L1 - L2;
1465 let \u0394a = a1 - a2;
1466 let \u0394b = b1 - b2;
1467 return Math.sqrt(\u0394L ** 2 + \u0394a ** 2 + \u0394b ** 2);
1468 }
1469
1470 // packages/theme/node_modules/colorjs.io/src/inGamut.js
1471 var \u03B54 = 75e-6;
1472 function inGamut(color, space, { epsilon = \u03B54 } = {}) {
1473 color = getColor(color);
1474 if (!space) {
1475 space = color.space;
1476 }
1477 space = ColorSpace.get(space);
1478 let coords = color.coords;
1479 if (space !== color.space) {
1480 coords = space.from(color);
1481 }
1482 return space.inGamut(coords, { epsilon });
1483 }
1484
1485 // packages/theme/node_modules/colorjs.io/src/clone.js
1486 function clone(color) {
1487 return {
1488 space: color.space,
1489 coords: (
1490 /** @type {Coords} */
1491 color.coords.slice()
1492 ),
1493 alpha: color.alpha
1494 };
1495 }
1496
1497 // packages/theme/node_modules/colorjs.io/src/distance.js
1498 function distance(color1, color2, space = "lab") {
1499 space = ColorSpace.get(space);
1500 let coords1 = space.from(color1);
1501 let coords2 = space.from(color2);
1502 return Math.sqrt(
1503 coords1.reduce((acc, c13, i) => {
1504 let c23 = coords2[i];
1505 if (isNone(c13) || isNone(c23)) {
1506 return acc;
1507 }
1508 return acc + (c23 - c13) ** 2;
1509 }, 0)
1510 );
1511 }
1512
1513 // packages/theme/node_modules/colorjs.io/src/deltaE/deltaE76.js
1514 function deltaE76(color, sample) {
1515 return distance(color, sample, "lab");
1516 }
1517
1518 // packages/theme/node_modules/colorjs.io/src/deltaE/deltaECMC.js
1519 var \u03C02 = Math.PI;
1520 var d2r2 = \u03C02 / 180;
1521 function deltaECMC_default(color, sample, { l = 2, c = 1 } = {}) {
1522 [color, sample] = getColor([color, sample]);
1523 let [L1, a1, b1] = lab_default.from(color);
1524 let [, C1, H1] = lch_default.from(lab_default, [L1, a1, b1]);
1525 let [L2, a2, b2] = lab_default.from(sample);
1526 let C2 = lch_default.from(lab_default, [L2, a2, b2])[1];
1527 if (C1 < 0) {
1528 C1 = 0;
1529 }
1530 if (C2 < 0) {
1531 C2 = 0;
1532 }
1533 let \u0394L = L1 - L2;
1534 let \u0394C = C1 - C2;
1535 let \u0394a = a1 - a2;
1536 let \u0394b = b1 - b2;
1537 let H2 = \u0394a ** 2 + \u0394b ** 2 - \u0394C ** 2;
1538 let SL = 0.511;
1539 if (L1 >= 16) {
1540 SL = 0.040975 * L1 / (1 + 0.01765 * L1);
1541 }
1542 let SC = 0.0638 * C1 / (1 + 0.0131 * C1) + 0.638;
1543 let T;
1544 if (isNone(H1)) {
1545 H1 = 0;
1546 }
1547 if (H1 >= 164 && H1 <= 345) {
1548 T = 0.56 + Math.abs(0.2 * Math.cos((H1 + 168) * d2r2));
1549 } else {
1550 T = 0.36 + Math.abs(0.4 * Math.cos((H1 + 35) * d2r2));
1551 }
1552 let C4 = Math.pow(C1, 4);
1553 let F = Math.sqrt(C4 / (C4 + 1900));
1554 let SH = SC * (F * T + 1 - F);
1555 let dE = (\u0394L / (l * SL)) ** 2;
1556 dE += (\u0394C / (c * SC)) ** 2;
1557 dE += H2 / SH ** 2;
1558 return Math.sqrt(dE);
1559 }
1560
1561 // packages/theme/node_modules/colorjs.io/src/spaces/xyz-abs-d65.js
1562 var Yw = 203;
1563 var xyz_abs_d65_default = new ColorSpace({
1564 // Absolute CIE XYZ, with a D65 whitepoint,
1565 // as used in most HDR colorspaces as a starting point.
1566 // SDR spaces are converted per BT.2048
1567 // so that diffuse, media white is 203 cd/m²
1568 id: "xyz-abs-d65",
1569 cssId: "--xyz-abs-d65",
1570 name: "Absolute XYZ D65",
1571 coords: {
1572 x: {
1573 refRange: [0, 9504.7],
1574 name: "Xa"
1575 },
1576 y: {
1577 refRange: [0, 1e4],
1578 name: "Ya"
1579 },
1580 z: {
1581 refRange: [0, 10888.3],
1582 name: "Za"
1583 }
1584 },
1585 base: xyz_d65_default,
1586 fromBase(XYZ) {
1587 return XYZ.map((v) => v * Yw);
1588 },
1589 toBase(AbsXYZ) {
1590 return AbsXYZ.map((v) => v / Yw);
1591 }
1592 });
1593
1594 // packages/theme/node_modules/colorjs.io/src/spaces/jzazbz.js
1595 var b = 1.15;
1596 var g = 0.66;
1597 var n = 2610 / 2 ** 14;
1598 var ninv = 2 ** 14 / 2610;
1599 var c1 = 3424 / 2 ** 12;
1600 var c2 = 2413 / 2 ** 7;
1601 var c3 = 2392 / 2 ** 7;
1602 var p = 1.7 * 2523 / 2 ** 5;
1603 var pinv = 2 ** 5 / (1.7 * 2523);
1604 var d = -0.56;
1605 var d0 = 16295499532821565e-27;
1606 var XYZtoCone_M = [
1607 [0.41478972, 0.579999, 0.014648],
1608 [-0.20151, 1.120649, 0.0531008],
1609 [-0.0166008, 0.2648, 0.6684799]
1610 ];
1611 var ConetoXYZ_M = [
1612 [1.9242264357876067, -1.0047923125953657, 0.037651404030618],
1613 [0.35031676209499907, 0.7264811939316552, -0.06538442294808501],
1614 [-0.09098281098284752, -0.3127282905230739, 1.5227665613052603]
1615 ];
1616 var ConetoIab_M = [
1617 [0.5, 0.5, 0],
1618 [3.524, -4.066708, 0.542708],
1619 [0.199076, 1.096799, -1.295875]
1620 ];
1621 var IabtoCone_M = [
1622 [1, 0.13860504327153927, 0.05804731615611883],
1623 [1, -0.1386050432715393, -0.058047316156118904],
1624 [1, -0.09601924202631895, -0.811891896056039]
1625 ];
1626 var jzazbz_default = new ColorSpace({
1627 id: "jzazbz",
1628 name: "Jzazbz",
1629 coords: {
1630 jz: {
1631 refRange: [0, 1],
1632 name: "Jz"
1633 },
1634 az: {
1635 refRange: [-0.21, 0.21]
1636 },
1637 bz: {
1638 refRange: [-0.21, 0.21]
1639 }
1640 },
1641 base: xyz_abs_d65_default,
1642 fromBase(XYZ) {
1643 let [Xa, Ya, Za] = XYZ;
1644 let Xm = b * Xa - (b - 1) * Za;
1645 let Ym = g * Ya - (g - 1) * Xa;
1646 let LMS = multiply_v3_m3x3([Xm, Ym, Za], XYZtoCone_M);
1647 let PQLMS = (
1648 /** @type {Vector3} } */
1649 LMS.map(function(val) {
1650 let num = c1 + c2 * spow(val / 1e4, n);
1651 let denom = 1 + c3 * spow(val / 1e4, n);
1652 return spow(num / denom, p);
1653 })
1654 );
1655 let [Iz, az, bz] = multiply_v3_m3x3(PQLMS, ConetoIab_M);
1656 let Jz = (1 + d) * Iz / (1 + d * Iz) - d0;
1657 return [Jz, az, bz];
1658 },
1659 toBase(Jzazbz) {
1660 let [Jz, az, bz] = Jzazbz;
1661 let Iz = (Jz + d0) / (1 + d - d * (Jz + d0));
1662 let PQLMS = multiply_v3_m3x3([Iz, az, bz], IabtoCone_M);
1663 let LMS = (
1664 /** @type {Vector3} } */
1665 PQLMS.map(function(val) {
1666 let num = c1 - spow(val, pinv);
1667 let denom = c3 * spow(val, pinv) - c2;
1668 let x = 1e4 * spow(num / denom, ninv);
1669 return x;
1670 })
1671 );
1672 let [Xm, Ym, Za] = multiply_v3_m3x3(LMS, ConetoXYZ_M);
1673 let Xa = (Xm + (b - 1) * Za) / b;
1674 let Ya = (Ym + (g - 1) * Xa) / g;
1675 return [Xa, Ya, Za];
1676 },
1677 formats: {
1678 // https://drafts.csswg.org/css-color-hdr/#Jzazbz
1679 jzazbz: {
1680 coords: [
1681 "<percentage> | <number>",
1682 "<number> | <percentage>",
1683 "<number> | <percentage>"
1684 ]
1685 }
1686 }
1687 });
1688
1689 // packages/theme/node_modules/colorjs.io/src/spaces/jzczhz.js
1690 var jzczhz_default = new ColorSpace({
1691 id: "jzczhz",
1692 name: "JzCzHz",
1693 coords: {
1694 jz: {
1695 refRange: [0, 1],
1696 name: "Jz"
1697 },
1698 cz: {
1699 refRange: [0, 0.26],
1700 name: "Chroma"
1701 },
1702 hz: {
1703 refRange: [0, 360],
1704 type: "angle",
1705 name: "Hue"
1706 }
1707 },
1708 base: jzazbz_default,
1709 fromBase: lch_default.fromBase,
1710 toBase: lch_default.toBase,
1711 formats: {
1712 // https://drafts.csswg.org/css-color-hdr/#JzCzhz
1713 jzczhz: {
1714 coords: ["<percentage> | <number>", "<number> | <percentage>", "<number> | <angle>"]
1715 }
1716 }
1717 });
1718
1719 // packages/theme/node_modules/colorjs.io/src/deltaE/deltaEJz.js
1720 function deltaEJz_default(color, sample) {
1721 [color, sample] = getColor([color, sample]);
1722 let [Jz1, Cz1, Hz1] = jzczhz_default.from(color);
1723 let [Jz2, Cz2, Hz2] = jzczhz_default.from(sample);
1724 let \u0394J = Jz1 - Jz2;
1725 let \u0394C = Cz1 - Cz2;
1726 if (isNone(Hz1) && isNone(Hz2)) {
1727 Hz1 = 0;
1728 Hz2 = 0;
1729 } else if (isNone(Hz1)) {
1730 Hz1 = Hz2;
1731 } else if (isNone(Hz2)) {
1732 Hz2 = Hz1;
1733 }
1734 let \u0394h = Hz1 - Hz2;
1735 let \u0394H = 2 * Math.sqrt(Cz1 * Cz2) * Math.sin(\u0394h / 2 * (Math.PI / 180));
1736 return Math.sqrt(\u0394J ** 2 + \u0394C ** 2 + \u0394H ** 2);
1737 }
1738
1739 // packages/theme/node_modules/colorjs.io/src/spaces/ictcp.js
1740 var c12 = 3424 / 4096;
1741 var c22 = 2413 / 128;
1742 var c32 = 2392 / 128;
1743 var m1 = 2610 / 16384;
1744 var m2 = 2523 / 32;
1745 var im1 = 16384 / 2610;
1746 var im2 = 32 / 2523;
1747 var XYZtoLMS_M2 = [
1748 [0.3592832590121217, 0.6976051147779502, -0.035891593232029],
1749 [-0.1920808463704993, 1.100476797037432, 0.0753748658519118],
1750 [0.0070797844607479, 0.0748396662186362, 0.8433265453898765]
1751 ];
1752 var LMStoIPT_M = [
1753 [2048 / 4096, 2048 / 4096, 0],
1754 [6610 / 4096, -13613 / 4096, 7003 / 4096],
1755 [17933 / 4096, -17390 / 4096, -543 / 4096]
1756 ];
1757 var IPTtoLMS_M = [
1758 [0.9999999999999998, 0.0086090370379328, 0.111029625003026],
1759 [0.9999999999999998, -0.0086090370379328, -0.1110296250030259],
1760 [0.9999999999999998, 0.5600313357106791, -0.3206271749873188]
1761 ];
1762 var LMStoXYZ_M2 = [
1763 [2.0701522183894223, -1.3263473389671563, 0.2066510476294053],
1764 [0.3647385209748072, 0.6805660249472273, -0.0453045459220347],
1765 [-0.0497472075358123, -0.0492609666966131, 1.1880659249923042]
1766 ];
1767 var ictcp_default = new ColorSpace({
1768 id: "ictcp",
1769 name: "ICTCP",
1770 // From BT.2100-2 page 7:
1771 // During production, signal values are expected to exceed the
1772 // range E′ = [0.0 : 1.0]. This provides processing headroom and avoids
1773 // signal degradation during cascaded processing. Such values of E′,
1774 // below 0.0 or exceeding 1.0, should not be clipped during production
1775 // and exchange.
1776 // Values below 0.0 should not be clipped in reference displays (even
1777 // though they represent “negative” light) to allow the black level of
1778 // the signal (LB) to be properly set using test signals known as “PLUGE”
1779 coords: {
1780 i: {
1781 refRange: [0, 1],
1782 // Constant luminance,
1783 name: "I"
1784 },
1785 ct: {
1786 refRange: [-0.5, 0.5],
1787 // Full BT.2020 gamut in range [-0.5, 0.5]
1788 name: "CT"
1789 },
1790 cp: {
1791 refRange: [-0.5, 0.5],
1792 name: "CP"
1793 }
1794 },
1795 base: xyz_abs_d65_default,
1796 fromBase(XYZ) {
1797 let LMS = multiply_v3_m3x3(XYZ, XYZtoLMS_M2);
1798 return LMStoICtCp(LMS);
1799 },
1800 toBase(ICtCp) {
1801 let LMS = ICtCptoLMS(ICtCp);
1802 return multiply_v3_m3x3(LMS, LMStoXYZ_M2);
1803 },
1804 formats: {
1805 ictcp: {
1806 coords: [
1807 "<percentage> | <number>",
1808 "<number> | <percentage>",
1809 "<number> | <percentage>"
1810 ]
1811 }
1812 }
1813 });
1814 function LMStoICtCp(LMS) {
1815 let PQLMS = (
1816 /** @type {Vector3} */
1817 LMS.map(function(val) {
1818 let num = c12 + c22 * (val / 1e4) ** m1;
1819 let denom = 1 + c32 * (val / 1e4) ** m1;
1820 return (num / denom) ** m2;
1821 })
1822 );
1823 return multiply_v3_m3x3(PQLMS, LMStoIPT_M);
1824 }
1825 function ICtCptoLMS(ICtCp) {
1826 let PQLMS = multiply_v3_m3x3(ICtCp, IPTtoLMS_M);
1827 let LMS = (
1828 /** @type {Vector3} */
1829 PQLMS.map(function(val) {
1830 let num = Math.max(val ** im2 - c12, 0);
1831 let denom = c22 - c32 * val ** im2;
1832 return 1e4 * (num / denom) ** im1;
1833 })
1834 );
1835 return LMS;
1836 }
1837
1838 // packages/theme/node_modules/colorjs.io/src/deltaE/deltaEITP.js
1839 function deltaEITP_default(color, sample) {
1840 [color, sample] = getColor([color, sample]);
1841 let [I1, T1, P1] = ictcp_default.from(color);
1842 let [I2, T2, P2] = ictcp_default.from(sample);
1843 return 720 * Math.sqrt((I1 - I2) ** 2 + 0.25 * (T1 - T2) ** 2 + (P1 - P2) ** 2);
1844 }
1845
1846 // packages/theme/node_modules/colorjs.io/src/deltaE/deltaEOK2.js
1847 function deltaEOK2_default(color, sample) {
1848 [color, sample] = getColor([color, sample]);
1849 let abscale = 2;
1850 let [L1, a1, b1] = oklab_default.from(color);
1851 let [L2, a2, b2] = oklab_default.from(sample);
1852 let \u0394L = L1 - L2;
1853 let \u0394a = abscale * (a1 - a2);
1854 let \u0394b = abscale * (b1 - b2);
1855 return Math.sqrt(\u0394L ** 2 + \u0394a ** 2 + \u0394b ** 2);
1856 }
1857
1858 // packages/theme/node_modules/colorjs.io/src/spaces/cam16.js
1859 var white2 = WHITES.D65;
1860 var adaptedCoef = 0.42;
1861 var adaptedCoefInv = 1 / adaptedCoef;
1862 var tau = 2 * Math.PI;
1863 var cat16 = [
1864 [0.401288, 0.650173, -0.051461],
1865 [-0.250268, 1.204414, 0.045854],
1866 [-2079e-6, 0.048952, 0.953127]
1867 ];
1868 var cat16Inv = [
1869 [1.8620678550872327, -1.0112546305316843, 0.14918677544445175],
1870 [0.38752654323613717, 0.6214474419314753, -0.008973985167612518],
1871 [-0.015841498849333856, -0.03412293802851557, 1.0499644368778496]
1872 ];
1873 var m12 = [
1874 [460, 451, 288],
1875 [460, -891, -261],
1876 [460, -220, -6300]
1877 ];
1878 var surroundMap = {
1879 dark: [0.8, 0.525, 0.8],
1880 dim: [0.9, 0.59, 0.9],
1881 average: [1, 0.69, 1]
1882 };
1883 var hueQuadMap = {
1884 // Red, Yellow, Green, Blue, Red
1885 h: [20.14, 90, 164.25, 237.53, 380.14],
1886 e: [0.8, 0.7, 1, 1.2, 0.8],
1887 H: [0, 100, 200, 300, 400]
1888 };
1889 var rad2deg = 180 / Math.PI;
1890 var deg2rad = Math.PI / 180;
1891 function adapt2(coords, fl) {
1892 const temp = (
1893 /** @type {[number, number, number]} */
1894 coords.map((c) => {
1895 const x = spow(fl * Math.abs(c) * 0.01, adaptedCoef);
1896 return 400 * copySign(x, c) / (x + 27.13);
1897 })
1898 );
1899 return temp;
1900 }
1901 function unadapt(adapted, fl) {
1902 const constant = 100 / fl * 27.13 ** adaptedCoefInv;
1903 return (
1904 /** @type {[number, number, number]} */
1905 adapted.map((c) => {
1906 const cabs = Math.abs(c);
1907 return copySign(constant * spow(cabs / (400 - cabs), adaptedCoefInv), c);
1908 })
1909 );
1910 }
1911 function hueQuadrature(h) {
1912 let hp = constrain(h);
1913 if (hp <= hueQuadMap.h[0]) {
1914 hp += 360;
1915 }
1916 const i = bisectLeft(hueQuadMap.h, hp) - 1;
1917 const [hi, hii] = hueQuadMap.h.slice(i, i + 2);
1918 const [ei, eii] = hueQuadMap.e.slice(i, i + 2);
1919 const Hi = hueQuadMap.H[i];
1920 const t = (hp - hi) / ei;
1921 return Hi + 100 * t / (t + (hii - hp) / eii);
1922 }
1923 function invHueQuadrature(H) {
1924 let Hp = (H % 400 + 400) % 400;
1925 const i = Math.floor(0.01 * Hp);
1926 Hp = Hp % 100;
1927 const [hi, hii] = hueQuadMap.h.slice(i, i + 2);
1928 const [ei, eii] = hueQuadMap.e.slice(i, i + 2);
1929 return constrain((Hp * (eii * hi - ei * hii) - 100 * hi * eii) / (Hp * (eii - ei) - 100 * eii));
1930 }
1931 function environment(refWhite, adaptingLuminance, backgroundLuminance, surround, discounting) {
1932 const env = {};
1933 env.discounting = discounting;
1934 env.refWhite = refWhite;
1935 env.surround = surround;
1936 const xyzW = (
1937 /** @type {Vector3} */
1938 refWhite.map((c) => {
1939 return c * 100;
1940 })
1941 );
1942 env.la = adaptingLuminance;
1943 env.yb = backgroundLuminance;
1944 const yw = xyzW[1];
1945 const rgbW = multiply_v3_m3x3(xyzW, cat16);
1946 let values = surroundMap[env.surround];
1947 const f = values[0];
1948 env.c = values[1];
1949 env.nc = values[2];
1950 const k = 1 / (5 * env.la + 1);
1951 const k4 = k ** 4;
1952 env.fl = k4 * env.la + 0.1 * (1 - k4) * (1 - k4) * Math.cbrt(5 * env.la);
1953 env.flRoot = env.fl ** 0.25;
1954 env.n = env.yb / yw;
1955 env.z = 1.48 + Math.sqrt(env.n);
1956 env.nbb = 0.725 * env.n ** -0.2;
1957 env.ncb = env.nbb;
1958 const d2 = discounting ? 1 : Math.max(Math.min(f * (1 - 1 / 3.6 * Math.exp((-env.la - 42) / 92)), 1), 0);
1959 env.dRgb = /** @type {[number, number, number]} */
1960 rgbW.map((c) => {
1961 return interpolate(1, yw / c, d2);
1962 });
1963 env.dRgbInv = /** @type {[number, number, number]} */
1964 env.dRgb.map((c) => {
1965 return 1 / c;
1966 });
1967 const rgbCW = (
1968 /** @type {[number, number, number]} */
1969 rgbW.map((c, i) => {
1970 return c * env.dRgb[i];
1971 })
1972 );
1973 const rgbAW = adapt2(rgbCW, env.fl);
1974 env.aW = env.nbb * (2 * rgbAW[0] + rgbAW[1] + 0.05 * rgbAW[2]);
1975 return env;
1976 }
1977 var viewingConditions = environment(white2, 64 / Math.PI * 0.2, 20, "average", false);
1978 function fromCam16(cam16, env) {
1979 if (!(cam16.J !== void 0 ^ cam16.Q !== void 0)) {
1980 throw new Error("Conversion requires one and only one: 'J' or 'Q'");
1981 }
1982 if (!(cam16.C !== void 0 ^ cam16.M !== void 0 ^ cam16.s !== void 0)) {
1983 throw new Error("Conversion requires one and only one: 'C', 'M' or 's'");
1984 }
1985 if (!(cam16.h !== void 0 ^ cam16.H !== void 0)) {
1986 throw new Error("Conversion requires one and only one: 'h' or 'H'");
1987 }
1988 if (cam16.J === 0 || cam16.Q === 0) {
1989 return [0, 0, 0];
1990 }
1991 let hRad = 0;
1992 if (cam16.h !== void 0) {
1993 hRad = constrain(cam16.h) * deg2rad;
1994 } else {
1995 hRad = invHueQuadrature(cam16.H) * deg2rad;
1996 }
1997 const cosh = Math.cos(hRad);
1998 const sinh = Math.sin(hRad);
1999 let Jroot = 0;
2000 if (cam16.J !== void 0) {
2001 Jroot = spow(cam16.J, 1 / 2) * 0.1;
2002 } else if (cam16.Q !== void 0) {
2003 Jroot = 0.25 * env.c * cam16.Q / ((env.aW + 4) * env.flRoot);
2004 }
2005 let alpha = 0;
2006 if (cam16.C !== void 0) {
2007 alpha = cam16.C / Jroot;
2008 } else if (cam16.M !== void 0) {
2009 alpha = cam16.M / env.flRoot / Jroot;
2010 } else if (cam16.s !== void 0) {
2011 alpha = 4e-4 * cam16.s ** 2 * (env.aW + 4) / env.c;
2012 }
2013 const t = spow(alpha * Math.pow(1.64 - Math.pow(0.29, env.n), -0.73), 10 / 9);
2014 const et = 0.25 * (Math.cos(hRad + 2) + 3.8);
2015 const A = env.aW * spow(Jroot, 2 / env.c / env.z);
2016 const p1 = 5e4 / 13 * env.nc * env.ncb * et;
2017 const p2 = A / env.nbb;
2018 const r = 23 * (p2 + 0.305) * zdiv(t, 23 * p1 + t * (11 * cosh + 108 * sinh));
2019 const a = r * cosh;
2020 const b2 = r * sinh;
2021 const rgb_c = unadapt(
2022 /** @type {Vector3} */
2023 multiply_v3_m3x3([p2, a, b2], m12).map((c) => {
2024 return c * 1 / 1403;
2025 }),
2026 env.fl
2027 );
2028 return (
2029 /** @type {Vector3} */
2030 multiply_v3_m3x3(
2031 /** @type {Vector3} */
2032 rgb_c.map((c, i) => {
2033 return c * env.dRgbInv[i];
2034 }),
2035 cat16Inv
2036 ).map((c) => {
2037 return c / 100;
2038 })
2039 );
2040 }
2041 function toCam16(xyzd65, env) {
2042 const xyz100 = (
2043 /** @type {Vector3} */
2044 xyzd65.map((c) => {
2045 return c * 100;
2046 })
2047 );
2048 const rgbA = adapt2(
2049 /** @type {[number, number, number]} */
2050 multiply_v3_m3x3(xyz100, cat16).map((c, i) => {
2051 return c * env.dRgb[i];
2052 }),
2053 env.fl
2054 );
2055 const a = rgbA[0] + (-12 * rgbA[1] + rgbA[2]) / 11;
2056 const b2 = (rgbA[0] + rgbA[1] - 2 * rgbA[2]) / 9;
2057 const hRad = (Math.atan2(b2, a) % tau + tau) % tau;
2058 const et = 0.25 * (Math.cos(hRad + 2) + 3.8);
2059 const t = 5e4 / 13 * env.nc * env.ncb * zdiv(et * Math.sqrt(a ** 2 + b2 ** 2), rgbA[0] + rgbA[1] + 1.05 * rgbA[2] + 0.305);
2060 const alpha = spow(t, 0.9) * Math.pow(1.64 - Math.pow(0.29, env.n), 0.73);
2061 const A = env.nbb * (2 * rgbA[0] + rgbA[1] + 0.05 * rgbA[2]);
2062 const Jroot = spow(A / env.aW, 0.5 * env.c * env.z);
2063 const J = 100 * spow(Jroot, 2);
2064 const Q = 4 / env.c * Jroot * (env.aW + 4) * env.flRoot;
2065 const C = alpha * Jroot;
2066 const M = C * env.flRoot;
2067 const h = constrain(hRad * rad2deg);
2068 const H = hueQuadrature(h);
2069 const s = 50 * spow(env.c * alpha / (env.aW + 4), 1 / 2);
2070 return { J, C, h, s, Q, M, H };
2071 }
2072 var cam16_default = new ColorSpace({
2073 id: "cam16-jmh",
2074 cssId: "--cam16-jmh",
2075 name: "CAM16-JMh",
2076 coords: {
2077 j: {
2078 refRange: [0, 100],
2079 name: "J"
2080 },
2081 m: {
2082 refRange: [0, 105],
2083 name: "Colorfulness"
2084 },
2085 h: {
2086 refRange: [0, 360],
2087 type: "angle",
2088 name: "Hue"
2089 }
2090 },
2091 base: xyz_d65_default,
2092 fromBase(xyz) {
2093 if (this.\u03B5 === void 0) {
2094 this.\u03B5 = Object.values(this.coords)[1].refRange[1] / 1e5;
2095 }
2096 const cam16 = toCam16(xyz, viewingConditions);
2097 const isAchromatic = Math.abs(cam16.M) < this.\u03B5;
2098 return [cam16.J, isAchromatic ? 0 : cam16.M, isAchromatic ? null : cam16.h];
2099 },
2100 toBase(cam16) {
2101 return fromCam16({ J: cam16[0], M: cam16[1], h: cam16[2] }, viewingConditions);
2102 }
2103 });
2104
2105 // packages/theme/node_modules/colorjs.io/src/spaces/hct.js
2106 var white3 = WHITES.D65;
2107 var \u03B55 = 216 / 24389;
2108 var \u03BA2 = 24389 / 27;
2109 function toLstar(y) {
2110 const fy = y > \u03B55 ? Math.cbrt(y) : (\u03BA2 * y + 16) / 116;
2111 return 116 * fy - 16;
2112 }
2113 function fromLstar(lstar) {
2114 return lstar > 8 ? Math.pow((lstar + 16) / 116, 3) : lstar / \u03BA2;
2115 }
2116 function fromHct(coords, env) {
2117 let [h, c, t] = coords;
2118 let xyz = [];
2119 let j = 0;
2120 if (t === 0) {
2121 return [0, 0, 0];
2122 }
2123 let y = fromLstar(t);
2124 if (t > 0) {
2125 j = 0.00379058511492914 * t ** 2 + 0.608983189401032 * t + 0.9155088574762233;
2126 } else {
2127 j = 9514440756550361e-21 * t ** 2 + 0.08693057439788597 * t - 21.928975842194614;
2128 }
2129 const threshold = 2e-12;
2130 const max_attempts = 15;
2131 let attempt = 0;
2132 let last = Infinity;
2133 let best = j;
2134 while (attempt <= max_attempts) {
2135 xyz = fromCam16({ J: j, C: c, h }, env);
2136 const delta = Math.abs(xyz[1] - y);
2137 if (delta < last) {
2138 if (delta <= threshold) {
2139 return xyz;
2140 }
2141 best = j;
2142 last = delta;
2143 }
2144 j = j - (xyz[1] - y) * j / (2 * xyz[1]);
2145 attempt += 1;
2146 }
2147 return fromCam16({ J: j, C: c, h }, env);
2148 }
2149 function toHct(xyz, env) {
2150 const t = toLstar(xyz[1]);
2151 if (t === 0) {
2152 return [0, 0, 0];
2153 }
2154 const cam16 = toCam16(xyz, viewingConditions2);
2155 return [constrain(cam16.h), cam16.C, t];
2156 }
2157 var viewingConditions2 = environment(
2158 white3,
2159 200 / Math.PI * fromLstar(50),
2160 fromLstar(50) * 100,
2161 "average",
2162 false
2163 );
2164 var hct_default = new ColorSpace({
2165 id: "hct",
2166 name: "HCT",
2167 coords: {
2168 h: {
2169 refRange: [0, 360],
2170 type: "angle",
2171 name: "Hue"
2172 },
2173 c: {
2174 refRange: [0, 145],
2175 name: "Colorfulness"
2176 },
2177 t: {
2178 refRange: [0, 100],
2179 name: "Tone"
2180 }
2181 },
2182 base: xyz_d65_default,
2183 fromBase(xyz) {
2184 if (this.\u03B5 === void 0) {
2185 this.\u03B5 = Object.values(this.coords)[1].refRange[1] / 1e5;
2186 }
2187 let hct = toHct(xyz, viewingConditions2);
2188 if (hct[1] < this.\u03B5) {
2189 hct[1] = 0;
2190 hct[0] = null;
2191 }
2192 return hct;
2193 },
2194 toBase(hct) {
2195 return fromHct(hct, viewingConditions2);
2196 },
2197 formats: {
2198 color: {
2199 id: "--hct",
2200 coords: ["<number> | <angle>", "<percentage> | <number>", "<percentage> | <number>"]
2201 }
2202 }
2203 });
2204
2205 // packages/theme/node_modules/colorjs.io/src/deltaE/deltaEHCT.js
2206 var rad2deg2 = 180 / Math.PI;
2207 var deg2rad2 = Math.PI / 180;
2208 var ucsCoeff = [1, 7e-3, 0.0228];
2209 function convertUcsAb(coords) {
2210 if (coords[1] < 0) {
2211 coords = hct_default.fromBase(hct_default.toBase(coords));
2212 }
2213 const M = Math.log(Math.max(1 + ucsCoeff[2] * coords[1] * viewingConditions2.flRoot, 1)) / ucsCoeff[2];
2214 const hrad = coords[0] * deg2rad2;
2215 const a = M * Math.cos(hrad);
2216 const b2 = M * Math.sin(hrad);
2217 return [coords[2], a, b2];
2218 }
2219 function deltaEHCT_default(color, sample) {
2220 [color, sample] = getColor([color, sample]);
2221 let [t1, a1, b1] = convertUcsAb(hct_default.from(color));
2222 let [t2, a2, b2] = convertUcsAb(hct_default.from(sample));
2223 return Math.sqrt((t1 - t2) ** 2 + (a1 - a2) ** 2 + (b1 - b2) ** 2);
2224 }
2225
2226 // packages/theme/node_modules/colorjs.io/src/deltaE/index.js
2227 var deltaE_default = {
2228 deltaE76,
2229 deltaECMC: deltaECMC_default,
2230 deltaE2000: deltaE2000_default,
2231 deltaEJz: deltaEJz_default,
2232 deltaEITP: deltaEITP_default,
2233 deltaEOK: deltaEOK_default,
2234 deltaEOK2: deltaEOK2_default,
2235 deltaEHCT: deltaEHCT_default
2236 };
2237
2238 // packages/theme/node_modules/colorjs.io/src/toGamut.js
2239 function calcEpsilon(jnd) {
2240 const order = !jnd ? 0 : Math.floor(Math.log10(Math.abs(jnd)));
2241 return Math.max(parseFloat(`1e${order - 2}`), 1e-6);
2242 }
2243 var GMAPPRESET = {
2244 hct: {
2245 method: "hct.c",
2246 jnd: 2,
2247 deltaEMethod: "hct",
2248 blackWhiteClamp: {}
2249 },
2250 "hct-tonal": {
2251 method: "hct.c",
2252 jnd: 0,
2253 deltaEMethod: "hct",
2254 blackWhiteClamp: { channel: "hct.t", min: 0, max: 100 }
2255 }
2256 };
2257 function toGamut(color, {
2258 method = defaults_default.gamut_mapping,
2259 space = void 0,
2260 deltaEMethod = "",
2261 jnd = 2,
2262 blackWhiteClamp = void 0
2263 } = {}) {
2264 color = getColor(color);
2265 if (isString(arguments[1])) {
2266 space = arguments[1];
2267 } else if (!space) {
2268 space = color.space;
2269 }
2270 space = ColorSpace.get(space);
2271 if (inGamut(color, space, { epsilon: 0 })) {
2272 return (
2273 /** @type {PlainColorObject} */
2274 color
2275 );
2276 }
2277 let spaceColor;
2278 if (method === "css") {
2279 spaceColor = toGamutCSS(color, { space });
2280 } else {
2281 if (method !== "clip" && !inGamut(color, space)) {
2282 if (Object.prototype.hasOwnProperty.call(GMAPPRESET, method)) {
2283 ({ method, jnd, deltaEMethod, blackWhiteClamp } = GMAPPRESET[method]);
2284 }
2285 let de = deltaE2000_default;
2286 if (deltaEMethod !== "") {
2287 for (let m in deltaE_default) {
2288 if ("deltae" + deltaEMethod.toLowerCase() === m.toLowerCase()) {
2289 de = deltaE_default[m];
2290 break;
2291 }
2292 }
2293 }
2294 if (jnd === 0) {
2295 jnd = 1e-16;
2296 }
2297 let clipped = toGamut(to(color, space), { method: "clip", space });
2298 if (de(color, clipped) > jnd) {
2299 if (blackWhiteClamp && Object.keys(blackWhiteClamp).length === 3) {
2300 let channelMeta = ColorSpace.resolveCoord(blackWhiteClamp.channel);
2301 let channel = get(to(color, channelMeta.space), channelMeta.id);
2302 if (isNone(channel)) {
2303 channel = 0;
2304 }
2305 if (channel >= blackWhiteClamp.max) {
2306 return to({ space: "xyz-d65", coords: WHITES["D65"] }, color.space);
2307 } else if (channel <= blackWhiteClamp.min) {
2308 return to({ space: "xyz-d65", coords: [0, 0, 0] }, color.space);
2309 }
2310 }
2311 let coordMeta = ColorSpace.resolveCoord(method);
2312 let mapSpace = coordMeta.space;
2313 let coordId = coordMeta.id;
2314 let mappedColor = to(color, mapSpace);
2315 mappedColor.coords.forEach((c, i) => {
2316 if (isNone(c)) {
2317 mappedColor.coords[i] = 0;
2318 }
2319 });
2320 let bounds = coordMeta.range || coordMeta.refRange;
2321 let min = bounds[0];
2322 let \u03B56 = calcEpsilon(jnd);
2323 let low = min;
2324 let high = get(mappedColor, coordId);
2325 while (high - low > \u03B56) {
2326 let clipped2 = clone(mappedColor);
2327 clipped2 = toGamut(clipped2, { space, method: "clip" });
2328 let deltaE = de(mappedColor, clipped2);
2329 if (deltaE - jnd < \u03B56) {
2330 low = get(mappedColor, coordId);
2331 } else {
2332 high = get(mappedColor, coordId);
2333 }
2334 set(mappedColor, coordId, (low + high) / 2);
2335 }
2336 spaceColor = to(mappedColor, space);
2337 } else {
2338 spaceColor = clipped;
2339 }
2340 } else {
2341 spaceColor = to(color, space);
2342 }
2343 if (method === "clip" || // Dumb coord clipping
2344 // finish off smarter gamut mapping with clip to get rid of ε, see #17
2345 !inGamut(spaceColor, space, { epsilon: 0 })) {
2346 let bounds = Object.values(space.coords).map((c) => c.range || []);
2347 spaceColor.coords = /** @type {[number, number, number]} */
2348 spaceColor.coords.map((c, i) => {
2349 let [min, max] = bounds[i];
2350 if (min !== void 0) {
2351 c = Math.max(min, c);
2352 }
2353 if (max !== void 0) {
2354 c = Math.min(c, max);
2355 }
2356 return c;
2357 });
2358 }
2359 }
2360 if (space !== color.space) {
2361 spaceColor = to(spaceColor, color.space);
2362 }
2363 color.coords = spaceColor.coords;
2364 return (
2365 /** @type {PlainColorObject} */
2366 color
2367 );
2368 }
2369 toGamut.returns = "color";
2370 var COLORS = {
2371 WHITE: { space: oklab_default, coords: [1, 0, 0], alpha: 1 },
2372 BLACK: { space: oklab_default, coords: [0, 0, 0], alpha: 1 }
2373 };
2374 function toGamutCSS(origin, { space } = {}) {
2375 const JND = 0.02;
2376 const \u03B56 = 1e-4;
2377 origin = getColor(origin);
2378 if (!space) {
2379 space = origin.space;
2380 }
2381 space = ColorSpace.get(space);
2382 const oklchSpace = ColorSpace.get("oklch");
2383 if (space.isUnbounded) {
2384 return to(origin, space);
2385 }
2386 const origin_OKLCH = to(origin, oklchSpace);
2387 let L = origin_OKLCH.coords[0];
2388 if (L >= 1) {
2389 const white4 = to(COLORS.WHITE, space);
2390 white4.alpha = origin.alpha;
2391 return to(white4, space);
2392 }
2393 if (L <= 0) {
2394 const black = to(COLORS.BLACK, space);
2395 black.alpha = origin.alpha;
2396 return to(black, space);
2397 }
2398 if (inGamut(origin_OKLCH, space, { epsilon: 0 })) {
2399 return to(origin_OKLCH, space);
2400 }
2401 function clip(_color) {
2402 const destColor = to(_color, space);
2403 const spaceCoords = Object.values(
2404 /** @type {ColorSpace} */
2405 space.coords
2406 );
2407 destColor.coords = /** @type {[number, number, number]} */
2408 destColor.coords.map((coord, index) => {
2409 if ("range" in spaceCoords[index]) {
2410 const [min2, max2] = spaceCoords[index].range;
2411 return clamp(min2, coord, max2);
2412 }
2413 return coord;
2414 });
2415 return destColor;
2416 }
2417 let min = 0;
2418 let max = origin_OKLCH.coords[1];
2419 let min_inGamut = true;
2420 let current = clone(origin_OKLCH);
2421 let clipped = clip(current);
2422 let E = deltaEOK_default(clipped, current);
2423 if (E < JND) {
2424 return clipped;
2425 }
2426 while (max - min > \u03B56) {
2427 const chroma = (min + max) / 2;
2428 current.coords[1] = chroma;
2429 if (min_inGamut && inGamut(current, space, { epsilon: 0 })) {
2430 min = chroma;
2431 } else {
2432 clipped = clip(current);
2433 E = deltaEOK_default(clipped, current);
2434 if (E < JND) {
2435 if (JND - E < \u03B56) {
2436 break;
2437 } else {
2438 min_inGamut = false;
2439 min = chroma;
2440 }
2441 } else {
2442 max = chroma;
2443 }
2444 }
2445 }
2446 return clipped;
2447 }
2448
2449 // packages/theme/node_modules/colorjs.io/src/to.js
2450 function to(color, space, { inGamut: inGamut2 } = {}) {
2451 color = getColor(color);
2452 space = ColorSpace.get(space);
2453 let coords = space.from(color);
2454 let ret = { space, coords, alpha: color.alpha };
2455 if (inGamut2) {
2456 ret = toGamut(ret, inGamut2 === true ? void 0 : inGamut2);
2457 }
2458 return ret;
2459 }
2460 to.returns = "color";
2461
2462 // packages/theme/node_modules/colorjs.io/src/serialize.js
2463 function serialize(color, options = {}) {
2464 let {
2465 precision = defaults_default.precision,
2466 format,
2467 inGamut: inGamut2 = true,
2468 coords: coordFormat,
2469 alpha: alphaFormat,
2470 commas
2471 } = options;
2472 let ret;
2473 let colorWithMeta = (
2474 /** @type {PlainColorObject & ParseOptions} */
2475 getColor(color)
2476 );
2477 let formatId = format;
2478 let parseMeta = colorWithMeta.parseMeta;
2479 if (parseMeta && !format) {
2480 if (parseMeta.format.canSerialize()) {
2481 format = parseMeta.format;
2482 formatId = parseMeta.formatId;
2483 }
2484 coordFormat ??= parseMeta.types;
2485 alphaFormat ??= parseMeta.alphaType;
2486 commas ??= parseMeta.commas;
2487 }
2488 if (formatId) {
2489 format = colorWithMeta.space.getFormat(format) ?? ColorSpace.findFormat(formatId);
2490 }
2491 if (!format) {
2492 format = colorWithMeta.space.getFormat("default") ?? ColorSpace.DEFAULT_FORMAT;
2493 formatId = format.name;
2494 }
2495 if (format && format.space && format.space !== colorWithMeta.space) {
2496 colorWithMeta = to(colorWithMeta, format.space);
2497 }
2498 let coords = colorWithMeta.coords.slice();
2499 inGamut2 ||= format.toGamut;
2500 if (inGamut2 && !inGamut(colorWithMeta)) {
2501 coords = toGamut(clone(colorWithMeta), inGamut2 === true ? void 0 : inGamut2).coords;
2502 }
2503 if (format.type === "custom") {
2504 if (format.serialize) {
2505 ret = format.serialize(coords, colorWithMeta.alpha, options);
2506 } else {
2507 throw new TypeError(
2508 `format ${formatId} can only be used to parse colors, not for serialization`
2509 );
2510 }
2511 } else {
2512 let name = format.name || "color";
2513 let args = format.serializeCoords(coords, precision, coordFormat);
2514 if (name === "color") {
2515 let cssId = format.id || format.ids?.[0] || colorWithMeta.space.cssId || colorWithMeta.space.id;
2516 args.unshift(cssId);
2517 }
2518 let alpha = colorWithMeta.alpha;
2519 if (alphaFormat !== void 0 && !(typeof alphaFormat === "object")) {
2520 alphaFormat = typeof alphaFormat === "string" ? { type: alphaFormat } : { include: alphaFormat };
2521 }
2522 let alphaType = alphaFormat?.type ?? "<number>";
2523 let serializeAlpha = alphaFormat?.include === true || format.alpha === true || alphaFormat?.include !== false && format.alpha !== false && alpha < 1;
2524 let strAlpha = "";
2525 commas ??= format.commas;
2526 if (serializeAlpha) {
2527 if (precision !== null) {
2528 let unit;
2529 if (alphaType === "<percentage>") {
2530 unit = "%";
2531 alpha *= 100;
2532 }
2533 alpha = serializeNumber(alpha, { precision, unit });
2534 }
2535 strAlpha = `${commas ? "," : " /"} ${alpha}`;
2536 }
2537 ret = `${name}(${args.join(commas ? ", " : " ")}${strAlpha})`;
2538 }
2539 return ret;
2540 }
2541
2542 // packages/theme/node_modules/colorjs.io/src/spaces/srgb-linear.js
2543 var toXYZ_M = [
2544 [0.41239079926595934, 0.357584339383878, 0.1804807884018343],
2545 [0.21263900587151027, 0.715168678767756, 0.07219231536073371],
2546 [0.01933081871559182, 0.11919477979462598, 0.9505321522496607]
2547 ];
2548 var fromXYZ_M = [
2549 [3.2409699419045226, -1.537383177570094, -0.4986107602930034],
2550 [-0.9692436362808796, 1.8759675015077202, 0.04155505740717559],
2551 [0.05563007969699366, -0.20397695888897652, 1.0569715142428786]
2552 ];
2553 var srgb_linear_default = new RGBColorSpace({
2554 id: "srgb-linear",
2555 name: "Linear sRGB",
2556 white: "D65",
2557 toXYZ_M,
2558 fromXYZ_M
2559 });
2560
2561 // packages/theme/node_modules/colorjs.io/src/keywords.js
2562 var keywords_default = {
2563 aliceblue: [240 / 255, 248 / 255, 1],
2564 antiquewhite: [250 / 255, 235 / 255, 215 / 255],
2565 aqua: [0, 1, 1],
2566 aquamarine: [127 / 255, 1, 212 / 255],
2567 azure: [240 / 255, 1, 1],
2568 beige: [245 / 255, 245 / 255, 220 / 255],
2569 bisque: [1, 228 / 255, 196 / 255],
2570 black: [0, 0, 0],
2571 blanchedalmond: [1, 235 / 255, 205 / 255],
2572 blue: [0, 0, 1],
2573 blueviolet: [138 / 255, 43 / 255, 226 / 255],
2574 brown: [165 / 255, 42 / 255, 42 / 255],
2575 burlywood: [222 / 255, 184 / 255, 135 / 255],
2576 cadetblue: [95 / 255, 158 / 255, 160 / 255],
2577 chartreuse: [127 / 255, 1, 0],
2578 chocolate: [210 / 255, 105 / 255, 30 / 255],
2579 coral: [1, 127 / 255, 80 / 255],
2580 cornflowerblue: [100 / 255, 149 / 255, 237 / 255],
2581 cornsilk: [1, 248 / 255, 220 / 255],
2582 crimson: [220 / 255, 20 / 255, 60 / 255],
2583 cyan: [0, 1, 1],
2584 darkblue: [0, 0, 139 / 255],
2585 darkcyan: [0, 139 / 255, 139 / 255],
2586 darkgoldenrod: [184 / 255, 134 / 255, 11 / 255],
2587 darkgray: [169 / 255, 169 / 255, 169 / 255],
2588 darkgreen: [0, 100 / 255, 0],
2589 darkgrey: [169 / 255, 169 / 255, 169 / 255],
2590 darkkhaki: [189 / 255, 183 / 255, 107 / 255],
2591 darkmagenta: [139 / 255, 0, 139 / 255],
2592 darkolivegreen: [85 / 255, 107 / 255, 47 / 255],
2593 darkorange: [1, 140 / 255, 0],
2594 darkorchid: [153 / 255, 50 / 255, 204 / 255],
2595 darkred: [139 / 255, 0, 0],
2596 darksalmon: [233 / 255, 150 / 255, 122 / 255],
2597 darkseagreen: [143 / 255, 188 / 255, 143 / 255],
2598 darkslateblue: [72 / 255, 61 / 255, 139 / 255],
2599 darkslategray: [47 / 255, 79 / 255, 79 / 255],
2600 darkslategrey: [47 / 255, 79 / 255, 79 / 255],
2601 darkturquoise: [0, 206 / 255, 209 / 255],
2602 darkviolet: [148 / 255, 0, 211 / 255],
2603 deeppink: [1, 20 / 255, 147 / 255],
2604 deepskyblue: [0, 191 / 255, 1],
2605 dimgray: [105 / 255, 105 / 255, 105 / 255],
2606 dimgrey: [105 / 255, 105 / 255, 105 / 255],
2607 dodgerblue: [30 / 255, 144 / 255, 1],
2608 firebrick: [178 / 255, 34 / 255, 34 / 255],
2609 floralwhite: [1, 250 / 255, 240 / 255],
2610 forestgreen: [34 / 255, 139 / 255, 34 / 255],
2611 fuchsia: [1, 0, 1],
2612 gainsboro: [220 / 255, 220 / 255, 220 / 255],
2613 ghostwhite: [248 / 255, 248 / 255, 1],
2614 gold: [1, 215 / 255, 0],
2615 goldenrod: [218 / 255, 165 / 255, 32 / 255],
2616 gray: [128 / 255, 128 / 255, 128 / 255],
2617 green: [0, 128 / 255, 0],
2618 greenyellow: [173 / 255, 1, 47 / 255],
2619 grey: [128 / 255, 128 / 255, 128 / 255],
2620 honeydew: [240 / 255, 1, 240 / 255],
2621 hotpink: [1, 105 / 255, 180 / 255],
2622 indianred: [205 / 255, 92 / 255, 92 / 255],
2623 indigo: [75 / 255, 0, 130 / 255],
2624 ivory: [1, 1, 240 / 255],
2625 khaki: [240 / 255, 230 / 255, 140 / 255],
2626 lavender: [230 / 255, 230 / 255, 250 / 255],
2627 lavenderblush: [1, 240 / 255, 245 / 255],
2628 lawngreen: [124 / 255, 252 / 255, 0],
2629 lemonchiffon: [1, 250 / 255, 205 / 255],
2630 lightblue: [173 / 255, 216 / 255, 230 / 255],
2631 lightcoral: [240 / 255, 128 / 255, 128 / 255],
2632 lightcyan: [224 / 255, 1, 1],
2633 lightgoldenrodyellow: [250 / 255, 250 / 255, 210 / 255],
2634 lightgray: [211 / 255, 211 / 255, 211 / 255],
2635 lightgreen: [144 / 255, 238 / 255, 144 / 255],
2636 lightgrey: [211 / 255, 211 / 255, 211 / 255],
2637 lightpink: [1, 182 / 255, 193 / 255],
2638 lightsalmon: [1, 160 / 255, 122 / 255],
2639 lightseagreen: [32 / 255, 178 / 255, 170 / 255],
2640 lightskyblue: [135 / 255, 206 / 255, 250 / 255],
2641 lightslategray: [119 / 255, 136 / 255, 153 / 255],
2642 lightslategrey: [119 / 255, 136 / 255, 153 / 255],
2643 lightsteelblue: [176 / 255, 196 / 255, 222 / 255],
2644 lightyellow: [1, 1, 224 / 255],
2645 lime: [0, 1, 0],
2646 limegreen: [50 / 255, 205 / 255, 50 / 255],
2647 linen: [250 / 255, 240 / 255, 230 / 255],
2648 magenta: [1, 0, 1],
2649 maroon: [128 / 255, 0, 0],
2650 mediumaquamarine: [102 / 255, 205 / 255, 170 / 255],
2651 mediumblue: [0, 0, 205 / 255],
2652 mediumorchid: [186 / 255, 85 / 255, 211 / 255],
2653 mediumpurple: [147 / 255, 112 / 255, 219 / 255],
2654 mediumseagreen: [60 / 255, 179 / 255, 113 / 255],
2655 mediumslateblue: [123 / 255, 104 / 255, 238 / 255],
2656 mediumspringgreen: [0, 250 / 255, 154 / 255],
2657 mediumturquoise: [72 / 255, 209 / 255, 204 / 255],
2658 mediumvioletred: [199 / 255, 21 / 255, 133 / 255],
2659 midnightblue: [25 / 255, 25 / 255, 112 / 255],
2660 mintcream: [245 / 255, 1, 250 / 255],
2661 mistyrose: [1, 228 / 255, 225 / 255],
2662 moccasin: [1, 228 / 255, 181 / 255],
2663 navajowhite: [1, 222 / 255, 173 / 255],
2664 navy: [0, 0, 128 / 255],
2665 oldlace: [253 / 255, 245 / 255, 230 / 255],
2666 olive: [128 / 255, 128 / 255, 0],
2667 olivedrab: [107 / 255, 142 / 255, 35 / 255],
2668 orange: [1, 165 / 255, 0],
2669 orangered: [1, 69 / 255, 0],
2670 orchid: [218 / 255, 112 / 255, 214 / 255],
2671 palegoldenrod: [238 / 255, 232 / 255, 170 / 255],
2672 palegreen: [152 / 255, 251 / 255, 152 / 255],
2673 paleturquoise: [175 / 255, 238 / 255, 238 / 255],
2674 palevioletred: [219 / 255, 112 / 255, 147 / 255],
2675 papayawhip: [1, 239 / 255, 213 / 255],
2676 peachpuff: [1, 218 / 255, 185 / 255],
2677 peru: [205 / 255, 133 / 255, 63 / 255],
2678 pink: [1, 192 / 255, 203 / 255],
2679 plum: [221 / 255, 160 / 255, 221 / 255],
2680 powderblue: [176 / 255, 224 / 255, 230 / 255],
2681 purple: [128 / 255, 0, 128 / 255],
2682 rebeccapurple: [102 / 255, 51 / 255, 153 / 255],
2683 red: [1, 0, 0],
2684 rosybrown: [188 / 255, 143 / 255, 143 / 255],
2685 royalblue: [65 / 255, 105 / 255, 225 / 255],
2686 saddlebrown: [139 / 255, 69 / 255, 19 / 255],
2687 salmon: [250 / 255, 128 / 255, 114 / 255],
2688 sandybrown: [244 / 255, 164 / 255, 96 / 255],
2689 seagreen: [46 / 255, 139 / 255, 87 / 255],
2690 seashell: [1, 245 / 255, 238 / 255],
2691 sienna: [160 / 255, 82 / 255, 45 / 255],
2692 silver: [192 / 255, 192 / 255, 192 / 255],
2693 skyblue: [135 / 255, 206 / 255, 235 / 255],
2694 slateblue: [106 / 255, 90 / 255, 205 / 255],
2695 slategray: [112 / 255, 128 / 255, 144 / 255],
2696 slategrey: [112 / 255, 128 / 255, 144 / 255],
2697 snow: [1, 250 / 255, 250 / 255],
2698 springgreen: [0, 1, 127 / 255],
2699 steelblue: [70 / 255, 130 / 255, 180 / 255],
2700 tan: [210 / 255, 180 / 255, 140 / 255],
2701 teal: [0, 128 / 255, 128 / 255],
2702 thistle: [216 / 255, 191 / 255, 216 / 255],
2703 tomato: [1, 99 / 255, 71 / 255],
2704 turquoise: [64 / 255, 224 / 255, 208 / 255],
2705 violet: [238 / 255, 130 / 255, 238 / 255],
2706 wheat: [245 / 255, 222 / 255, 179 / 255],
2707 white: [1, 1, 1],
2708 whitesmoke: [245 / 255, 245 / 255, 245 / 255],
2709 yellow: [1, 1, 0],
2710 yellowgreen: [154 / 255, 205 / 255, 50 / 255]
2711 };
2712
2713 // packages/theme/node_modules/colorjs.io/src/spaces/srgb.js
2714 var coordGrammar = Array(3).fill("<percentage> | <number>[0, 255]");
2715 var coordGrammarNumber = Array(3).fill("<number>[0, 255]");
2716 var srgb_default = new RGBColorSpace({
2717 id: "srgb",
2718 name: "sRGB",
2719 base: srgb_linear_default,
2720 fromBase: (rgb) => {
2721 return rgb.map((val) => {
2722 let sign = val < 0 ? -1 : 1;
2723 let abs = val * sign;
2724 if (abs > 31308e-7) {
2725 return sign * (1.055 * abs ** (1 / 2.4) - 0.055);
2726 }
2727 return 12.92 * val;
2728 });
2729 },
2730 toBase: (rgb) => {
2731 return rgb.map((val) => {
2732 let sign = val < 0 ? -1 : 1;
2733 let abs = val * sign;
2734 if (abs <= 0.04045) {
2735 return val / 12.92;
2736 }
2737 return sign * ((abs + 0.055) / 1.055) ** 2.4;
2738 });
2739 },
2740 formats: {
2741 rgb: {
2742 coords: coordGrammar
2743 },
2744 rgb_number: {
2745 name: "rgb",
2746 commas: true,
2747 coords: coordGrammarNumber,
2748 alpha: false
2749 },
2750 color: {
2751 /* use defaults */
2752 },
2753 rgba: {
2754 coords: coordGrammar,
2755 commas: true,
2756 alpha: true
2757 },
2758 rgba_number: {
2759 name: "rgba",
2760 commas: true,
2761 coords: coordGrammarNumber
2762 },
2763 hex: {
2764 type: "custom",
2765 toGamut: true,
2766 test: (str) => /^#(([a-f0-9]{2}){3,4}|[a-f0-9]{3,4})$/i.test(str),
2767 parse(str) {
2768 if (str.length <= 5) {
2769 str = str.replace(/[a-f0-9]/gi, "$&$&");
2770 }
2771 let rgba = [];
2772 str.replace(/[a-f0-9]{2}/gi, (component) => {
2773 rgba.push(parseInt(component, 16) / 255);
2774 });
2775 return {
2776 spaceId: "srgb",
2777 coords: (
2778 /** @type {Coords} */
2779 rgba.slice(0, 3)
2780 ),
2781 alpha: (
2782 /** @type {number} */
2783 rgba.slice(3)[0]
2784 )
2785 };
2786 },
2787 serialize: (coords, alpha, {
2788 collapse = true,
2789 // collapse to 3-4 digit hex when possible?
2790 alpha: alphaFormat
2791 } = {}) => {
2792 if (alphaFormat !== false && alpha < 1 || alphaFormat === true) {
2793 coords.push(alpha);
2794 }
2795 coords = /** @type {[number, number, number]} */
2796 coords.map((c) => Math.round(c * 255));
2797 let collapsible = collapse && coords.every((c) => c % 17 === 0);
2798 let hex = coords.map((c) => {
2799 if (collapsible) {
2800 return (c / 17).toString(16);
2801 }
2802 return c.toString(16).padStart(2, "0");
2803 }).join("");
2804 return "#" + hex;
2805 }
2806 },
2807 keyword: {
2808 type: "custom",
2809 test: (str) => /^[a-z]+$/i.test(str),
2810 parse(str) {
2811 str = str.toLowerCase();
2812 let ret = { spaceId: "srgb", coords: null, alpha: 1 };
2813 if (str === "transparent") {
2814 ret.coords = keywords_default.black;
2815 ret.alpha = 0;
2816 } else {
2817 ret.coords = keywords_default[str];
2818 }
2819 if (ret.coords) {
2820 return ret;
2821 }
2822 }
2823 }
2824 }
2825 });
2826
2827 // packages/theme/node_modules/colorjs.io/src/luminance.js
2828 function getLuminance(color) {
2829 return get(color, [xyz_d65_default, "y"]);
2830 }
2831
2832 // packages/theme/node_modules/colorjs.io/src/contrast/WCAG21.js
2833 function contrastWCAG21(color1, color2) {
2834 color1 = getColor(color1);
2835 color2 = getColor(color2);
2836 let Y1 = Math.max(getLuminance(color1), 0);
2837 let Y2 = Math.max(getLuminance(color2), 0);
2838 if (Y2 > Y1) {
2839 [Y1, Y2] = [Y2, Y1];
2840 }
2841 return (Y1 + 0.05) / (Y2 + 0.05);
2842 }
2843
2844 // packages/theme/node_modules/colorjs.io/src/spaces/hsl.js
2845 var hsl_default = new ColorSpace({
2846 id: "hsl",
2847 name: "HSL",
2848 coords: {
2849 h: {
2850 refRange: [0, 360],
2851 type: "angle",
2852 name: "Hue"
2853 },
2854 s: {
2855 range: [0, 100],
2856 name: "Saturation"
2857 },
2858 l: {
2859 range: [0, 100],
2860 name: "Lightness"
2861 }
2862 },
2863 base: srgb_default,
2864 // Adapted from https://drafts.csswg.org/css-color-4/better-rgbToHsl.js
2865 fromBase: (rgb) => {
2866 let max = Math.max(...rgb);
2867 let min = Math.min(...rgb);
2868 let [r, g2, b2] = rgb;
2869 let [h, s, l] = [null, 0, (min + max) / 2];
2870 let d2 = max - min;
2871 if (d2 !== 0) {
2872 s = l === 0 || l === 1 ? 0 : (max - l) / Math.min(l, 1 - l);
2873 switch (max) {
2874 case r:
2875 h = (g2 - b2) / d2 + (g2 < b2 ? 6 : 0);
2876 break;
2877 case g2:
2878 h = (b2 - r) / d2 + 2;
2879 break;
2880 case b2:
2881 h = (r - g2) / d2 + 4;
2882 }
2883 h = h * 60;
2884 }
2885 if (s < 0) {
2886 h += 180;
2887 s = Math.abs(s);
2888 }
2889 if (h >= 360) {
2890 h -= 360;
2891 }
2892 return [h, s * 100, l * 100];
2893 },
2894 // Adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative
2895 toBase: (hsl) => {
2896 let [h, s, l] = hsl;
2897 h = h % 360;
2898 if (h < 0) {
2899 h += 360;
2900 }
2901 s /= 100;
2902 l /= 100;
2903 function f(n2) {
2904 let k = (n2 + h / 30) % 12;
2905 let a = s * Math.min(l, 1 - l);
2906 return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
2907 }
2908 return [f(0), f(8), f(4)];
2909 },
2910 formats: {
2911 hsl: {
2912 coords: ["<number> | <angle>", "<percentage> | <number>", "<percentage> | <number>"]
2913 },
2914 hsla: {
2915 coords: ["<number> | <angle>", "<percentage> | <number>", "<percentage> | <number>"],
2916 commas: true,
2917 alpha: true
2918 }
2919 }
2920 });
2921
2922 // packages/theme/node_modules/colorjs.io/src/spaces/oklch.js
2923 var oklch_default = new ColorSpace({
2924 id: "oklch",
2925 name: "OkLCh",
2926 coords: {
2927 l: {
2928 refRange: [0, 1],
2929 name: "Lightness"
2930 },
2931 c: {
2932 refRange: [0, 0.4],
2933 name: "Chroma"
2934 },
2935 h: {
2936 refRange: [0, 360],
2937 type: "angle",
2938 name: "Hue"
2939 }
2940 },
2941 white: "D65",
2942 base: oklab_default,
2943 fromBase: lch_default.fromBase,
2944 toBase: lch_default.toBase,
2945 formats: {
2946 oklch: {
2947 coords: ["<percentage> | <number>", "<number> | <percentage>", "<number> | <angle>"]
2948 }
2949 }
2950 });
2951
2952 // node_modules/memize/dist/index.js
2953 function memize(fn, options) {
2954 var size = 0;
2955 var head;
2956 var tail;
2957 options = options || {};
2958 function memoized() {
2959 var node = head, len = arguments.length, args, i;
2960 searchCache: while (node) {
2961 if (node.args.length !== arguments.length) {
2962 node = node.next;
2963 continue;
2964 }
2965 for (i = 0; i < len; i++) {
2966 if (node.args[i] !== arguments[i]) {
2967 node = node.next;
2968 continue searchCache;
2969 }
2970 }
2971 if (node !== head) {
2972 if (node === tail) {
2973 tail = node.prev;
2974 }
2975 node.prev.next = node.next;
2976 if (node.next) {
2977 node.next.prev = node.prev;
2978 }
2979 node.next = head;
2980 node.prev = null;
2981 head.prev = node;
2982 head = node;
2983 }
2984 return node.val;
2985 }
2986 args = new Array(len);
2987 for (i = 0; i < len; i++) {
2988 args[i] = arguments[i];
2989 }
2990 node = {
2991 args,
2992 // Generate the result from original function
2993 val: fn.apply(null, args)
2994 };
2995 if (head) {
2996 head.prev = node;
2997 node.next = head;
2998 } else {
2999 tail = node;
3000 }
3001 if (size === /** @type {MemizeOptions} */
3002 options.maxSize) {
3003 tail = /** @type {MemizeCacheNode} */
3004 tail.prev;
3005 tail.next = null;
3006 } else {
3007 size++;
3008 }
3009 head = node;
3010 return node.val;
3011 }
3012 memoized.clear = function() {
3013 head = null;
3014 tail = null;
3015 size = 0;
3016 };
3017 return memoized;
3018 }
3019
3020 // packages/theme/build-module/use-theme-provider-styles.mjs
3021 var import_element2 = __toESM(require_element(), 1);
3022
3023 // packages/theme/build-module/prebuilt/ts/color-tokens.mjs
3024 var color_tokens_default = {
3025 transparent: [
3026 "background-interactive-brand-weak",
3027 "background-interactive-brand-weak-disabled",
3028 "background-interactive-error",
3029 "background-interactive-error-disabled",
3030 "background-interactive-error-weak",
3031 "background-interactive-error-weak-disabled",
3032 "background-interactive-neutral-weak",
3033 "background-interactive-neutral-weak-disabled"
3034 ],
3035 "primary-bgFill1": ["background-interactive-brand-strong"],
3036 "primary-fgFill": [
3037 "foreground-interactive-brand-strong",
3038 "foreground-interactive-brand-strong-active"
3039 ],
3040 "primary-bgFill2": ["background-interactive-brand-strong-active"],
3041 "primary-surface4": ["background-interactive-brand-weak-active"],
3042 "primary-fgSurface4": ["foreground-interactive-brand-active"],
3043 "primary-fgSurface3": ["foreground-interactive-brand"],
3044 "primary-stroke3": [
3045 "background-thumb-brand",
3046 "background-thumb-brand-active",
3047 "stroke-focus",
3048 "stroke-interactive-brand",
3049 "stroke-surface-brand-strong"
3050 ],
3051 "primary-stroke4": ["stroke-interactive-brand-active"],
3052 "primary-stroke1": ["stroke-surface-brand"],
3053 "primary-surface1": ["background-surface-brand"],
3054 "info-surface2": ["background-surface-info-weak"],
3055 "info-surface4": ["background-surface-info"],
3056 "info-fgSurface4": ["foreground-content-info"],
3057 "info-fgSurface3": ["foreground-content-info-weak"],
3058 "info-stroke3": ["stroke-surface-info-strong"],
3059 "info-stroke1": ["stroke-surface-info"],
3060 "success-surface2": ["background-surface-success-weak"],
3061 "success-surface4": ["background-surface-success"],
3062 "success-fgSurface4": ["foreground-content-success"],
3063 "success-fgSurface3": ["foreground-content-success-weak"],
3064 "success-stroke3": ["stroke-surface-success-strong"],
3065 "success-stroke1": ["stroke-surface-success"],
3066 "warning-surface2": ["background-surface-warning-weak"],
3067 "warning-surface4": ["background-surface-warning"],
3068 "warning-fgSurface4": ["foreground-content-warning"],
3069 "warning-fgSurface3": ["foreground-content-warning-weak"],
3070 "warning-stroke3": ["stroke-surface-warning-strong"],
3071 "warning-stroke1": ["stroke-surface-warning"],
3072 "error-bgFill1": ["background-interactive-error-strong"],
3073 "error-fgFill": [
3074 "foreground-interactive-error-strong",
3075 "foreground-interactive-error-strong-active"
3076 ],
3077 "error-bgFill2": ["background-interactive-error-strong-active"],
3078 "error-surface2": [
3079 "background-interactive-error-active",
3080 "background-surface-error-weak"
3081 ],
3082 "error-surface4": [
3083 "background-interactive-error-weak-active",
3084 "background-surface-error"
3085 ],
3086 "error-fgSurface4": [
3087 "foreground-content-error",
3088 "foreground-interactive-error-active"
3089 ],
3090 "error-fgSurface3": [
3091 "foreground-content-error-weak",
3092 "foreground-interactive-error"
3093 ],
3094 "error-stroke3": [
3095 "stroke-interactive-error",
3096 "stroke-interactive-error-strong",
3097 "stroke-surface-error-strong"
3098 ],
3099 "error-stroke4": ["stroke-interactive-error-active"],
3100 "error-stroke1": ["stroke-surface-error"],
3101 "bg-surface2": ["background-surface-neutral"],
3102 "bg-surface5": [
3103 "background-interactive-brand-strong-disabled",
3104 "background-interactive-error-strong-disabled",
3105 "background-interactive-neutral-strong-disabled"
3106 ],
3107 "bg-surface4": ["background-interactive-neutral-weak-active"],
3108 "bg-surface3": ["background-surface-neutral-strong"],
3109 "bg-fgSurface4": [
3110 "foreground-content-neutral",
3111 "foreground-interactive-neutral",
3112 "foreground-interactive-neutral-active",
3113 "foreground-interactive-neutral-weak-active"
3114 ],
3115 "bg-fgSurface3": [
3116 "foreground-content-neutral-weak",
3117 "foreground-interactive-neutral-weak"
3118 ],
3119 "bg-fgSurface2": [
3120 "foreground-interactive-brand-disabled",
3121 "foreground-interactive-brand-strong-disabled",
3122 "foreground-interactive-error-disabled",
3123 "foreground-interactive-error-strong-disabled",
3124 "foreground-interactive-neutral-disabled",
3125 "foreground-interactive-neutral-strong-disabled",
3126 "foreground-interactive-neutral-weak-disabled"
3127 ],
3128 "bg-stroke3": [
3129 "background-thumb-neutral-weak",
3130 "stroke-interactive-neutral",
3131 "stroke-surface-neutral-strong"
3132 ],
3133 "bg-stroke4": [
3134 "background-thumb-neutral-weak-active",
3135 "stroke-interactive-neutral-active",
3136 "stroke-interactive-neutral-strong"
3137 ],
3138 "bg-stroke2": [
3139 "background-thumb-brand-disabled",
3140 "background-thumb-neutral-weak-disabled",
3141 "background-track-neutral",
3142 "stroke-interactive-brand-disabled",
3143 "stroke-interactive-error-disabled",
3144 "stroke-interactive-neutral-disabled",
3145 "stroke-surface-neutral"
3146 ],
3147 "bg-stroke1": [
3148 "background-track-neutral-weak",
3149 "stroke-surface-neutral-weak"
3150 ],
3151 "bg-bgFillInverted2": ["background-interactive-neutral-strong-active"],
3152 "bg-bgFillInverted1": ["background-interactive-neutral-strong"],
3153 "bg-fgFillInverted": [
3154 "foreground-interactive-neutral-strong",
3155 "foreground-interactive-neutral-strong-active"
3156 ],
3157 "bg-surface1": ["background-surface-neutral-weak"],
3158 "caution-surface2": ["background-surface-caution-weak"],
3159 "caution-surface4": ["background-surface-caution"],
3160 "caution-fgSurface4": ["foreground-content-caution"],
3161 "caution-fgSurface3": ["foreground-content-caution-weak"],
3162 "caution-stroke3": ["stroke-surface-caution-strong"],
3163 "caution-stroke1": ["stroke-surface-caution"]
3164 };
3165
3166 // packages/theme/build-module/color-ramps/lib/color-utils.mjs
3167 var ALLOWED_SEED_COLOR_SPACES = [srgb_default];
3168 function getColorString(color) {
3169 ColorSpace.register(srgb_default);
3170 const rgbRounded = serialize(to(color, srgb_default));
3171 return serialize(rgbRounded, { format: "hex" });
3172 }
3173 function getContrast(colorA, colorB) {
3174 ColorSpace.register(srgb_default);
3175 return contrastWCAG21(colorA, colorB);
3176 }
3177 function assertValidSeedColor(seed) {
3178 ALLOWED_SEED_COLOR_SPACES.forEach(
3179 (space) => ColorSpace.register(space)
3180 );
3181 let parsedColor;
3182 try {
3183 parsedColor = parse(seed);
3184 } catch {
3185 throw new Error(
3186 `Unsupported seed color "${seed}": expected a fully opaque hex value, an \`rgb()\`/\`rgba()\` string, or a CSS named color.`
3187 );
3188 }
3189 const { alpha = 1, spaceId } = parsedColor;
3190 if (!ALLOWED_SEED_COLOR_SPACES.some((space) => space.id === spaceId)) {
3191 throw new Error(
3192 `Unsupported seed color "${seed}": expected a fully opaque hex value, an \`rgb()\`/\`rgba()\` string, or a CSS named color, but received a \`${spaceId}\` color.`
3193 );
3194 }
3195 if (alpha !== 1) {
3196 throw new Error(
3197 `Unsupported seed color "${seed}": expected a fully opaque color.`
3198 );
3199 }
3200 }
3201 function clampToGamut(c) {
3202 ColorSpace.register(srgb_default);
3203 ColorSpace.register(oklch_default);
3204 return to(toGamut(c, { space: srgb_default, method: "css" }), oklch_default);
3205 }
3206
3207 // packages/theme/build-module/color-ramps/lib/constants.mjs
3208 var WHITE = {
3209 space: oklch_default,
3210 coords: [1, 0, 0],
3211 alpha: 1
3212 };
3213 var BLACK = {
3214 space: oklch_default,
3215 coords: [0, 0, 0],
3216 alpha: 1
3217 };
3218 var UNIVERSAL_CONTRAST_TOPUP = 0.02;
3219 var WHITE_TEXT_CONTRAST_MARGIN = 3.1;
3220 var ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS = {
3221 lighter: { min: 0.2, max: 0.4 },
3222 darker: { min: 0.75, max: 0.98 }
3223 };
3224 var CONTRAST_EPSILON = 4e-3;
3225 var MAX_BISECTION_ITERATIONS = 10;
3226 var DEFAULT_SEED_COLORS = {
3227 background: "#fcfcfc",
3228 primary: "#3858e9",
3229 info: "#0090ff",
3230 success: "#4ab866",
3231 caution: "#f0d149",
3232 warning: "#f0b849",
3233 error: "#cc1818"
3234 };
3235
3236 // packages/theme/build-module/color-ramps/lib/utils.mjs
3237 function buildDependencyGraph(config) {
3238 const dependencies = /* @__PURE__ */ new Map();
3239 const dependents = /* @__PURE__ */ new Map();
3240 Object.keys(config).forEach((step) => {
3241 dependencies.set(step, []);
3242 });
3243 dependents.set("seed", []);
3244 Object.keys(config).forEach((step) => {
3245 dependents.set(step, []);
3246 });
3247 Object.entries(config).forEach(([stepName, stepConfig]) => {
3248 const step = stepName;
3249 const reference = stepConfig.contrast.reference;
3250 dependencies.get(step).push(reference);
3251 dependents.get(reference).push(step);
3252 if (stepConfig.sameAsIfPossible) {
3253 dependencies.get(step).push(stepConfig.sameAsIfPossible);
3254 dependents.get(stepConfig.sameAsIfPossible).push(step);
3255 }
3256 });
3257 return { dependencies, dependents };
3258 }
3259 function sortByDependency(config) {
3260 const { dependents } = buildDependencyGraph(config);
3261 const result = [];
3262 const visited = /* @__PURE__ */ new Set();
3263 const visiting = /* @__PURE__ */ new Set();
3264 function visit(node) {
3265 if (visiting.has(node)) {
3266 throw new Error(
3267 `Circular dependency detected involving step: ${String(
3268 node
3269 )}`
3270 );
3271 }
3272 if (visited.has(node)) {
3273 return;
3274 }
3275 visiting.add(node);
3276 const nodeDependents = dependents.get(node) || [];
3277 nodeDependents.forEach((dependent) => {
3278 visit(dependent);
3279 });
3280 visiting.delete(node);
3281 visited.add(node);
3282 if (node !== "seed") {
3283 result.unshift(node);
3284 }
3285 }
3286 visit("seed");
3287 return result;
3288 }
3289 function stepsForStep(stepName, config) {
3290 const result = /* @__PURE__ */ new Set();
3291 function visit(step) {
3292 if (step === "seed" || result.has(step)) {
3293 return;
3294 }
3295 const stepConfig = config[step];
3296 if (!stepConfig) {
3297 return;
3298 }
3299 visit(stepConfig.contrast.reference);
3300 if (stepConfig.sameAsIfPossible) {
3301 visit(stepConfig.sameAsIfPossible);
3302 }
3303 result.add(step);
3304 }
3305 visit(stepName);
3306 return Array.from(result);
3307 }
3308 function computeBetterFgColorDirection(seed, preferLighter) {
3309 const contrastAgainstBlack = getContrast(seed, BLACK);
3310 const contrastAgainstWhite = getContrast(seed, WHITE);
3311 return contrastAgainstBlack > contrastAgainstWhite + (preferLighter ? WHITE_TEXT_CONTRAST_MARGIN : 0) ? { better: "darker", worse: "lighter" } : { better: "lighter", worse: "darker" };
3312 }
3313 function adjustContrastTarget(target) {
3314 if (target === 1) {
3315 return 1;
3316 }
3317 return target + UNIVERSAL_CONTRAST_TOPUP;
3318 }
3319 function clampAccentScaleReferenceLightness(rawLightness, direction) {
3320 const thresholds = ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS[direction];
3321 return Math.max(thresholds.min, Math.min(thresholds.max, rawLightness));
3322 }
3323 function solveWithBisect(calculateC, calculateValue, initLowerL, initLowerValue, initUpperL, initUpperValue) {
3324 let lowerL = initLowerL;
3325 let lowerValue = initLowerValue;
3326 let lowerReplaced = false;
3327 let upperL = initUpperL;
3328 let upperValue = initUpperValue;
3329 let upperReplaced = false;
3330 let bestC;
3331 let bestValue;
3332 let iterations = 0;
3333 while (true) {
3334 iterations++;
3335 const newL = (lowerL * upperValue - upperL * lowerValue) / (upperValue - lowerValue);
3336 bestC = calculateC(newL);
3337 bestValue = calculateValue(bestC);
3338 if (Math.abs(bestValue) <= CONTRAST_EPSILON || iterations >= MAX_BISECTION_ITERATIONS) {
3339 break;
3340 }
3341 if (bestValue <= 0) {
3342 lowerL = newL;
3343 lowerValue = bestValue;
3344 if (lowerReplaced) {
3345 upperValue /= 2;
3346 }
3347 lowerReplaced = true;
3348 upperReplaced = false;
3349 } else {
3350 upperL = newL;
3351 upperValue = bestValue;
3352 if (upperReplaced) {
3353 lowerValue /= 2;
3354 }
3355 upperReplaced = true;
3356 lowerReplaced = false;
3357 }
3358 }
3359 return bestC;
3360 }
3361
3362 // packages/theme/build-module/color-ramps/lib/taper-chroma.mjs
3363 function taperChroma(seed, lTarget, options = {}) {
3364 ColorSpace.register(oklch_default);
3365 const gamut = options.gamut ?? srgb_default;
3366 const alpha = options.alpha ?? 0.65;
3367 const carry = options.carry ?? 0.5;
3368 const cUpperBound = options.cUpperBound ?? 0.45;
3369 const radiusLight = options.radiusLight ?? 0.2;
3370 const radiusDark = options.radiusDark ?? 0.2;
3371 const kLight = options.kLight ?? 0.85;
3372 const kDark = options.kDark ?? 0.85;
3373 const achromaEpsilon = options.achromaEpsilon ?? 5e-3;
3374 const cSeed = Math.max(0, get(seed, [oklch_default, "c"]));
3375 let hSeed = get(seed, [oklch_default, "h"]);
3376 const chromaIsTiny = cSeed < achromaEpsilon;
3377 const hueIsInvalid = hSeed === null || !Number.isFinite(hSeed);
3378 if (chromaIsTiny || hueIsInvalid) {
3379 if (typeof options.hueFallback === "number") {
3380 hSeed = normalizeHue(options.hueFallback);
3381 } else {
3382 return {
3383 space: oklch_default,
3384 coords: [clamp01(lTarget), 0, 0],
3385 alpha: 1
3386 };
3387 }
3388 }
3389 const lSeed = clamp01(get(seed, [oklch_default, "l"]));
3390 const cmaxSeed = getCachedMaxChromaAtLH(lSeed, hSeed, gamut, cUpperBound);
3391 const cmaxTarget = getCachedMaxChromaAtLH(
3392 clamp01(lTarget),
3393 hSeed,
3394 gamut,
3395 cUpperBound
3396 );
3397 let seedRelative = 0;
3398 const denom = cmaxSeed > 0 ? cmaxSeed : 1e-6;
3399 seedRelative = clamp01(cSeed / denom);
3400 const cIntendedBase = alpha * cmaxTarget;
3401 const cWithCarry = cIntendedBase * Math.pow(seedRelative, clamp01(carry));
3402 const t = continuousTaper(lSeed, lTarget, {
3403 radiusLight,
3404 radiusDark,
3405 kLight,
3406 kDark
3407 });
3408 const cPlanned = cWithCarry * t;
3409 const lOut = clamp01(lTarget);
3410 return { l: lOut, c: cPlanned };
3411 }
3412 function clamp01(x) {
3413 if (x < 0) {
3414 return 0;
3415 }
3416 if (x > 1) {
3417 return 1;
3418 }
3419 return x;
3420 }
3421 function normalizeHue(h) {
3422 let hue = h % 360;
3423 if (hue < 0) {
3424 hue += 360;
3425 }
3426 return hue;
3427 }
3428 function raisedCosine(u) {
3429 const x = clamp01(u);
3430 return 0.5 - 0.5 * Math.cos(Math.PI * x);
3431 }
3432 function continuousTaper(seedL, targetL, opts) {
3433 const d2 = targetL - seedL;
3434 if (d2 >= 0) {
3435 const u2 = opts.radiusLight > 0 ? Math.abs(d2) / opts.radiusLight : 1;
3436 const w2 = raisedCosine(u2 > 1 ? 1 : u2);
3437 return 1 - (1 - opts.kLight) * w2;
3438 }
3439 const u = opts.radiusDark > 0 ? Math.abs(d2) / opts.radiusDark : 1;
3440 const w = raisedCosine(u > 1 ? 1 : u);
3441 return 1 - (1 - opts.kDark) * w;
3442 }
3443 var maxChromaCache = /* @__PURE__ */ new Map();
3444 function keyMax(l, h, gamut, cap) {
3445 const lq = quantize(l, 0.05);
3446 const hq = quantize(normalizeHue(h), 10);
3447 const cq = quantize(cap, 0.05);
3448 return `${gamut}|L:${lq}|H:${hq}|cap:${cq}`;
3449 }
3450 function quantize(x, step) {
3451 const k = Math.round(x / step);
3452 return k * step;
3453 }
3454 function getCachedMaxChromaAtLH(l, h, gamutSpace, cap) {
3455 const gamut = gamutSpace.id;
3456 const key = keyMax(l, h, gamut, cap);
3457 const hit = maxChromaCache.get(key);
3458 if (typeof hit === "number") {
3459 return hit;
3460 }
3461 const computed = maxInGamutChromaAtLH(l, h, gamutSpace, cap);
3462 maxChromaCache.set(key, computed);
3463 return computed;
3464 }
3465 function maxInGamutChromaAtLH(l, h, gamutSpace, cap) {
3466 const probe = {
3467 space: oklch_default,
3468 coords: [l, cap, h],
3469 alpha: 1
3470 };
3471 const clamped = toGamut(probe, { space: gamutSpace, method: "css" });
3472 return get(clamped, [oklch_default, "c"]);
3473 }
3474
3475 // packages/theme/build-module/color-ramps/lib/find-color-with-constraints.mjs
3476 function cdiff(c13, c23) {
3477 return Math.log(c13 / c23);
3478 }
3479 function findColorMeetingRequirements(reference, seed, target, direction, {
3480 lightnessConstraint,
3481 taperChromaOptions
3482 } = {}) {
3483 if (target <= 1) {
3484 return {
3485 color: reference,
3486 reached: true,
3487 achieved: 1
3488 };
3489 }
3490 function getColorForL(l) {
3491 let newL = l;
3492 let newC = get(seed, [oklch_default, "c"]);
3493 if (taperChromaOptions) {
3494 const tapered = taperChroma(seed, newL, taperChromaOptions);
3495 if ("l" in tapered && "c" in tapered) {
3496 newL = tapered.l;
3497 newC = tapered.c;
3498 } else {
3499 return tapered;
3500 }
3501 }
3502 return clampToGamut({
3503 space: oklch_default,
3504 coords: [newL, newC, get(seed, [oklch_default, "h"])],
3505 alpha: seed.alpha
3506 });
3507 }
3508 const mostContrastingL = direction === "lighter" ? 1 : 0;
3509 const mostContrastingColor = direction === "lighter" ? WHITE : BLACK;
3510 const highestContrast = getContrast(reference, mostContrastingColor);
3511 if (lightnessConstraint) {
3512 const colorWithExactL = getColorForL(lightnessConstraint.value);
3513 const exactLContrast = getContrast(reference, colorWithExactL);
3514 const exactLContrastMeetsTarget = cdiff(exactLContrast, target) >= -CONTRAST_EPSILON;
3515 if (exactLContrastMeetsTarget || lightnessConstraint.type === "force") {
3516 return {
3517 color: colorWithExactL,
3518 reached: exactLContrastMeetsTarget,
3519 achieved: exactLContrast,
3520 deficit: exactLContrastMeetsTarget ? cdiff(exactLContrast, highestContrast) : cdiff(target, exactLContrast)
3521 };
3522 }
3523 }
3524 if (cdiff(highestContrast, target) <= CONTRAST_EPSILON) {
3525 return {
3526 color: mostContrastingColor,
3527 reached: cdiff(highestContrast, target) >= -CONTRAST_EPSILON,
3528 achieved: highestContrast,
3529 deficit: cdiff(target, highestContrast)
3530 };
3531 }
3532 const lowerL = get(reference, [oklch_default, "l"]);
3533 const lowerContrast = cdiff(1, target);
3534 const upperL = mostContrastingL;
3535 const upperContrast = cdiff(highestContrast, target);
3536 const bestColor = solveWithBisect(
3537 getColorForL,
3538 (c) => cdiff(getContrast(reference, c), target),
3539 lowerL,
3540 lowerContrast,
3541 upperL,
3542 upperContrast
3543 );
3544 return {
3545 color: bestColor,
3546 reached: true,
3547 achieved: target,
3548 // Negative number that specifies how much room we have.
3549 deficit: cdiff(target, highestContrast)
3550 };
3551 }
3552
3553 // packages/theme/build-module/color-ramps/lib/index.mjs
3554 function calculateRamp({
3555 seed,
3556 sortedSteps,
3557 config,
3558 mainDir,
3559 oppDir,
3560 pinLightness
3561 }) {
3562 const rampResults = {};
3563 let warnings;
3564 let maxDeficit = -Infinity;
3565 let maxDeficitDirection = "lighter";
3566 let maxDeficitStep;
3567 const calculatedColors = /* @__PURE__ */ new Map();
3568 calculatedColors.set("seed", seed);
3569 for (const stepName of sortedSteps) {
3570 let computeDirection = function(color, followDirection) {
3571 if (followDirection === "main") {
3572 return mainDir;
3573 }
3574 if (followDirection === "opposite") {
3575 return oppDir;
3576 }
3577 if (followDirection === "best") {
3578 return computeBetterFgColorDirection(
3579 color,
3580 contrast.preferLighter
3581 ).better;
3582 }
3583 return followDirection;
3584 };
3585 const {
3586 contrast,
3587 lightness: stepLightnessConstraint,
3588 taperChromaOptions,
3589 sameAsIfPossible
3590 } = config[stepName];
3591 const referenceColor = calculatedColors.get(contrast.reference);
3592 if (!referenceColor) {
3593 throw new Error(
3594 `Reference color for step ${stepName} not found: ${contrast.reference}`
3595 );
3596 }
3597 if (sameAsIfPossible) {
3598 const candidateColor = calculatedColors.get(sameAsIfPossible);
3599 if (!candidateColor) {
3600 throw new Error(
3601 `Same-as color for step ${stepName} not found: ${sameAsIfPossible}`
3602 );
3603 }
3604 const candidateContrast = getContrast(
3605 referenceColor,
3606 candidateColor
3607 );
3608 const adjustedTarget2 = adjustContrastTarget(contrast.target);
3609 if (candidateContrast >= adjustedTarget2) {
3610 calculatedColors.set(stepName, candidateColor);
3611 rampResults[stepName] = getColorString(candidateColor);
3612 continue;
3613 }
3614 }
3615 const computedDir = computeDirection(
3616 referenceColor,
3617 contrast.followDirection
3618 );
3619 const adjustedTarget = adjustContrastTarget(contrast.target);
3620 let lightnessConstraint;
3621 if (pinLightness?.stepName === stepName) {
3622 lightnessConstraint = {
3623 value: pinLightness.value,
3624 type: "force"
3625 };
3626 } else if (stepLightnessConstraint) {
3627 lightnessConstraint = {
3628 value: stepLightnessConstraint(computedDir),
3629 type: "onlyIfSucceeds"
3630 };
3631 }
3632 const searchResults = findColorMeetingRequirements(
3633 referenceColor,
3634 seed,
3635 adjustedTarget,
3636 computedDir,
3637 {
3638 lightnessConstraint,
3639 taperChromaOptions
3640 }
3641 );
3642 if (!contrast.ignoreWhenAdjustingSeed && searchResults.deficit && searchResults.deficit > maxDeficit) {
3643 maxDeficit = searchResults.deficit;
3644 maxDeficitDirection = computedDir;
3645 maxDeficitStep = stepName;
3646 }
3647 calculatedColors.set(stepName, searchResults.color);
3648 rampResults[stepName] = getColorString(searchResults.color);
3649 if (!searchResults.reached && !contrast.ignoreWhenAdjustingSeed) {
3650 warnings ??= [];
3651 warnings.push(stepName);
3652 }
3653 }
3654 return {
3655 rampResults,
3656 warnings,
3657 maxDeficit,
3658 maxDeficitDirection,
3659 maxDeficitStep
3660 };
3661 }
3662 function buildRamp(seedArg, config, {
3663 mainDirection,
3664 pinLightness,
3665 rescaleToFitContrastTargets = true
3666 } = {}) {
3667 assertValidSeedColor(seedArg);
3668 let seed;
3669 try {
3670 seed = clampToGamut(seedArg);
3671 } catch (error) {
3672 throw new Error(
3673 `Invalid seed color "${seedArg}": ${error instanceof Error ? error.message : "Unknown error"}`
3674 );
3675 }
3676 let mainDir = "lighter";
3677 let oppDir = "darker";
3678 if (mainDirection) {
3679 mainDir = mainDirection;
3680 oppDir = mainDirection === "darker" ? "lighter" : "darker";
3681 } else {
3682 const { better, worse } = computeBetterFgColorDirection(seed);
3683 mainDir = better;
3684 oppDir = worse;
3685 }
3686 const sortedSteps = sortByDependency(config);
3687 const {
3688 rampResults,
3689 warnings,
3690 maxDeficit,
3691 maxDeficitDirection,
3692 maxDeficitStep
3693 } = calculateRamp({
3694 seed,
3695 sortedSteps,
3696 config,
3697 mainDir,
3698 oppDir,
3699 pinLightness
3700 });
3701 let bestRamp = rampResults;
3702 if (maxDeficit > CONTRAST_EPSILON && rescaleToFitContrastTargets) {
3703 let getSeedForL = function(l) {
3704 return clampToGamut(set(clone(seed), [oklch_default, "l"], l));
3705 }, getDeficitForSeed = function(s) {
3706 const iterationResults = calculateRamp({
3707 seed: s,
3708 sortedSteps: iterSteps,
3709 config,
3710 mainDir,
3711 oppDir,
3712 pinLightness
3713 });
3714 return iterationResults.maxDeficitDirection === maxDeficitDirection ? iterationResults.maxDeficit : -maxDeficit;
3715 };
3716 const iterSteps = stepsForStep(maxDeficitStep, config);
3717 const lowerSeedL = maxDeficitDirection === "lighter" ? 0 : 1;
3718 const lowerDeficit = -maxDeficit;
3719 const upperSeedL = get(seed, [oklch_default, "l"]);
3720 const upperDeficit = maxDeficit;
3721 const bestSeed = solveWithBisect(
3722 getSeedForL,
3723 getDeficitForSeed,
3724 lowerSeedL,
3725 lowerDeficit,
3726 upperSeedL,
3727 upperDeficit
3728 );
3729 bestRamp = calculateRamp({
3730 seed: bestSeed,
3731 sortedSteps,
3732 config,
3733 mainDir,
3734 oppDir,
3735 pinLightness
3736 }).rampResults;
3737 }
3738 if (mainDir === "darker") {
3739 const tmpSurface1 = bestRamp.surface1;
3740 bestRamp.surface1 = bestRamp.surface3;
3741 bestRamp.surface3 = tmpSurface1;
3742 }
3743 return {
3744 ramp: bestRamp,
3745 warnings,
3746 direction: mainDir
3747 };
3748 }
3749
3750 // packages/theme/build-module/color-ramps/lib/ramp-configs.mjs
3751 var lightnessConstraintForegroundHighContrast = (direction) => direction === "lighter" ? 0.9551 : 0.235;
3752 var lightnessConstraintForegroundMediumContrast = (direction) => direction === "lighter" ? 0.77 : 0.56;
3753 var lightnessConstraintBgFill = (direction) => direction === "lighter" ? 0.67 : 0.45;
3754 var BG_SURFACE_TAPER_CHROMA = {
3755 alpha: 0.7
3756 };
3757 var FG_TAPER_CHROMA = {
3758 alpha: 0.6,
3759 kLight: 0.2,
3760 kDark: 0.2
3761 };
3762 var STROKE_TAPER_CHROMA = {
3763 alpha: 0.6,
3764 radiusDark: 0.01,
3765 radiusLight: 0.01,
3766 kLight: 0.8,
3767 kDark: 0.8
3768 };
3769 var ACCENT_SURFACE_TAPER_CHROMA = {
3770 alpha: 0.75,
3771 radiusDark: 0.01,
3772 radiusLight: 0.01
3773 };
3774 var fgSurface4Config = {
3775 contrast: {
3776 reference: "surface3",
3777 followDirection: "main",
3778 target: 7,
3779 preferLighter: true
3780 },
3781 lightness: lightnessConstraintForegroundHighContrast,
3782 taperChromaOptions: FG_TAPER_CHROMA
3783 };
3784 var BG_RAMP_CONFIG = {
3785 // Surface
3786 surface1: {
3787 contrast: {
3788 reference: "surface2",
3789 followDirection: "opposite",
3790 target: 1.06,
3791 ignoreWhenAdjustingSeed: true
3792 },
3793 taperChromaOptions: BG_SURFACE_TAPER_CHROMA
3794 },
3795 surface2: {
3796 contrast: {
3797 reference: "seed",
3798 followDirection: "main",
3799 target: 1
3800 }
3801 },
3802 surface3: {
3803 contrast: {
3804 reference: "surface2",
3805 followDirection: "main",
3806 target: 1.06
3807 },
3808 taperChromaOptions: BG_SURFACE_TAPER_CHROMA
3809 },
3810 surface4: {
3811 contrast: {
3812 reference: "surface2",
3813 followDirection: "main",
3814 target: 1.12
3815 },
3816 taperChromaOptions: BG_SURFACE_TAPER_CHROMA
3817 },
3818 surface5: {
3819 contrast: {
3820 reference: "surface2",
3821 followDirection: "main",
3822 target: 1.2
3823 },
3824 taperChromaOptions: BG_SURFACE_TAPER_CHROMA
3825 },
3826 surface6: {
3827 contrast: {
3828 reference: "surface2",
3829 followDirection: "main",
3830 target: 1.4
3831 },
3832 taperChromaOptions: BG_SURFACE_TAPER_CHROMA
3833 },
3834 // Bg fill
3835 bgFill1: {
3836 contrast: {
3837 reference: "surface2",
3838 followDirection: "main",
3839 target: 4
3840 },
3841 lightness: lightnessConstraintBgFill
3842 },
3843 bgFill2: {
3844 contrast: {
3845 reference: "bgFill1",
3846 followDirection: "main",
3847 target: 1.2
3848 }
3849 },
3850 bgFillInverted1: {
3851 contrast: {
3852 reference: "bgFillInverted2",
3853 followDirection: "opposite",
3854 target: 1.2
3855 }
3856 },
3857 bgFillInverted2: fgSurface4Config,
3858 bgFillDark: {
3859 contrast: {
3860 reference: "surface3",
3861 followDirection: "darker",
3862 // This is what causes the token to be always dark
3863 target: 7,
3864 ignoreWhenAdjustingSeed: true
3865 },
3866 lightness: lightnessConstraintForegroundHighContrast,
3867 taperChromaOptions: FG_TAPER_CHROMA
3868 },
3869 // Stroke
3870 stroke1: {
3871 contrast: {
3872 reference: "stroke3",
3873 followDirection: "opposite",
3874 target: 2.9
3875 },
3876 taperChromaOptions: STROKE_TAPER_CHROMA
3877 },
3878 stroke2: {
3879 contrast: {
3880 reference: "stroke3",
3881 followDirection: "opposite",
3882 target: 2.4
3883 },
3884 taperChromaOptions: STROKE_TAPER_CHROMA
3885 },
3886 stroke3: {
3887 contrast: {
3888 reference: "surface3",
3889 followDirection: "main",
3890 target: 3
3891 },
3892 taperChromaOptions: STROKE_TAPER_CHROMA
3893 },
3894 stroke4: {
3895 contrast: {
3896 reference: "stroke3",
3897 followDirection: "main",
3898 target: 1.5
3899 },
3900 taperChromaOptions: STROKE_TAPER_CHROMA
3901 },
3902 // fgSurface
3903 fgSurface1: {
3904 contrast: {
3905 reference: "surface3",
3906 followDirection: "main",
3907 target: 2,
3908 preferLighter: true
3909 },
3910 taperChromaOptions: FG_TAPER_CHROMA
3911 },
3912 fgSurface2: {
3913 contrast: {
3914 reference: "surface3",
3915 followDirection: "main",
3916 target: 3,
3917 preferLighter: true
3918 },
3919 taperChromaOptions: FG_TAPER_CHROMA
3920 },
3921 fgSurface3: {
3922 contrast: {
3923 reference: "surface3",
3924 followDirection: "main",
3925 target: 4.5,
3926 preferLighter: true
3927 },
3928 lightness: lightnessConstraintForegroundMediumContrast,
3929 taperChromaOptions: FG_TAPER_CHROMA
3930 },
3931 fgSurface4: fgSurface4Config,
3932 // fgFill
3933 fgFill: {
3934 contrast: {
3935 reference: "bgFill1",
3936 followDirection: "best",
3937 target: 4.5,
3938 preferLighter: true
3939 },
3940 lightness: lightnessConstraintForegroundHighContrast,
3941 taperChromaOptions: FG_TAPER_CHROMA
3942 },
3943 fgFillInverted: {
3944 contrast: {
3945 reference: "bgFillInverted1",
3946 followDirection: "best",
3947 target: 4.5,
3948 preferLighter: true
3949 },
3950 lightness: lightnessConstraintForegroundHighContrast,
3951 taperChromaOptions: FG_TAPER_CHROMA
3952 },
3953 fgFillDark: {
3954 contrast: {
3955 reference: "bgFillDark",
3956 followDirection: "best",
3957 target: 4.5,
3958 preferLighter: true
3959 },
3960 lightness: lightnessConstraintForegroundHighContrast,
3961 taperChromaOptions: FG_TAPER_CHROMA
3962 }
3963 };
3964 var ACCENT_RAMP_CONFIG = {
3965 ...BG_RAMP_CONFIG,
3966 surface1: {
3967 ...BG_RAMP_CONFIG.surface1,
3968 taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA
3969 },
3970 surface2: {
3971 contrast: {
3972 reference: "bgFill1",
3973 followDirection: "opposite",
3974 target: BG_RAMP_CONFIG.bgFill1.contrast.target,
3975 ignoreWhenAdjustingSeed: true
3976 },
3977 taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA
3978 },
3979 surface3: {
3980 ...BG_RAMP_CONFIG.surface3,
3981 taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA
3982 },
3983 surface4: {
3984 ...BG_RAMP_CONFIG.surface4,
3985 taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA
3986 },
3987 surface5: {
3988 ...BG_RAMP_CONFIG.surface5,
3989 taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA
3990 },
3991 surface6: {
3992 ...BG_RAMP_CONFIG.surface6,
3993 taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA
3994 },
3995 bgFill1: {
3996 contrast: {
3997 reference: "seed",
3998 followDirection: "main",
3999 target: 1
4000 }
4001 },
4002 stroke1: {
4003 ...BG_RAMP_CONFIG.stroke1
4004 },
4005 stroke2: {
4006 ...BG_RAMP_CONFIG.stroke2
4007 },
4008 stroke3: {
4009 ...BG_RAMP_CONFIG.stroke3,
4010 sameAsIfPossible: "fgSurface3",
4011 taperChromaOptions: void 0
4012 },
4013 stroke4: {
4014 ...BG_RAMP_CONFIG.stroke4,
4015 taperChromaOptions: void 0
4016 },
4017 // fgSurface: do not de-saturate
4018 fgSurface1: {
4019 ...BG_RAMP_CONFIG.fgSurface1,
4020 taperChromaOptions: void 0
4021 },
4022 fgSurface2: {
4023 ...BG_RAMP_CONFIG.fgSurface2,
4024 taperChromaOptions: void 0
4025 },
4026 fgSurface3: {
4027 ...BG_RAMP_CONFIG.fgSurface3,
4028 taperChromaOptions: void 0,
4029 sameAsIfPossible: "bgFill1"
4030 },
4031 fgSurface4: {
4032 ...BG_RAMP_CONFIG.fgSurface4,
4033 taperChromaOptions: void 0
4034 }
4035 };
4036
4037 // packages/theme/build-module/color-ramps/index.mjs
4038 function buildBgRamp(seed) {
4039 if (typeof seed !== "string" || seed.trim() === "") {
4040 throw new Error("Seed color must be a non-empty string");
4041 }
4042 return buildRamp(seed, BG_RAMP_CONFIG);
4043 }
4044 var STEP_TO_PIN = "surface2";
4045 function getBgRampInfo(ramp) {
4046 return {
4047 mainDirection: ramp.direction,
4048 pinLightness: {
4049 stepName: STEP_TO_PIN,
4050 value: clampAccentScaleReferenceLightness(
4051 get(ramp.ramp[STEP_TO_PIN], [oklch_default, "l"]),
4052 ramp.direction
4053 )
4054 }
4055 };
4056 }
4057 function buildAccentRamp(seed, bgRamp) {
4058 if (typeof seed !== "string" || seed.trim() === "") {
4059 throw new Error("Seed color must be a non-empty string");
4060 }
4061 const bgRampInfo = bgRamp ? getBgRampInfo(bgRamp) : void 0;
4062 return buildRamp(seed, ACCENT_RAMP_CONFIG, bgRampInfo);
4063 }
4064
4065 // packages/theme/build-module/use-theme-provider-styles.mjs
4066 var getCachedBgRamp = memize(buildBgRamp, { maxSize: 10 });
4067 var getCachedAccentRamp = memize(buildAccentRamp, { maxSize: 10 });
4068 var legacyWpComponentsOverridesCSS = [
4069 ["--wp-components-color-accent", "var(--wp-admin-theme-color)"],
4070 [
4071 "--wp-components-color-accent-darker-10",
4072 "var(--wp-admin-theme-color-darker-10)"
4073 ],
4074 [
4075 "--wp-components-color-accent-darker-20",
4076 "var(--wp-admin-theme-color-darker-20)"
4077 ],
4078 [
4079 "--wp-components-color-accent-inverted",
4080 "var(--wpds-color-foreground-interactive-brand-strong, #fff)"
4081 ],
4082 [
4083 "--wp-components-color-background",
4084 "var(--wpds-color-background-surface-neutral-strong, #fff)"
4085 ],
4086 [
4087 "--wp-components-color-foreground",
4088 "var(--wpds-color-foreground-content-neutral, #1e1e1e)"
4089 ],
4090 [
4091 "--wp-components-color-foreground-inverted",
4092 "var(--wpds-color-background-surface-neutral, #fcfcfc)"
4093 ],
4094 [
4095 "--wp-components-color-gray-100",
4096 "var(--wpds-color-background-surface-neutral, #fcfcfc)"
4097 ],
4098 [
4099 "--wp-components-color-gray-200",
4100 "var(--wpds-color-stroke-surface-neutral, #dbdbdb)"
4101 ],
4102 [
4103 "--wp-components-color-gray-300",
4104 "var(--wpds-color-stroke-surface-neutral, #dbdbdb)"
4105 ],
4106 [
4107 "--wp-components-color-gray-400",
4108 "var(--wpds-color-stroke-interactive-neutral, #8d8d8d)"
4109 ],
4110 [
4111 "--wp-components-color-gray-600",
4112 "var(--wpds-color-stroke-interactive-neutral, #8d8d8d)"
4113 ],
4114 [
4115 "--wp-components-color-gray-700",
4116 "var(--wpds-color-foreground-content-neutral-weak, #707070)"
4117 ],
4118 [
4119 "--wp-components-color-gray-800",
4120 "var(--wpds-color-foreground-content-neutral, #1e1e1e)"
4121 ]
4122 ];
4123 function customRgbFormat(color) {
4124 const rgb = to(color, srgb_default);
4125 return rgb.coords.map((n2) => Math.round((n2 ?? 0) * 255)).join(", ");
4126 }
4127 function legacyWpAdminThemeOverridesCSS(accent) {
4128 ColorSpace.register(srgb_default);
4129 const parsedAccent = to(accent, hsl_default);
4130 const parsedL = parsedAccent.coords[2] ?? 0;
4131 const darker10 = set(
4132 clone(parsedAccent),
4133 [hsl_default, "l"],
4134 Math.max(0, parsedL - 5)
4135 // L reduced by 5%
4136 );
4137 const darker20 = set(
4138 clone(parsedAccent),
4139 [hsl_default, "l"],
4140 Math.max(0, parsedL - 10)
4141 // L reduced by 10%
4142 );
4143 return [
4144 ["--wp-admin-theme-color", getColorString(parsedAccent)],
4145 ["--wp-admin-theme-color--rgb", customRgbFormat(parsedAccent)],
4146 ["--wp-admin-theme-color-darker-10", getColorString(darker10)],
4147 [
4148 "--wp-admin-theme-color-darker-10--rgb",
4149 customRgbFormat(darker10)
4150 ],
4151 ["--wp-admin-theme-color-darker-20", getColorString(darker20)],
4152 [
4153 "--wp-admin-theme-color-darker-20--rgb",
4154 customRgbFormat(darker20)
4155 ]
4156 ];
4157 }
4158 function colorTokensCSS(computedColorRamps) {
4159 const entries = [];
4160 for (const [rampName, { ramp }] of computedColorRamps) {
4161 for (const [tokenName, tokenValue] of Object.entries(ramp)) {
4162 const key = `${rampName}-${tokenName}`;
4163 const aliasedBy = color_tokens_default[key] ?? [];
4164 for (const aliasedId of aliasedBy) {
4165 entries.push([`--wpds-color-${aliasedId}`, tokenValue]);
4166 }
4167 }
4168 }
4169 return entries;
4170 }
4171 function generateStyles({
4172 primary,
4173 computedColorRamps
4174 }) {
4175 return Object.fromEntries(
4176 [
4177 // Semantic color tokens
4178 colorTokensCSS(computedColorRamps),
4179 // Legacy overrides
4180 legacyWpAdminThemeOverridesCSS(primary),
4181 legacyWpComponentsOverridesCSS
4182 ].flat()
4183 );
4184 }
4185 function useThemeProviderStyles({
4186 color = {},
4187 cursor,
4188 cornerRadius
4189 } = {}) {
4190 const { resolvedSettings: inheritedSettings } = (0, import_element2.useContext)(ThemeContext);
4191 const primary = color.primary ?? inheritedSettings.color?.primary ?? DEFAULT_SEED_COLORS.primary;
4192 const background = color.background ?? inheritedSettings.color?.background ?? DEFAULT_SEED_COLORS.background;
4193 const cursorControl = cursor?.control ?? inheritedSettings.cursor?.control;
4194 const cornerRadiusPreset = cornerRadius ?? inheritedSettings.cornerRadius ?? "subtle";
4195 const resolvedSettings = (0, import_element2.useMemo)(
4196 () => ({
4197 color: {
4198 primary,
4199 background
4200 },
4201 cursor: cursorControl ? { control: cursorControl } : void 0,
4202 cornerRadius: cornerRadiusPreset
4203 }),
4204 [primary, background, cursorControl, cornerRadiusPreset]
4205 );
4206 const colorStyles = (0, import_element2.useMemo)(() => {
4207 const seeds = {
4208 ...DEFAULT_SEED_COLORS,
4209 background,
4210 primary
4211 };
4212 const computedColorRamps = /* @__PURE__ */ new Map();
4213 const bgRamp = getCachedBgRamp(seeds.background);
4214 Object.entries(seeds).forEach(([rampName, seed]) => {
4215 if (rampName === "background") {
4216 computedColorRamps.set("bg", bgRamp);
4217 } else {
4218 computedColorRamps.set(
4219 rampName,
4220 getCachedAccentRamp(seed, bgRamp)
4221 );
4222 }
4223 });
4224 return generateStyles({
4225 primary: seeds.primary,
4226 computedColorRamps
4227 });
4228 }, [primary, background]);
4229 const themeProviderStyles = (0, import_element2.useMemo)(
4230 () => ({
4231 ...colorStyles,
4232 ...cursorControl && {
4233 "--wpds-cursor-control": cursorControl
4234 }
4235 }),
4236 [colorStyles, cursorControl]
4237 );
4238 return {
4239 resolvedSettings,
4240 themeProviderStyles
4241 };
4242 }
4243
4244 // packages/theme/build-module/theme-provider.mjs
4245 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
4246 var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
4247 function getRuntime() {
4248 const globalScope = globalThis;
4249 if (globalScope.__wpStyleRuntime) {
4250 return globalScope.__wpStyleRuntime;
4251 }
4252 globalScope.__wpStyleRuntime = {
4253 documents: /* @__PURE__ */ new Map(),
4254 styles: /* @__PURE__ */ new Map(),
4255 injectedStyles: /* @__PURE__ */ new WeakMap()
4256 };
4257 if (typeof document !== "undefined") {
4258 registerDocument(document);
4259 }
4260 return globalScope.__wpStyleRuntime;
4261 }
4262 function documentContainsStyleHash(targetDocument, hash) {
4263 if (!targetDocument.head) {
4264 return false;
4265 }
4266 for (const style of targetDocument.head.querySelectorAll(
4267 `style[${STYLE_HASH_ATTRIBUTE}]`
4268 )) {
4269 if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
4270 return true;
4271 }
4272 }
4273 return false;
4274 }
4275 function injectStyle(targetDocument, hash, css) {
4276 if (!targetDocument.head) {
4277 return;
4278 }
4279 const runtime = getRuntime();
4280 let injectedStyles = runtime.injectedStyles.get(targetDocument);
4281 if (!injectedStyles) {
4282 injectedStyles = /* @__PURE__ */ new Set();
4283 runtime.injectedStyles.set(targetDocument, injectedStyles);
4284 }
4285 if (injectedStyles.has(hash)) {
4286 return;
4287 }
4288 if (documentContainsStyleHash(targetDocument, hash)) {
4289 injectedStyles.add(hash);
4290 return;
4291 }
4292 const style = targetDocument.createElement("style");
4293 style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
4294 style.appendChild(targetDocument.createTextNode(css));
4295 targetDocument.head.appendChild(style);
4296 injectedStyles.add(hash);
4297 }
4298 function registerDocument(targetDocument) {
4299 const runtime = getRuntime();
4300 runtime.documents.set(
4301 targetDocument,
4302 (runtime.documents.get(targetDocument) ?? 0) + 1
4303 );
4304 for (const [hash, css] of runtime.styles) {
4305 injectStyle(targetDocument, hash, css);
4306 }
4307 return () => {
4308 const count = runtime.documents.get(targetDocument);
4309 if (count === void 0) {
4310 return;
4311 }
4312 if (count <= 1) {
4313 runtime.documents.delete(targetDocument);
4314 return;
4315 }
4316 runtime.documents.set(targetDocument, count - 1);
4317 };
4318 }
4319 function registerStyle(hash, css) {
4320 const runtime = getRuntime();
4321 runtime.styles.set(hash, css);
4322 for (const targetDocument of runtime.documents.keys()) {
4323 injectStyle(targetDocument, hash, css);
4324 }
4325 }
4326 if (typeof process === "undefined" || true) {
4327 registerStyle("f4e6e06c6a", ".dba930ea7a9438fd__root{display:contents}");
4328 }
4329 var style_default = { "root": "dba930ea7a9438fd__root" };
4330 var rootProviderCountByDocument = /* @__PURE__ */ new WeakMap();
4331 var ThemeProvider = ({
4332 children,
4333 color = {},
4334 cursor,
4335 cornerRadius,
4336 isRoot = false
4337 }) => {
4338 const { themeProviderStyles, resolvedSettings } = useThemeProviderStyles({
4339 color,
4340 cursor,
4341 cornerRadius
4342 });
4343 const cornerRadiusPreset = resolvedSettings.cornerRadius ?? "subtle";
4344 const contextValue = (0, import_element3.useMemo)(
4345 () => ({
4346 resolvedSettings
4347 }),
4348 [resolvedSettings]
4349 );
4350 const wrapperRef = (0, import_element3.useRef)(null);
4351 (0, import_compose.useIsomorphicLayoutEffect)(() => {
4352 if (!isRoot) {
4353 return;
4354 }
4355 const doc = wrapperRef.current?.ownerDocument;
4356 if (!doc) {
4357 return;
4358 }
4359 const root = doc.documentElement;
4360 if (true) {
4361 const active = rootProviderCountByDocument.get(doc) ?? 0;
4362 if (active > 0) {
4363 console.warn(
4364 "ThemeProvider: More than one root provider (`isRoot`) is mounted on the same document. Their forwarded document-level styles conflict, and unmounting one can reset the others. Render a single root provider per document."
4365 );
4366 }
4367 rootProviderCountByDocument.set(doc, active + 1);
4368 }
4369 const previous = /* @__PURE__ */ new Map();
4370 const applied = [];
4371 for (const [rawKey, rawValue] of Object.entries(
4372 themeProviderStyles
4373 )) {
4374 if (!rawKey.startsWith("--") || rawValue === null || rawValue === void 0) {
4375 continue;
4376 }
4377 previous.set(rawKey, root.style.getPropertyValue(rawKey));
4378 root.style.setProperty(rawKey, String(rawValue));
4379 applied.push(rawKey);
4380 }
4381 return () => {
4382 if (true) {
4383 const active = rootProviderCountByDocument.get(doc) ?? 1;
4384 if (active <= 1) {
4385 rootProviderCountByDocument.delete(doc);
4386 } else {
4387 rootProviderCountByDocument.set(doc, active - 1);
4388 }
4389 }
4390 for (const key of applied) {
4391 const prev = previous.get(key);
4392 if (prev) {
4393 root.style.setProperty(key, prev);
4394 } else {
4395 root.style.removeProperty(key);
4396 }
4397 }
4398 };
4399 }, [isRoot, themeProviderStyles]);
4400 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
4401 "div",
4402 {
4403 ref: wrapperRef,
4404 "data-wpds-root-provider": isRoot || void 0,
4405 "data-wpds-corner-radius": cornerRadiusPreset,
4406 className: style_default.root,
4407 style: themeProviderStyles,
4408 children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeContext.Provider, { value: contextValue, children })
4409 }
4410 );
4411 };
4412
4413 // packages/theme/build-module/private-apis.mjs
4414 function warnPrivateApi(apiName, options = {}) {
4415 (0, import_deprecated.default)(`\`privateApis.${apiName}\` from \`@wordpress/theme\``, {
4416 since: "7.1",
4417 version: "7.3",
4418 ...options
4419 });
4420 }
4421 var privateApis = {};
4422 lock(privateApis, {
4423 get ThemeProvider() {
4424 warnPrivateApi("ThemeProvider", {
4425 alternative: "`ThemeProvider` from `@wordpress/theme`"
4426 });
4427 return ThemeProvider;
4428 },
4429 get useThemeProviderStyles() {
4430 warnPrivateApi("useThemeProviderStyles", {
4431 alternative: "`ThemeProvider` from `@wordpress/theme` for supported theming use cases",
4432 hint: "`useThemeProviderStyles` has no public replacement."
4433 });
4434 return useThemeProviderStyles;
4435 }
4436 });
4437 return __toCommonJS(index_exports);
4438 })();
4439 //# sourceMappingURL=index.js.map
4440