PluginProbe
Gutenberg / 22.4.4
Gutenberg v22.4.4
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 22.4.4, at build/scripts/theme/index.js

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