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

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

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