PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 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 All 404 releases
gutenberg / build / scripts / theme / index.js

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

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