PluginProbe
Gutenberg / 23.4.0
Gutenberg v23.4.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 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / theme / index.js

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

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