@fluixi/utils 1.0.0-alpha.82 → 1.0.0-alpha.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/index.cjs +2858 -1
  2. package/dist/index.mjs +2838 -1
  3. package/dist/lib/array/advanced.cjs +2227 -1
  4. package/dist/lib/array/advanced.mjs +2204 -1
  5. package/dist/lib/array/array.cjs +57 -1
  6. package/dist/lib/array/array.mjs +36 -1
  7. package/dist/lib/array/index.cjs +2344 -1
  8. package/dist/lib/array/index.mjs +2322 -1
  9. package/dist/lib/array/utils.cjs +103 -1
  10. package/dist/lib/array/utils.mjs +82 -1
  11. package/dist/lib/color/color.cjs +2190 -1
  12. package/dist/lib/color/color.mjs +2167 -1
  13. package/dist/lib/color/constants.cjs +380 -1
  14. package/dist/lib/color/constants.mjs +359 -1
  15. package/dist/lib/color/conversions.cjs +629 -1
  16. package/dist/lib/color/conversions.mjs +608 -1
  17. package/dist/lib/color/helpers.cjs +2534 -1
  18. package/dist/lib/color/helpers.mjs +2511 -1
  19. package/dist/lib/color/index.cjs +2641 -1
  20. package/dist/lib/color/index.mjs +2619 -1
  21. package/dist/lib/color/types.cjs +18 -1
  22. package/dist/lib/color/utils.cjs +962 -1
  23. package/dist/lib/color/utils.mjs +939 -1
  24. package/dist/lib/compare/comparators.cjs +171 -1
  25. package/dist/lib/compare/comparators.mjs +150 -1
  26. package/dist/lib/compare/index.cjs +172 -1
  27. package/dist/lib/compare/index.mjs +152 -1
  28. package/dist/lib/crypto/hash.cjs +83 -1
  29. package/dist/lib/crypto/hash.mjs +62 -1
  30. package/dist/lib/crypto/index.cjs +85 -1
  31. package/dist/lib/crypto/index.mjs +62 -1
  32. package/dist/lib/dom/events.cjs +40 -1
  33. package/dist/lib/dom/events.mjs +19 -1
  34. package/dist/lib/dom/index.cjs +78 -1
  35. package/dist/lib/dom/index.mjs +56 -1
  36. package/dist/lib/dom/utils.cjs +57 -1
  37. package/dist/lib/dom/utils.mjs +36 -1
  38. package/dist/lib/functions/functions.cjs +366 -1
  39. package/dist/lib/functions/functions.mjs +345 -1
  40. package/dist/lib/functions/index.cjs +369 -1
  41. package/dist/lib/functions/index.mjs +347 -1
  42. package/dist/lib/functions/types.cjs +18 -1
  43. package/dist/lib/helpers.cjs +78 -1
  44. package/dist/lib/helpers.mjs +59 -1
  45. package/dist/lib/index.cjs +2857 -1
  46. package/dist/lib/index.mjs +2836 -1
  47. package/dist/lib/maths/constants.cjs +70 -1
  48. package/dist/lib/maths/constants.mjs +50 -1
  49. package/dist/lib/maths/fn/advanced.cjs +231 -1
  50. package/dist/lib/maths/fn/advanced.mjs +208 -1
  51. package/dist/lib/maths/fn/basic.cjs +212 -1
  52. package/dist/lib/maths/fn/basic.mjs +191 -1
  53. package/dist/lib/maths/fn/complex.cjs +268 -1
  54. package/dist/lib/maths/fn/complex.mjs +247 -1
  55. package/dist/lib/maths/fn/index.cjs +877 -1
  56. package/dist/lib/maths/fn/index.mjs +855 -1
  57. package/dist/lib/maths/fn/trigo.cjs +179 -1
  58. package/dist/lib/maths/fn/trigo.mjs +156 -1
  59. package/dist/lib/maths/fn/vector.cjs +728 -1
  60. package/dist/lib/maths/fn/vector.mjs +707 -1
  61. package/dist/lib/maths/formatter.cjs +61 -1
  62. package/dist/lib/maths/formatter.mjs +40 -1
  63. package/dist/lib/maths/guards.cjs +164 -1
  64. package/dist/lib/maths/guards.mjs +144 -1
  65. package/dist/lib/maths/index.cjs +1152 -1
  66. package/dist/lib/maths/index.mjs +1130 -1
  67. package/dist/lib/maths/parser.cjs +75 -1
  68. package/dist/lib/maths/parser.mjs +54 -1
  69. package/dist/lib/maths/random.cjs +49 -1
  70. package/dist/lib/maths/random.mjs +28 -1
  71. package/dist/lib/maths/types/advanced.cjs +18 -1
  72. package/dist/lib/maths/types/basic.cjs +18 -1
  73. package/dist/lib/maths/types/index.cjs +19 -1
  74. package/dist/lib/maths/types/index.mjs +1 -0
  75. package/dist/lib/maths/types/negative.cjs +18 -1
  76. package/dist/lib/maths/types/operations.cjs +18 -1
  77. package/dist/lib/object/clone.cjs +88 -1
  78. package/dist/lib/object/clone.mjs +65 -1
  79. package/dist/lib/object/diff.cjs +573 -1
  80. package/dist/lib/object/diff.mjs +550 -1
  81. package/dist/lib/object/getter-setter.cjs +2351 -1
  82. package/dist/lib/object/getter-setter.mjs +2330 -1
  83. package/dist/lib/object/index.cjs +3956 -6
  84. package/dist/lib/object/index.mjs +3936 -6
  85. package/dist/lib/object/merge.cjs +1029 -1
  86. package/dist/lib/object/merge.mjs +1006 -1
  87. package/dist/lib/object/object.cjs +280 -1
  88. package/dist/lib/object/object.mjs +257 -1
  89. package/dist/lib/object/omit.cjs +2022 -1
  90. package/dist/lib/object/omit.mjs +1999 -1
  91. package/dist/lib/object/reconcile.cjs +126 -1
  92. package/dist/lib/object/reconcile.mjs +105 -1
  93. package/dist/lib/object/selector.cjs +303 -1
  94. package/dist/lib/object/selector.mjs +282 -1
  95. package/dist/lib/object/sort.cjs +209 -1
  96. package/dist/lib/object/sort.mjs +186 -1
  97. package/dist/lib/object/transform.cjs +2211 -1
  98. package/dist/lib/object/transform.mjs +2190 -1
  99. package/dist/lib/object/types.cjs +18 -1
  100. package/dist/lib/object/utils.cjs +326 -6
  101. package/dist/lib/object/utils.mjs +305 -6
  102. package/dist/lib/primitive/boolean/boolean.cjs +407 -1
  103. package/dist/lib/primitive/boolean/boolean.mjs +386 -1
  104. package/dist/lib/primitive/boolean/index.cjs +382 -1
  105. package/dist/lib/primitive/boolean/index.mjs +359 -1
  106. package/dist/lib/primitive/boolean/types.cjs +18 -1
  107. package/dist/lib/primitive/date/date.cjs +1126 -1
  108. package/dist/lib/primitive/date/date.mjs +1105 -1
  109. package/dist/lib/primitive/date/index.cjs +1128 -1
  110. package/dist/lib/primitive/date/index.mjs +1105 -1
  111. package/dist/lib/primitive/date/types.cjs +18 -1
  112. package/dist/lib/primitive/index.cjs +2338 -5
  113. package/dist/lib/primitive/index.mjs +2316 -5
  114. package/dist/lib/primitive/string/index.cjs +875 -5
  115. package/dist/lib/primitive/string/index.mjs +852 -5
  116. package/dist/lib/primitive/string/parser-2.cjs +543 -8
  117. package/dist/lib/primitive/string/parser-2.mjs +522 -8
  118. package/dist/lib/primitive/string/parser.cjs +236 -3
  119. package/dist/lib/primitive/string/parser.mjs +215 -3
  120. package/dist/lib/primitive/string/string.cjs +926 -5
  121. package/dist/lib/primitive/string/string.mjs +903 -5
  122. package/dist/lib/primitive/string/types.cjs +18 -1
  123. package/dist/lib/primitive/types.cjs +18 -1
  124. package/dist/lib/url/index.cjs +327 -1
  125. package/dist/lib/url/index.mjs +304 -1
  126. package/dist/lib/url/parser.cjs +325 -1
  127. package/dist/lib/url/parser.mjs +304 -1
  128. package/dist/lib/url/types.cjs +18 -1
  129. package/package.json +5 -5
@@ -1 +1,2619 @@
1
- var D={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",transparent:"transparent",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32",zinc:"#71717a",stone:"#78716c",neutral:"#737373",slate:"#64748b",gray50:"#f9fafb",gray100:"#f3f4f6",gray200:"#e5e7eb",gray300:"#d1d5db",gray400:"#9ca3af",gray500:"#6b7280",gray600:"#4b5563",gray700:"#374151",gray800:"#1f2937",gray900:"#111827",gray950:"#030712",red50:"#fef2f2",red100:"#fee2e2",red200:"#fecaca",red300:"#fca5a5",red400:"#f87171",red500:"#ef4444",red600:"#dc2626",red700:"#b91c1c",red800:"#991b1b",red900:"#7f1d1d",red950:"#450a0a",orange50:"#fff7ed",orange100:"#ffedd5",orange200:"#fed7aa",orange300:"#fdba74",orange400:"#fb923c",orange500:"#f97316",orange600:"#ea580c",orange700:"#c2410c",orange800:"#9a3412",orange900:"#7c2d12",orange950:"#431407",amber50:"#fffbeb",amber100:"#fef3c7",amber200:"#fde68a",amber300:"#fcd34d",amber400:"#fbbf24",amber500:"#f59e0b",amber600:"#d97706",amber700:"#b45309",amber800:"#92400e",amber900:"#78350f",amber950:"#451a03",yellow50:"#fefce8",yellow100:"#fef9c3",yellow200:"#fef08a",yellow300:"#fde047",yellow400:"#facc15",yellow500:"#eab308",yellow600:"#ca8a04",yellow700:"#a16207",yellow800:"#854d0e",yellow900:"#713f12",yellow950:"#422006",lime50:"#f7fee7",lime100:"#ecfccb",lime200:"#d9f99d",lime300:"#bef264",lime400:"#a3e635",lime500:"#84cc16",lime600:"#65a30d",lime700:"#4d7c0f",lime800:"#3f6212",lime900:"#365314",lime950:"#1a2e05",green50:"#f0fdf4",green100:"#dcfce7",green200:"#bbf7d0",green300:"#86efac",green400:"#4ade80",green500:"#22c55e",green600:"#16a34a",green700:"#15803d",green800:"#166534",green900:"#14532d",green950:"#052e16",emerald50:"#ecfdf5",emerald100:"#d1fae5",emerald200:"#a7f3d0",emerald300:"#6ee7b7",emerald400:"#34d399",emerald500:"#10b981",emerald600:"#059669",emerald700:"#047857",emerald800:"#065f46",emerald900:"#064e3b",emerald950:"#022c22",teal50:"#f0fdfa",teal100:"#ccfbf1",teal200:"#99f6e4",teal300:"#5eead4",teal400:"#2dd4bf",teal500:"#14b8a6",teal600:"#0d9488",teal700:"#0f766e",teal800:"#115e59",teal900:"#134e4a",teal950:"#042f2e",cyan50:"#ecfeff",cyan100:"#cffafe",cyan200:"#a5f3fc",cyan300:"#67e8f9",cyan400:"#22d3ee",cyan500:"#06b6d4",cyan600:"#0891b2",cyan700:"#0e7490",cyan800:"#155e75",cyan900:"#164e63",cyan950:"#083344",sky50:"#f0f9ff",sky100:"#e0f2fe",sky200:"#bae6fd",sky300:"#7dd3fc",sky400:"#38bdf8",sky500:"#0ea5e9",sky600:"#0284c7",sky700:"#0369a1",sky800:"#075985",sky900:"#0c4a6e",sky950:"#082f49",blue50:"#eff6ff",blue100:"#dbeafe",blue200:"#bfdbfe",blue300:"#93c5fd",blue400:"#60a5fa",blue500:"#3b82f6",blue600:"#2563eb",blue700:"#1d4ed8",blue800:"#1e40af",blue900:"#1e3a8a",blue950:"#172554",indigo50:"#eef2ff",indigo100:"#e0e7ff",indigo200:"#c7d2fe",indigo300:"#a5b4fc",indigo400:"#818cf8",indigo500:"#6366f1",indigo600:"#4f46e5",indigo700:"#4338ca",indigo800:"#3730a3",indigo900:"#312e81",indigo950:"#1e1b4b",violet50:"#f5f3ff",violet100:"#ede9fe",violet200:"#ddd6fe",violet300:"#c4b5fd",violet400:"#a78bfa",violet500:"#8b5cf6",violet600:"#7c3aed",violet700:"#6d28d9",violet800:"#5b21b6",violet900:"#4c1d95",violet950:"#2e1065",purple50:"#faf5ff",purple100:"#f3e8ff",purple200:"#e9d5ff",purple300:"#d8b4fe",purple400:"#c084fc",purple500:"#a855f7",purple600:"#9333ea",purple700:"#7e22ce",purple800:"#6b21a8",purple900:"#581c87",purple950:"#3b0764",fuchsia50:"#fdf4ff",fuchsia100:"#fae8ff",fuchsia200:"#f5d0fe",fuchsia300:"#f0abfc",fuchsia400:"#e879f9",fuchsia500:"#d946ef",fuchsia600:"#c026d3",fuchsia700:"#a21caf",fuchsia800:"#86198f",fuchsia900:"#701a75",fuchsia950:"#4a044e",pink50:"#fdf2f8",pink100:"#fce7f3",pink200:"#fbcfe8",pink300:"#f9a8d4",pink400:"#f472b6",pink500:"#ec4899",pink600:"#db2777",pink700:"#be185d",pink800:"#9d174d",pink900:"#831843",pink950:"#500724",rose50:"#fff1f2",rose100:"#ffe4e6",rose200:"#fecdd3",rose300:"#fda4af",rose400:"#fb7185",rose500:"#f43f5e",rose600:"#e11d48",rose700:"#be123c",rose800:"#9f1239",rose900:"#881337",rose950:"#4c0519"};var V={LEGACY_RGB:/^rgb\(\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*\)$/i,MODERN_RGB:/^rgb\(\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s+(\d{1,3}|\.\d+|\d+\.\d+%?)\s+(\d{1,3}|\.\d+|\d+\.\d+%?)\s*\)$/i,LEGACY_RGBA:/^rgba\(\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(0|1|0?\.\d+|\d{1,3}%?|\.\d+%?)\s*\)$/i,MODERN_RGBA:/^rgba?\(\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s+(\d{1,3}|\.\d+|\d+\.\d+%?)\s+(\d{1,3}|\.\d+|\d+\.\d+%?)\s*\/\s*(0|1|0?\.\d+|\d{1,3}%?|\.\d+%?)\s*\)$/i,COMPREHENSIVE:/^rgba?\(\s*((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\)))\s*(?:[,\s]\s*((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\))))?\s*(?:[,\s]\s*((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\))))?\s*(?:(?:\s*[,\s]?\s*\/?\s*|\s*\/\s*)((?:0|1|0?\.\d+|\.\d+|\d{1,3}%?|var\([^)]+\))))?\s*\)$/i,STRICT_RGB:/^rgb\(\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*\)$/i,STRICT_RGBA:/^rgba\(\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:0|1|0?\.\d+|\.\d+|\d{1,2}(?:\.\d+)?%|100%|var\([^)]+\)))\s*\)$/i,MODERN_RGB_ALPHA:/^rgba?\(\s*((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\)))\s+((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\)))\s+((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\)))\s*(?:\/\s*((?:0|1|0?\.\d+|\.\d+|\d{1,3}%?|var\([^)]+\))))?\s*\)$/i},G=t=>{let e=t.trim().toLowerCase();if(!e||e.includes("var("))return null;let r=l=>{if(!l)return null;let b=l.trim();if(!b||b.includes("var("))return null;if(b.endsWith("%")){let u=parseFloat(b);if(isNaN(u))return null;let h=Math.max(0,Math.min(100,u));return Math.round(h*255/100)}let c=parseFloat(b);return isNaN(c)?null:Math.round(Math.max(0,Math.min(255,c)))},n=l=>{if(!l)return 1;let b=l.trim();if(!b||b.includes("var("))return 1;if(b.endsWith("%")){let u=parseFloat(b);return isNaN(u)?1:Math.max(0,Math.min(100,u))/100}let c=parseFloat(b);return isNaN(c)?1:Math.max(0,Math.min(1,c))},a=/^rgba?\(\s*([^,]+)\s*,\s*([^,]+)\s*,\s*([^,]+)\s*(?:,\s*([^\)]+))?\s*\)$/,o=e.match(a);if(o){let l=r(o[1]),b=r(o[2]),c=r(o[3]),u=n(o[4]);if(l!==null&&b!==null&&c!==null)return[l,b,c,u]}let i=/^rgba?\(\s*([^\s\/]+)\s+([^\s\/]+)\s+([^\s\/]+)\s*(?:\/\s*([^\)]+))?\s*\)$/;if(o=e.match(i),o){let l=r(o[1]),b=r(o[2]),c=r(o[3]),u=n(o[4]);if(l!==null&&b!==null&&c!==null)return[l,b,c,u]}let s=/^rgb\(\s*([^\s,]+)\s+([^\s,]+)\s+([^\s,]+)\s*\)$/;if(o=e.match(s),o){let l=r(o[1]),b=r(o[2]),c=r(o[3]);if(l!==null&&b!==null&&c!==null)return[l,b,c,1]}return null},J={HEX:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/,RGB:V.COMPREHENSIVE,HSL:/^hsla?\(\s*(\d+(?:\.\d+)?)(?:deg|rad|grad|turn)?\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,OKLCH:/^oklch\(\s*(\d+(?:\.\d+)?%?)\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)(?:\s+[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,OKLAB:/^oklab\(\s*(\d+(?:\.\d+)?%?)\s+([+-]?\d+(?:\.\d+)?)\s+([+-]?\d+(?:\.\d+)?)(?:\s+[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,HSV:/^hsv\(\s*(\d+(?:\.\d+)?)(?:deg|rad|grad|turn)?\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,CMYK:/^cmyk\(\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,COLOR_FUNCTION:/^color\(\s*([a-z]+)\s+((?:\d+(?:\.\d+)?%?\s+)*\d+(?:\.\d+)?%?)(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,LAB:/^lab\(\s*(\d+(?:\.\d+)?%?)\s+([+-]?\d+(?:\.\d+)?)\s+([+-]?\d+(?:\.\d+)?)(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,LCH:/^lch\(\s*(\d+(?:\.\d+)?%?)\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i};var C=t=>{if(!t||typeof t!="string")return null;let e=t.trim().toLowerCase();if(!e)return null;if(e==="transparent")return[0,0,0,0];let r=e;if(D[r])return C(D[r]);let n=G(e);if(n)return n;let a=e.match(J.HEX);if(a){let s=a[1];(s.length===3||s.length===4)&&(s=s.split("").map(h=>h+h).join(""));let l=parseInt(s.substring(0,2),16),b=parseInt(s.substring(2,4),16),c=parseInt(s.substring(4,6),16),u=s.length===8?parseInt(s.substring(6,8),16)/255:1;if(!isNaN(l)&&!isNaN(b)&&!isNaN(c)&&!isNaN(u))return[l,b,c,u]}let o=e.match(J.HSL);if(o){let s=parseFloat(o[1]),l=parseFloat(o[2])/100,b=parseFloat(o[3])/100,c=o[4]?z(o[4]):1;if(!isNaN(s)&&!isNaN(l)&&!isNaN(b)&&!isNaN(c))return mt(s,l,b,c)}let i=e.match(J.OKLCH);if(i){let s=z(i[1]),l=parseFloat(i[2]),b=parseFloat(i[3]),c=i[4]?z(i[4]):1;if(!isNaN(s)&&!isNaN(l)&&!isNaN(b)&&!isNaN(c))return yt(s,l,b,c)}return null},mt=(t,e,r,n=1)=>{t=t%360,t<0&&(t+=360);let a=(1-Math.abs(2*r-1))*e,o=a*(1-Math.abs(t/60%2-1)),i=r-a/2,s=0,l=0,b=0;return t>=0&&t<60?[s,l,b]=[a,o,0]:t>=60&&t<120?[s,l,b]=[o,a,0]:t>=120&&t<180?[s,l,b]=[0,a,o]:t>=180&&t<240?[s,l,b]=[0,o,a]:t>=240&&t<300?[s,l,b]=[o,0,a]:t>=300&&t<360&&([s,l,b]=[a,0,o]),[Math.round((s+i)*255),Math.round((l+i)*255),Math.round((b+i)*255),n]},yt=(t,e,r,n=1)=>{let a=r%360,o=Math.min(100,e*100),i=t*100;return mt(a,o/100,i/100,n)},Q=(t,e,r,n=1)=>(s=>typeof s=="string"&&s.includes("var("))(n)||typeof n=="number"&&n!==1?`rgba(${t} ${e} ${r} / ${n})`:`rgb(${t} ${e} ${r})`,U=t=>{let e=Math.round(t).toString(16);return e.length===1?`0${e}`:e},z=t=>t.endsWith("%")?parseFloat(t)/100:parseFloat(t),tt=t=>{if(t.toLowerCase()in D)return!0;if(t.toLowerCase().trim().startsWith("rgb"))return G(t)!==null;let{RGB:e,...r}=J;return Object.values(r).some(n=>n.test(t))},E=(t,e,r,n=1)=>{let a=`#${U(t)}${U(e)}${U(r)}`;return n<1?`${a}${U(Math.round(n*255))}`:a},L=(t,e,r,n=1)=>{let a=t/255,o=e/255,i=r/255,s=Math.max(a,o,i),l=Math.min(a,o,i),b=0,c=0,u=(s+l)/2;if(s!==l){let d=s-l;switch(c=u>.5?d/(2-s-l):d/(s+l),s){case a:b=(o-i)/d+(o<i?6:0);break;case o:b=(i-a)/d+2;break;case i:b=(a-o)/d+4;break}b/=6}b=Math.round(b*360),c=Math.round(c*100);let h=Math.round(u*100);return n===1?`hsl(${b}, ${c}%, ${h}%)`:`hsla(${b}, ${c}%, ${h}%, ${n})`},ot=(t,e,r,n=1)=>{let a=t/255,o=e/255,i=r/255,s=Math.max(a,o,i),l=Math.min(a,o,i),b=s-l,c=0;if(b!==0){switch(s){case a:c=(o-i)/b+(o<i?6:0);break;case o:c=(i-a)/b+2;break;case i:c=(a-o)/b+4;break}c/=6}let u=s===0?0:b/s,h=s;c=Math.round(c*360);let d=Math.round(u*100),g=Math.round(h*100);return n===1?`hsv(${c}, ${d}%, ${g}%)`:`hsva(${c}, ${d}%, ${g}%, ${n})`},st=(t,e,r,n=1)=>{if(t===0&&e===0&&r===0)return"cmyk(0%, 0%, 0%, 100%)";let a=t/255,o=e/255,i=r/255,s=1-Math.max(a,o,i),l=(1-a-s)/(1-s),b=(1-o-s)/(1-s),c=(1-i-s)/(1-s),u=Math.round(l*100),h=Math.round(b*100),d=Math.round(c*100),g=Math.round(s*100);return`cmyk(${u}%, ${h}%, ${d}%, ${g}%)`},v=(t,e,r)=>{let[n,a,o]=[t,e,r].map(i=>(i=i/255,i<=.03928?i/12.92:Math.pow((i+.055)/1.055,2.4)));return .2126*n+.7152*a+.0722*o},at=(t,e)=>{let r=C(t),n=C(e);if(!r||!n)return 1;let a=v(r[0],r[1],r[2]),o=v(n[0],n[1],n[2]),i=Math.max(a,o),s=Math.min(a,o);return(i+.05)/(s+.05)},et=(t,e)=>{let r=C(t);if(!r)return t;let[n,a,o,i]=r;e.alpha!==void 0&&(i=Math.max(0,Math.min(1,e.alpha)));let s=0,l=0,b=0;if(e.lightness!==void 0||e.saturation!==void 0||e.hue!==void 0){let c=n/255,u=a/255,h=o/255,d=Math.max(c,u,h),g=Math.min(c,u,h);if(b=(d+g)/2,d!==g){let B=d-g;switch(l=b>.5?B/(2-d-g):B/(d+g),d){case c:s=(u-h)/B+(u<h?6:0);break;case u:s=(h-c)/B+2;break;case h:s=(c-u)/B+4;break}s/=6}s*=360,l*=100,b*=100,e.hue!==void 0&&(s=(s+e.hue)%360,s<0&&(s+=360)),e.saturation!==void 0&&(l=Math.max(0,Math.min(100,l+e.saturation))),e.lightness!==void 0&&(b=Math.max(0,Math.min(100,b+e.lightness)));let m=s/360,j=l/100,O=b/100,p=(1-Math.abs(2*O-1))*j,H=p*(1-Math.abs(m*6%2-1)),y=O-p/2,M=0,w=0,R=0;m<1/6?[M,w,R]=[p,H,0]:m<2/6?[M,w,R]=[H,p,0]:m<3/6?[M,w,R]=[0,p,H]:m<4/6?[M,w,R]=[0,H,p]:m<5/6?[M,w,R]=[H,0,p]:[M,w,R]=[p,0,H],n=Math.round((M+y)*255),a=Math.round((w+y)*255),o=Math.round((R+y)*255)}if(e.contrast!==void 0){let c=e.contrast/100*2.55,u=(n+a+o)/3;n=Math.round(u+(n-u)*(1+c)),a=Math.round(u+(a-u)*(1+c)),o=Math.round(u+(o-u)*(1+c)),n=Math.max(0,Math.min(255,n)),a=Math.max(0,Math.min(255,a)),o=Math.max(0,Math.min(255,o))}return E(n,a,o,i)},it=t=>{let{color:e,with:r="transparent",percentage:n=50,colorSpace:a="srgb"}=t,o=C(e),i=C(r);if(!o||!i)return e;let s=n/100,[l,b,c,u]=o,[h,d,g,m]=i;switch(t.opacity!==void 0&&(u=typeof t.opacity=="number"?t.opacity:z(t.opacity)),t.withOpacity!==void 0&&(m=typeof t.withOpacity=="number"?t.withOpacity:z(t.withOpacity)),a){case"srgb":default:let j=Math.round(l+(h-l)*s),O=Math.round(b+(d-b)*s),p=Math.round(c+(g-c)*s),H=u+(m-u)*s;return E(j,O,p,H);case"hsl":let y=C(L(l,b,c,u)),M=C(L(h,d,g,m));if(!y||!M)return e;let w=(y[0]+(M[0]-y[0])*s)%360,R=y[1]+(M[1]-y[1])*s,B=y[2]+(M[2]-y[2])*s;return`hsl(${w}, ${R}%, ${B}%)`}},lt=(t,e={})=>{let r=C(t);if(!r)return{};let n=e.shades||10,a=e.lightnessFactor||.1,o=e.saturationFactor||.05,i={};for(let s=0;s<n;s++){let l=s/(n-1),b=(l-.5)*2*a*100,c=et(t,{lightness:b,saturation:(l-.5)*2*o*100}),u=s===0?"50":`${s*100}`;i[u]=c}if(e.includeComplementary){let s=C(L(r[0],r[1],r[2]));if(s){let l=s[0];l=(l+180)%360,i.complementary=`hsl(${l}, ${s[1]}%, ${s[2]}%)`}}if(e.includeAnalogous){let s=C(L(r[0],r[1],r[2]));if(s){let l=s[0];i.analogous1=`hsl(${(l-30+360)%360}, ${s[1]}%, ${s[2]}%)`,i.analogous2=`hsl(${(l+30)%360}, ${s[1]}%, ${s[2]}%)`}}if(e.includeTriadic){let s=C(L(r[0],r[1],r[2]));if(s){let l=s[0];i.triadic1=`hsl(${(l+120)%360}, ${s[1]}%, ${s[2]}%)`,i.triadic2=`hsl(${(l+240)%360}, ${s[1]}%, ${s[2]}%)`}}return i},ct=(t,e={})=>{let{lightColor:r="#ffffff",darkColor:n="#000000",targetRatio:a=4.5,fallbackColor:o="#000000"}=e,i=C(t);if(!i)return o;let s=v(i[0],i[1],i[2]),l=v(...C(r).slice(0,3)),b=v(...C(n).slice(0,3)),c=(Math.max(s,l)+.05)/(Math.min(s,l)+.05),u=(Math.max(s,b)+.05)/(Math.min(s,b)+.05);return c>=a&&u>=a?c>u?r:n:c>=a?r:u>=a?n:c>u?r:n};var F={x:.95047,y:1,z:1.08883},P=.008856,_=903.3;function N(t,e,r){return Math.max(e,Math.min(r,t))}function xt(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function x(t){let e=t.r/255,r=t.g/255,n=t.b/255,a=Math.max(e,r,n),o=Math.min(e,r,n),i=a-o,s=0,l=0,b=(a+o)/2;if(i!==0)switch(l=b>.5?i/(2-a-o):i/(a+o),a){case e:s=((r-n)/i+(r<n?6:0))/6;break;case r:s=((n-e)/i+2)/6;break;case n:s=((e-r)/i+4)/6;break}return{h:s*360,s:l*100,l:b*100,a:t.a}}function S(t){let e=t.r/255,r=t.g/255,n=t.b/255,a=Math.max(e,r,n),o=Math.min(e,r,n),i=a-o,s=0,l=a===0?0:i/a,b=a;if(i!==0)switch(a){case e:s=((r-n)/i+(r<n?6:0))/6;break;case r:s=((n-e)/i+2)/6;break;case n:s=((e-r)/i+4)/6;break}return{h:s*360,s:l*100,v:b*100,a:t.a}}function Y(t){let e=S(t),r=(100-e.s)*e.v/100,n=100-e.v;return{h:e.h,w:r,b:n,a:t.a}}function bt(t){let e=t.r/255,r=t.g/255,n=t.b/255,a=1-Math.max(e,r,n),o=a===1?0:(1-e-a)/(1-a),i=a===1?0:(1-r-a)/(1-a),s=a===1?0:(1-n-a)/(1-a);return{c:o*100,m:i*100,y:s*100,k:a*100,a:t.a}}function X(t){let e=t.r/255,r=t.g/255,n=t.b/255;e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,r=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92,n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92;let a=e*.4124564+r*.3575761+n*.1804375,o=e*.2126729+r*.7151522+n*.072175,i=e*.0193339+r*.119192+n*.9503041;return{x:a*100,y:o*100,z:i*100,alpha:t.a}}function k(t){let e=X(t);return kt(e)}function rt(t){let e=k(t);return wt(e)}function $(t){let e=t.r/255,r=t.g/255,n=t.b/255,a=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,o=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92,i=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,s=.4122214708*a+.5363325363*o+.0514459929*i,l=.2119034982*a+.6806995451*o+.1073969566*i,b=.0883024619*a+.2817188376*o+.6299787005*i,c=Math.cbrt(s),u=Math.cbrt(l),h=Math.cbrt(b);return{l:.2104542553*c+.793617785*u-.0040720468*h,a:1.9779984951*c-2.428592205*u+.4505937099*h,b:.0259040371*c+.7827717662*u-.808675766*h,alpha:t.a}}function A(t){let e=$(t);return Rt(e)}function T(t){let e=t.h/360,r=t.s/100,n=t.l/100,a,o,i;if(r===0)a=o=i=n;else{let s=(c,u,h)=>(h<0&&(h+=1),h>1&&(h-=1),h<.16666666666666666?c+(u-c)*6*h:h<.5?u:h<.6666666666666666?c+(u-c)*(.6666666666666666-h)*6:c),l=n<.5?n*(1+r):n+r-n*r,b=2*n-l;a=s(b,l,e+1/3),o=s(b,l,e),i=s(b,l,e-1/3)}return{r:Math.round(a*255),g:Math.round(o*255),b:Math.round(i*255),a:t.a}}function _t(t){let e=T(t);return S(e)}function Nt(t){let e=T(t);return Y(e)}function W(t){let e=t.h/360,r=t.s/100,n=t.v/100,a=Math.floor(e*6),o=e*6-a,i=n*(1-r),s=n*(1-o*r),l=n*(1-(1-o)*r),b,c,u;switch(a%6){case 0:b=n,c=l,u=i;break;case 1:b=s,c=n,u=i;break;case 2:b=i,c=n,u=l;break;case 3:b=i,c=s,u=n;break;case 4:b=l,c=i,u=n;break;default:b=n,c=i,u=s;break}return{r:Math.round(b*255),g:Math.round(c*255),b:Math.round(u*255),a:t.a}}function St(t){let e=W(t);return x(e)}function At(t){let e=(100-t.s)*t.v/100,r=100-t.v;return{h:t.h,w:e,b:r,a:t.a}}function I(t){let e=t.h,r=t.w/100,n=t.b/100,a=r+n;a>1&&(r/=a,n/=a);let o=1-n,i=o===0?0:1-r/o;return W({h:e,s:i*100,v:o*100,a:t.a})}function Gt(t){let e=I(t);return x(e)}function Ft(t){let e=I(t);return S(e)}function q(t){let e=t.c/100,r=t.m/100,n=t.y/100,a=t.k/100,o=255*(1-e)*(1-a),i=255*(1-r)*(1-a),s=255*(1-n)*(1-a);return{r:Math.round(o),g:Math.round(i),b:Math.round(s),a:t.a}}function Pt(t){let e=q(t);return x(e)}function Kt(t){let e=q(t);return S(e)}function nt(t){let e=t.x/100,r=t.y/100,n=t.z/100,a=e*3.2404542+r*-1.5371385+n*-.4985314,o=e*-.969266+r*1.8760108+n*.041556,i=e*.0556434+r*-.2040259+n*1.0572252;return a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a,o=o>.0031308?1.055*Math.pow(o,1/2.4)-.055:12.92*o,i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i,{r:Math.round(N(a*255,0,255)),g:Math.round(N(o*255,0,255)),b:Math.round(N(i*255,0,255)),a:t.alpha||1}}function kt(t){let e=t.x/F.x/100,r=t.y/F.y/100,n=t.z/F.z/100,a=e>P?Math.cbrt(e):(_*e+16)/116,o=r>P?Math.cbrt(r):(_*r+16)/116,i=n>P?Math.cbrt(n):(_*n+16)/116,s=116*o-16,l=500*(a-o),b=200*(o-i);return{l:N(s,0,100),a:l,b,alpha:t.alpha}}function Ct(t){let e=(t.l+16)/116,r=t.a/500+e,n=e-t.b/200,a=r*r*r>P?r*r*r:(116*r-16)/_,o=t.l>_*P?Math.pow((t.l+16)/116,3):t.l/_,i=n*n*n>P?n*n*n:(116*n-16)/_;return{x:a*F.x*100,y:o*F.y*100,z:i*F.z*100,alpha:t.alpha}}function K(t){let e=Ct(t);return nt(e)}function wt(t){let e=Math.sqrt(t.a*t.a+t.b*t.b),r=Math.atan2(t.b,t.a)*180/Math.PI;return r<0&&(r+=360),{l:t.l,c:e,h:r,alpha:t.alpha}}function pt(t){let e=t.h*Math.PI/180,r=t.c*Math.cos(e),n=t.c*Math.sin(e);return{l:t.l,a:r,b:n,alpha:t.alpha}}function ut(t){let e=pt(t);return K(e)}function zt(t){let e=pt(t);return Ct(e)}function ht(t){let e=t.l+.3963377774*t.a+.2158037573*t.b,r=t.l-.1055613458*t.a-.0638541728*t.b,n=t.l-.0894841775*t.a-1.291485548*t.b,a=e*e*e,o=r*r*r,i=n*n*n,s=4.0767416621*a-3.3077115913*o+.2309699292*i,l=-1.2684380046*a+2.6097574011*o-.3413193965*i,b=-.0041960863*a-.7034186147*o+1.707614701*i;return s=s>.0031308?1.055*Math.pow(s,1/2.4)-.055:12.92*s,l=l>.0031308?1.055*Math.pow(l,1/2.4)-.055:12.92*l,b=b>.0031308?1.055*Math.pow(b,1/2.4)-.055:12.92*b,{r:Math.round(N(s*255,0,255)),g:Math.round(N(l*255,0,255)),b:Math.round(N(b*255,0,255)),a:t.alpha}}function Rt(t){let e=Math.sqrt(t.a*t.a+t.b*t.b),r=Math.atan2(t.b,t.a)*180/Math.PI;return r<0&&(r+=360),{l:t.l,c:e,h:r,alpha:t.alpha}}function Ot(t){let e=t.h*Math.PI/180,r=t.c*Math.cos(e),n=t.c*Math.sin(e);return{l:t.l,a:r,b:n,alpha:t.alpha}}function Z(t){let e=Ot(t);return ht(e)}function Ht(t){if("r"in t&&"g"in t&&"b"in t)return t;if("h"in t&&"s"in t&&"l"in t)return T(t);if("h"in t&&"s"in t&&"v"in t)return W(t);if("h"in t&&"w"in t&&"b"in t)return I(t);if("c"in t&&"m"in t&&"y"in t&&"k"in t)return q(t);if("x"in t&&"y"in t&&"z"in t)return nt(t);if("l"in t&&"a"in t&&"b"in t&&!("c"in t)&&!("h"in t))return K(t);if("l"in t&&"c"in t&&"h"in t){let e=t;return e.l<=1?Z(t):ut(e)}throw new Error("Unknown color format")}function ft(t,e,r={}){let{round:n=!0,precision:a=2,preserveAlpha:o=!0}=r,i=Ht(t),s;switch(e.toLowerCase()){case"rgb":s=i;break;case"hsl":s=x(i);break;case"hsv":s=S(i);break;case"hwb":s=Y(i);break;case"cmyk":s=bt(i);break;case"xyz":s=X(i);break;case"lab":s=k(i);break;case"lch":s=rt(i);break;case"oklab":s=$(i);break;case"oklch":s=A(i);break;default:s=i}return n&&s&&Object.keys(s).forEach(l=>{typeof s[l]=="number"&&l!=="a"&&l!=="alpha"&&(s[l]=xt(s[l],a))}),o||(delete s.a,delete s.alpha),s}function Vt(t,e,r={}){return t.map(n=>ft(n,e,r))}function dt(t,e){let r={rgb:["hsl","hsv","hwb","cmyk","xyz","lab","lch","oklab","oklch"],hsl:["rgb","hsv","hwb"],hsv:["rgb","hsl","hwb"],hwb:["rgb","hsl","hsv"],cmyk:["rgb","hsl","hsv"],xyz:["rgb","lab"],lab:["rgb","xyz","lch"],lch:["rgb","lab","xyz"],oklab:["rgb","oklch"],oklch:["rgb","oklab"]};return t=t.toLowerCase(),e=e.toLowerCase(),t===e?[t]:r[t]?.includes(e)?[t,e]:r[t]?.includes("rgb")&&r.rgb?.includes(e)?[t,"rgb",e]:["lab","lch"].includes(t)&&["lab","lch"].includes(e)&&t!==e?[t,"xyz",e]:["oklab","oklch"].includes(t)&&["oklab","oklch"].includes(e)&&t!==e?[t,"oklab",e]:r[t]&&r.rgb?.includes(e)?[t,"rgb",e]:null}function Et(t,e){let r=dt(t,e);return r!==null&&r.length<=2}function gt(){return["rgb","hsl","hsv","hwb","cmyk","xyz","lab","lch","oklab","oklch"]}function Mt(t){return gt().includes(t.toLowerCase())}var f=class t{constructor(e="#000000"){this._r=0;this._g=0;this._b=0;this._a=1;this.set(e)}static parseRgbString(e){return G(e)}static isRgbFormat(e){return Object.values(V).some(r=>r.test(e.trim()))}static getRgbPatternMatch(e){let r=e.trim();for(let[n,a]of Object.entries(V))if(a.test(r))return n;return null}static toModernRgbSyntax(e,r,n,a){let o=[e,r,n];return a!==void 0&&a!==1?`rgb(${o.join(" ")} / ${a})`:`rgb(${o.join(" ")})`}static toLegacyRgbSyntax(e,r,n,a){let o=[e,r,n];return a!==void 0&&a!==1?`rgba(${o.join(", ")}, ${a})`:`rgb(${o.join(", ")})`}static normalizeRgbString(e,r="modern"){let n=G(e);if(!n)return null;let[a,o,i,s]=n;return r==="modern"?this.toModernRgbSyntax(a,o,i,s):this.toLegacyRgbSyntax(a,o,i,s)}set(e){if(typeof e=="string"){let r=C(e);r&&([this._r,this._g,this._b,this._a]=r)}else if(Array.isArray(e))[this._r=0,this._g=0,this._b=0,this._a=1]=e;else if(e instanceof t)[this._r,this._g,this._b,this._a]=[e._r,e._g,e._b,e._a];else if(typeof e=="object")return this.setFromObject(e);return this._clamp(),this}_clamp(){this._r=Math.max(0,Math.min(255,Math.round(this._r))),this._g=Math.max(0,Math.min(255,Math.round(this._g))),this._b=Math.max(0,Math.min(255,Math.round(this._b))),this._a=Math.max(0,Math.min(1,this._a))}get r(){return this._r}set r(e){this._r=e,this._clamp()}get g(){return this._g}set g(e){this._g=e,this._clamp()}get b(){return this._b}set b(e){this._b=e,this._clamp()}get a(){return this._a}set a(e){this._a=e,this._clamp()}get rgb(){return[this._r,this._g,this._b]}get rgba(){return[this._r,this._g,this._b,this._a]}toHex(){return E(this._r,this._g,this._b,this._a)}toRgb(){return Q(this._r,this._g,this._b)}toRgba(){return Q(this._r,this._g,this._b,this._a)}getRgbObject(){return{r:this._r,g:this._g,b:this._b,a:this._a}}toHsl(){return L(this._r,this._g,this._b,this._a)}getHslObject(){return x(this.getRgbObject())}toHsv(){return ot(this._r,this._g,this._b,this._a)}getHsvObject(){return S(this.getRgbObject())}toHwb(){let e=Y(this.getRgbObject()),r=this._a<1?` / ${Math.round(this._a*100)/100}`:"";return`hwb(${Math.round(e.h)} ${Math.round(e.w)}% ${Math.round(e.b)}%${r})`}getHwbObject(){return Y(this.getRgbObject())}toCmyk(){return st(this._r,this._g,this._b,this._a)}getCmykObject(){return bt(this.getRgbObject())}toXyz(){let e=X(this.getRgbObject()),r=this._a<1?` / ${Math.round(this._a*100)/100}`:"";return`color(xyz ${e.x.toFixed(4)} ${e.y.toFixed(4)} ${e.z.toFixed(4)}${r})`}getXyzObject(){return X(this.getRgbObject())}toLab(){let e=k(this.getRgbObject()),r=this._a<1?` / ${Math.round(this._a*100)/100}`:"";return`lab(${e.l.toFixed(2)}% ${e.a.toFixed(2)} ${e.b.toFixed(2)}${r})`}getLabObject(){return k(this.getRgbObject())}toLch(){let e=rt(this.getRgbObject()),r=this._a<1?` / ${Math.round(this._a*100)/100}`:"";return`lch(${e.l.toFixed(2)}% ${e.c.toFixed(2)} ${e.h.toFixed(2)}${r})`}getLchObject(){return rt(this.getRgbObject())}toOklab(){let e=$(this.getRgbObject()),r=this._a<1?` / ${Math.round(this._a*100)/100}`:"";return`oklab(${e.l.toFixed(4)} ${e.a.toFixed(4)} ${e.b.toFixed(4)}${r})`}getOklabObject(){return $(this.getRgbObject())}toOklch(){let e=A(this.getRgbObject()),r=this._a<1?` / ${Math.round(this._a*100)/100}`:"";return`oklch(${e.l.toFixed(4)} ${e.c.toFixed(4)} ${e.h.toFixed(2)}${r})`}getOklchObject(){return A(this.getRgbObject())}adjust(e){let r=et(this.toHex(),e);return this.set(r),this}lighten(e){return this.adjust({lightness:e})}darken(e){return this.adjust({lightness:-e})}saturate(e){return this.adjust({saturation:e})}desaturate(e){return this.adjust({saturation:-e})}rotate(e){return this.adjust({hue:e})}alpha(e){return this._a=Math.max(0,Math.min(1,e)),this}mix(e,r=50,n="srgb"){let a=it({color:this.toHex(),with:e,percentage:r,colorSpace:n});return this.set(a),this}getContrastColor(e={}){let r=ct(this.toHex(),e);return new t(r)}getLuminance(){return v(this._r,this._g,this._b)}getContrastRatio(e){let r=e instanceof t?e.toHex():e;return at(this.toHex(),r)}getPalette(e={}){return lt(this.toHex(),e)}clone(){return new t(this.rgba)}toString(e="hex"){switch(e){case"hex":return this.toHex();case"rgb":return this.toRgb();case"rgba":return this.toRgba();case"hsl":return this.toHsl();case"hsla":return this.toHsl();case"hsv":return this.toHsv();case"hsva":return this.toHsv();case"hwb":return this.toHwb();case"cmyk":return this.toCmyk();case"xyz":return this.toXyz();case"lab":return this.toLab();case"lch":return this.toLch();case"oklab":return this.toOklab();case"oklch":return this.toOklch();default:return this.toHex()}}convertTo(e,r={}){return ft(this.getRgbObject(),e,r)}setFromObject(e){let r;if("r"in e&&"g"in e&&"b"in e)r=e;else if("h"in e&&"s"in e&&"l"in e)r=T(e);else if("h"in e&&"s"in e&&"v"in e)r=W(e);else if("h"in e&&"w"in e&&"b"in e)r=I(e);else if("c"in e&&"m"in e&&"y"in e&&"k"in e)r=q(e);else if("x"in e&&"y"in e&&"z"in e)r=nt(e);else if("l"in e&&"a"in e&&"b"in e)r=K(e);else if("l"in e&&"c"in e&&"h"in e){let n=e;r=n.l<=1?Z(e):ut(n)}else throw new Error("Unknown color format");return this._r=r.r,this._g=r.g,this._b=r.b,this._a=r.a??1,this._clamp(),this}getHarmony(e={}){let{type:r="complementary",count:n=5,angleOffset:a=30}=e,o=this.getHslObject(),i=[];switch(r){case"complementary":i.push(new t({h:(o.h+180)%360,s:o.s,l:o.l,a:o.a}));break;case"analogous":i.push(new t({h:(o.h-a+360)%360,s:o.s,l:o.l,a:o.a}),new t({h:(o.h+a)%360,s:o.s,l:o.l,a:o.a}));break;case"triadic":i.push(new t({h:(o.h+120)%360,s:o.s,l:o.l,a:o.a}),new t({h:(o.h+240)%360,s:o.s,l:o.l,a:o.a}));break;case"tetradic":i.push(new t({h:(o.h+90)%360,s:o.s,l:o.l,a:o.a}),new t({h:(o.h+180)%360,s:o.s,l:o.l,a:o.a}),new t({h:(o.h+270)%360,s:o.s,l:o.l,a:o.a}));break;case"split-complementary":i.push(new t({h:(o.h+150)%360,s:o.s,l:o.l,a:o.a}),new t({h:(o.h+210)%360,s:o.s,l:o.l,a:o.a}));break;case"square":i.push(new t({h:(o.h+90)%360,s:o.s,l:o.l,a:o.a}),new t({h:(o.h+180)%360,s:o.s,l:o.l,a:o.a}),new t({h:(o.h+270)%360,s:o.s,l:o.l,a:o.a}));break;case"monochromatic":let s=100/(n+1);for(let l=1;l<=n;l++)i.push(new t({h:o.h,s:o.s,l:Math.max(0,Math.min(100,s*l)),a:o.a}));break}return i}static getSupportedFormats(){return gt()}static isValidFormat(e){return Mt(e)}static getConversionPath(e,r){return dt(e,r)}isValid(){return tt(this.toHex())}static fromString(e){return tt(e)?new t(e):null}static random(){let e=Math.floor(Math.random()*256),r=Math.floor(Math.random()*256),n=Math.floor(Math.random()*256);return new t([e,r,n,1])}static get transparent(){return new t("transparent")}static get white(){return new t("#ffffff")}static get black(){return new t("#000000")}static get red(){return new t("#ff0000")}static get green(){return new t("#00ff00")}static get blue(){return new t("#0000ff")}static get yellow(){return new t("#ffff00")}static get cyan(){return new t("#00ffff")}static get magenta(){return new t("#ff00ff")}static get gray(){return new t("#808080")}static get lightGray(){return new t("#d3d3d3")}static get darkGray(){return new t("#a9a9a9")}static get orange(){return new t("#ffa500")}static get purple(){return new t("#800080")}static get pink(){return new t("#ffc0cb")}static get brown(){return new t("#a52a2a")}static get teal(){return new t("#008080")}static get lime(){return new t("#00ff00")}static get indigo(){return new t("#4b0082")}static get violet(){return new t("#ee82ee")}};function Ut(t,e={}){let{temperature:r=0,intensity:n=.5}=e,o=(t instanceof f?t:new f(t)).getRgbObject(),i=Math.max(-1,Math.min(1,r/1e4)),s=o.r,l=o.g,b=o.b;if(i>0)s=Math.min(255,s+i*255*n),l=Math.min(255,l+i*200*n),b=Math.max(0,b-i*100*n);else{let c=Math.abs(i);s=Math.max(0,s-c*100*n),l=Math.max(0,l-c*50*n),b=Math.min(255,b+c*255*n)}return new f([Math.round(s),Math.round(l),Math.round(b),o.a||1])}function Jt(t,e="protanopia"){let n=(t instanceof f?t:new f(t)).getRgbObject(),a=n.r/255,o=n.g/255,i=n.b/255,s;switch(e){case"protanopia":s=[[.56667,.43333,0],[.55833,.44167,0],[0,.24167,.75833]];break;case"deuteranopia":s=[[.625,.375,0],[.7,.3,0],[0,.3,.7]];break;case"tritanopia":s=[[.95,.05,0],[0,.43333,.56667],[0,.475,.525]];break;case"achromatopsia":let u=.299*a+.587*o+.114*i;return new f([Math.round(u*255),Math.round(u*255),Math.round(u*255),n.a||1]);default:s=[[1,0,0],[0,1,0],[0,0,1]]}let l=s[0][0]*a+s[0][1]*o+s[0][2]*i,b=s[1][0]*a+s[1][1]*o+s[1][2]*i,c=s[2][0]*a+s[2][1]*o+s[2][2]*i;return new f([Math.round(Math.max(0,Math.min(255,l*255))),Math.round(Math.max(0,Math.min(255,b*255))),Math.round(Math.max(0,Math.min(255,c*255))),n.a||1])}function Qt(t,e=!1){let n=(t instanceof f?t:new f(t)).getRgbObject();return e?(.299*n.r+.587*n.g+.114*n.b)/255>.5?f.black:f.white:new f([255-n.r,255-n.g,255-n.b,n.a||1])}function te(t,e="luminosity"){let n=(t instanceof f?t:new f(t)).getRgbObject(),a;switch(e){case"average":a=(n.r+n.g+n.b)/3;break;case"luminosity":a=.299*n.r+.587*n.g+.114*n.b;break;case"lightness":a=(Math.max(n.r,n.g,n.b)+Math.min(n.r,n.g,n.b))/2;break;default:a=.299*n.r+.587*n.g+.114*n.b}let o=Math.round(a);return new f([o,o,o,n.a||1])}function ee(t,e=1){let n=(t instanceof f?t:new f(t)).getRgbObject(),a=n.r/255,o=n.g/255,i=n.b/255,s=.393*a+.769*o+.189*i,l=.349*a+.686*o+.168*i,b=.272*a+.534*o+.131*i;return s=a+(s-a)*e,l=o+(l-o)*e,b=i+(b-i)*e,new f([Math.round(Math.max(0,Math.min(255,s*255))),Math.round(Math.max(0,Math.min(255,l*255))),Math.round(Math.max(0,Math.min(255,b*255))),n.a||1])}function Lt(t,e){let r=t instanceof f?t:new f(t),n=e instanceof f?e:new f(e),a=k(r.getRgbObject()),o=k(n.getRgbObject()),i=a.l-o.l,s=a.a-o.a,l=a.b-o.b;return Math.sqrt(i*i+s*s+l*l)}function re(t,e){let r=t instanceof f?t:new f(t),n=null,a=1/0;for(let o of e){let i=Lt(r,o);i<a&&(a=i,n=o instanceof f?o:new f(o))}return n||r}function ne(t,e,r=5,n="rgb"){let a=t instanceof f?t:new f(t),o=e instanceof f?e:new f(e),i=[];if(r<2)return[a];for(let s=0;s<r;s++){let l=s/(r-1),b;switch(n){case"hsl":{let c=x(a.getRgbObject()),u=x(o.getRgbObject()),h=c.h,d=u.h,g=d-h;Math.abs(g)>180&&(h<d?h+=360:d+=360);let m=(h+(d-h)*l)%360,j=c.s+(u.s-c.s)*l,O=c.l+(u.l-c.l)*l,p=(c.a??1)+((u.a??1)-(c.a??1))*l;b=T({h:m,s:j,l:O,a:p});break}case"lab":{let c=k(a.getRgbObject()),u=k(o.getRgbObject()),h=c.l+(u.l-c.l)*l,d=c.a+(u.a-c.a)*l,g=c.b+(u.b-c.b)*l,m=(c.alpha??1)+((u.alpha??1)-(c.alpha??1))*l;b=K({l:h,a:d,b:g,alpha:m});break}case"oklab":{let c=$(a.getRgbObject()),u=$(o.getRgbObject()),h=c.l+(u.l-c.l)*l,d=c.a+(u.a-c.a)*l,g=c.b+(u.b-c.b)*l,m=(c.alpha??1)+((u.alpha??1)-(c.alpha??1))*l;b=ht({l:h,a:d,b:g,alpha:m});break}case"oklch":{let c=A(a.getRgbObject()),u=A(o.getRgbObject()),h=c.h,d=u.h,g=d-h;Math.abs(g)>180&&(h<d?h+=360:d+=360);let m=c.l+(u.l-c.l)*l,j=c.c+(u.c-c.c)*l,O=(h+(d-h)*l)%360,p=(c.alpha??1)+((u.alpha??1)-(c.alpha??1))*l;b=Z({l:m,c:j,h:O,alpha:p});break}default:{let c=a.getRgbObject(),u=o.getRgbObject();b={r:Math.round(c.r+(u.r-c.r)*l),g:Math.round(c.g+(u.g-c.g)*l),b:Math.round(c.b+(u.b-c.b)*l),a:(c.a??1)+((u.a??1)-(c.a??1))*l};break}}i.push(new f(b))}return i}function vt(t){let r=(t instanceof f?t:new f(t)).getRgbObject();return(.299*r.r+.587*r.g+.114*r.b)/255}function $t(t){return vt(t)>.5}function oe(t){return!$t(t)}function se(t,e,r="normal",n=1){let a=t instanceof f?t:new f(t),o=e instanceof f?e:new f(e),i=a.getRgbObject(),s=o.getRgbObject(),l=(b,c)=>{let u=b/255,h=c/255,d;switch(r){case"multiply":d=u*h;break;case"screen":d=1-(1-u)*(1-h);break;case"overlay":d=u<.5?2*u*h:1-2*(1-u)*(1-h);break;default:d=h*n+u*(1-n);break}return Math.round(Math.max(0,Math.min(255,d*255)))};return new f([l(i.r,s.r),l(i.g,s.g),l(i.b,s.b),i.a||1])}function ae(t){let r=(t instanceof f?t:new f(t)).getRgbObject(),n=Math.max(r.r,r.g,r.b),a=Math.min(r.r,r.g,r.b);return n-a<20?"gray":r.r===n?"red":r.g===n?"green":"blue"}function ie(t){let e=t instanceof f?t:new f(t),r=x(e.getRgbObject());if(r.s<10)return r.l>90?"white":r.l<10?"black":r.l>60?"light gray":r.l<40?"dark gray":"gray";let n=r.h,a;return n<15||n>=345?a="red":n<45?a="orange":n<75?a="yellow":n<165?a="green":n<255?a="blue":n<285?a="purple":n<315?a="magenta":a="pink",r.l<30?`dark ${a}`:r.l>70?`light ${a}`:r.s<30?`dull ${a}`:r.s>70?`vivid ${a}`:a}function le(t={}){let{hue:e=[0,360],saturation:r=[0,100],lightness:n=[0,100],alpha:a=1}=t,o=e[0]+Math.random()*(e[1]-e[0]),i=r[0]+Math.random()*(r[1]-r[0]),s=n[0]+Math.random()*(n[1]-n[0]),l=T({h:o,s:i,l:s,a});return new f(l)}export{f as Color,D as NAMED_COLORS,V as RGB_PATTERNS,et as adjustColor,Ut as adjustTemperature,Ht as anyToRgb,Vt as batchConvert,se as blendColors,at as calculateContrastRatio,v as calculateLuminance,Pt as cmykToHsl,Kt as cmykToHsv,q as cmykToRgb,Lt as colorDistance,ft as convertColor,ct as createContrastColor,re as findClosestColor,Q as formatRgba,ne as generateGradient,lt as generatePalette,ie as getColorName,dt as getConversionPath,ae as getDominantComponent,vt as getPerceivedBrightness,gt as getSupportedFormats,Et as hasDirectConversion,_t as hslToHsv,Nt as hslToHwb,T as hslToRgb,St as hsvToHsl,At as hsvToHwb,W as hsvToRgb,Gt as hwbToHsl,Ft as hwbToHsv,I as hwbToRgb,Qt as invertColor,oe as isDark,$t as isLight,tt as isValidColor,Mt as isValidFormat,wt as labToLch,K as labToRgb,Ct as labToXyz,pt as lchToLab,ut as lchToRgb,zt as lchToXyz,it as mixColors,Rt as oklabToOklch,ht as oklabToRgb,Ot as oklchToOklab,Z as oklchToRgb,C as parseColor,G as parseRgbaColor,le as randomColor,bt as rgbToCmyk,x as rgbToHsl,S as rgbToHsv,Y as rgbToHwb,k as rgbToLab,rt as rgbToLch,$ as rgbToOklab,A as rgbToOklch,X as rgbToXyz,st as rgbaToCmyk,E as rgbaToHex,L as rgbaToHsl,ot as rgbaToHsv,Jt as simulateColorBlindness,te as toGrayscale,ee as toSepia,kt as xyzToLab,nt as xyzToRgb};
1
+ /*! @fluixi/utils v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
+
3
+ // src/lib/color/constants.ts
4
+ var NAMED_COLORS = {
5
+ // Basic colors
6
+ aliceblue: "#f0f8ff",
7
+ antiquewhite: "#faebd7",
8
+ aqua: "#00ffff",
9
+ aquamarine: "#7fffd4",
10
+ azure: "#f0ffff",
11
+ beige: "#f5f5dc",
12
+ bisque: "#ffe4c4",
13
+ black: "#000000",
14
+ blanchedalmond: "#ffebcd",
15
+ blue: "#0000ff",
16
+ blueviolet: "#8a2be2",
17
+ brown: "#a52a2a",
18
+ burlywood: "#deb887",
19
+ cadetblue: "#5f9ea0",
20
+ chartreuse: "#7fff00",
21
+ chocolate: "#d2691e",
22
+ coral: "#ff7f50",
23
+ cornflowerblue: "#6495ed",
24
+ cornsilk: "#fff8dc",
25
+ crimson: "#dc143c",
26
+ cyan: "#00ffff",
27
+ darkblue: "#00008b",
28
+ darkcyan: "#008b8b",
29
+ darkgoldenrod: "#b8860b",
30
+ darkgray: "#a9a9a9",
31
+ darkgreen: "#006400",
32
+ darkgrey: "#a9a9a9",
33
+ darkkhaki: "#bdb76b",
34
+ darkmagenta: "#8b008b",
35
+ darkolivegreen: "#556b2f",
36
+ darkorange: "#ff8c00",
37
+ darkorchid: "#9932cc",
38
+ darkred: "#8b0000",
39
+ darksalmon: "#e9967a",
40
+ darkseagreen: "#8fbc8f",
41
+ darkslateblue: "#483d8b",
42
+ darkslategray: "#2f4f4f",
43
+ darkslategrey: "#2f4f4f",
44
+ darkturquoise: "#00ced1",
45
+ darkviolet: "#9400d3",
46
+ deeppink: "#ff1493",
47
+ deepskyblue: "#00bfff",
48
+ dimgray: "#696969",
49
+ dimgrey: "#696969",
50
+ dodgerblue: "#1e90ff",
51
+ firebrick: "#b22222",
52
+ floralwhite: "#fffaf0",
53
+ forestgreen: "#228b22",
54
+ fuchsia: "#ff00ff",
55
+ gainsboro: "#dcdcdc",
56
+ ghostwhite: "#f8f8ff",
57
+ gold: "#ffd700",
58
+ goldenrod: "#daa520",
59
+ gray: "#808080",
60
+ green: "#008000",
61
+ greenyellow: "#adff2f",
62
+ grey: "#808080",
63
+ honeydew: "#f0fff0",
64
+ hotpink: "#ff69b4",
65
+ indianred: "#cd5c5c",
66
+ indigo: "#4b0082",
67
+ ivory: "#fffff0",
68
+ khaki: "#f0e68c",
69
+ lavender: "#e6e6fa",
70
+ lavenderblush: "#fff0f5",
71
+ lawngreen: "#7cfc00",
72
+ lemonchiffon: "#fffacd",
73
+ lightblue: "#add8e6",
74
+ lightcoral: "#f08080",
75
+ lightcyan: "#e0ffff",
76
+ lightgoldenrodyellow: "#fafad2",
77
+ lightgray: "#d3d3d3",
78
+ lightgreen: "#90ee90",
79
+ lightgrey: "#d3d3d3",
80
+ lightpink: "#ffb6c1",
81
+ lightsalmon: "#ffa07a",
82
+ lightseagreen: "#20b2aa",
83
+ lightskyblue: "#87cefa",
84
+ lightslategray: "#778899",
85
+ lightslategrey: "#778899",
86
+ lightsteelblue: "#b0c4de",
87
+ lightyellow: "#ffffe0",
88
+ lime: "#00ff00",
89
+ limegreen: "#32cd32",
90
+ linen: "#faf0e6",
91
+ magenta: "#ff00ff",
92
+ maroon: "#800000",
93
+ mediumaquamarine: "#66cdaa",
94
+ mediumblue: "#0000cd",
95
+ mediumorchid: "#ba55d3",
96
+ mediumpurple: "#9370db",
97
+ mediumseagreen: "#3cb371",
98
+ mediumslateblue: "#7b68ee",
99
+ mediumspringgreen: "#00fa9a",
100
+ mediumturquoise: "#48d1cc",
101
+ mediumvioletred: "#c71585",
102
+ midnightblue: "#191970",
103
+ mintcream: "#f5fffa",
104
+ mistyrose: "#ffe4e1",
105
+ moccasin: "#ffe4b5",
106
+ navajowhite: "#ffdead",
107
+ navy: "#000080",
108
+ oldlace: "#fdf5e6",
109
+ olive: "#808000",
110
+ olivedrab: "#6b8e23",
111
+ orange: "#ffa500",
112
+ orangered: "#ff4500",
113
+ orchid: "#da70d6",
114
+ palegoldenrod: "#eee8aa",
115
+ palegreen: "#98fb98",
116
+ paleturquoise: "#afeeee",
117
+ palevioletred: "#db7093",
118
+ papayawhip: "#ffefd5",
119
+ peachpuff: "#ffdab9",
120
+ peru: "#cd853f",
121
+ pink: "#ffc0cb",
122
+ plum: "#dda0dd",
123
+ powderblue: "#b0e0e6",
124
+ purple: "#800080",
125
+ rebeccapurple: "#663399",
126
+ red: "#ff0000",
127
+ rosybrown: "#bc8f8f",
128
+ royalblue: "#4169e1",
129
+ saddlebrown: "#8b4513",
130
+ salmon: "#fa8072",
131
+ sandybrown: "#f4a460",
132
+ seagreen: "#2e8b57",
133
+ seashell: "#fff5ee",
134
+ sienna: "#a0522d",
135
+ silver: "#c0c0c0",
136
+ skyblue: "#87ceeb",
137
+ slateblue: "#6a5acd",
138
+ slategray: "#708090",
139
+ slategrey: "#708090",
140
+ snow: "#fffafa",
141
+ springgreen: "#00ff7f",
142
+ steelblue: "#4682b4",
143
+ tan: "#d2b48c",
144
+ teal: "#008080",
145
+ thistle: "#d8bfd8",
146
+ tomato: "#ff6347",
147
+ transparent: "transparent",
148
+ turquoise: "#40e0d0",
149
+ violet: "#ee82ee",
150
+ wheat: "#f5deb3",
151
+ white: "#ffffff",
152
+ whitesmoke: "#f5f5f5",
153
+ yellow: "#ffff00",
154
+ yellowgreen: "#9acd32",
155
+ // Additional modern colors
156
+ zinc: "#71717a",
157
+ stone: "#78716c",
158
+ neutral: "#737373",
159
+ slate: "#64748b",
160
+ gray50: "#f9fafb",
161
+ gray100: "#f3f4f6",
162
+ gray200: "#e5e7eb",
163
+ gray300: "#d1d5db",
164
+ gray400: "#9ca3af",
165
+ gray500: "#6b7280",
166
+ gray600: "#4b5563",
167
+ gray700: "#374151",
168
+ gray800: "#1f2937",
169
+ gray900: "#111827",
170
+ gray950: "#030712",
171
+ red50: "#fef2f2",
172
+ red100: "#fee2e2",
173
+ red200: "#fecaca",
174
+ red300: "#fca5a5",
175
+ red400: "#f87171",
176
+ red500: "#ef4444",
177
+ red600: "#dc2626",
178
+ red700: "#b91c1c",
179
+ red800: "#991b1b",
180
+ red900: "#7f1d1d",
181
+ red950: "#450a0a",
182
+ orange50: "#fff7ed",
183
+ orange100: "#ffedd5",
184
+ orange200: "#fed7aa",
185
+ orange300: "#fdba74",
186
+ orange400: "#fb923c",
187
+ orange500: "#f97316",
188
+ orange600: "#ea580c",
189
+ orange700: "#c2410c",
190
+ orange800: "#9a3412",
191
+ orange900: "#7c2d12",
192
+ orange950: "#431407",
193
+ amber50: "#fffbeb",
194
+ amber100: "#fef3c7",
195
+ amber200: "#fde68a",
196
+ amber300: "#fcd34d",
197
+ amber400: "#fbbf24",
198
+ amber500: "#f59e0b",
199
+ amber600: "#d97706",
200
+ amber700: "#b45309",
201
+ amber800: "#92400e",
202
+ amber900: "#78350f",
203
+ amber950: "#451a03",
204
+ yellow50: "#fefce8",
205
+ yellow100: "#fef9c3",
206
+ yellow200: "#fef08a",
207
+ yellow300: "#fde047",
208
+ yellow400: "#facc15",
209
+ yellow500: "#eab308",
210
+ yellow600: "#ca8a04",
211
+ yellow700: "#a16207",
212
+ yellow800: "#854d0e",
213
+ yellow900: "#713f12",
214
+ yellow950: "#422006",
215
+ lime50: "#f7fee7",
216
+ lime100: "#ecfccb",
217
+ lime200: "#d9f99d",
218
+ lime300: "#bef264",
219
+ lime400: "#a3e635",
220
+ lime500: "#84cc16",
221
+ lime600: "#65a30d",
222
+ lime700: "#4d7c0f",
223
+ lime800: "#3f6212",
224
+ lime900: "#365314",
225
+ lime950: "#1a2e05",
226
+ green50: "#f0fdf4",
227
+ green100: "#dcfce7",
228
+ green200: "#bbf7d0",
229
+ green300: "#86efac",
230
+ green400: "#4ade80",
231
+ green500: "#22c55e",
232
+ green600: "#16a34a",
233
+ green700: "#15803d",
234
+ green800: "#166534",
235
+ green900: "#14532d",
236
+ green950: "#052e16",
237
+ emerald50: "#ecfdf5",
238
+ emerald100: "#d1fae5",
239
+ emerald200: "#a7f3d0",
240
+ emerald300: "#6ee7b7",
241
+ emerald400: "#34d399",
242
+ emerald500: "#10b981",
243
+ emerald600: "#059669",
244
+ emerald700: "#047857",
245
+ emerald800: "#065f46",
246
+ emerald900: "#064e3b",
247
+ emerald950: "#022c22",
248
+ teal50: "#f0fdfa",
249
+ teal100: "#ccfbf1",
250
+ teal200: "#99f6e4",
251
+ teal300: "#5eead4",
252
+ teal400: "#2dd4bf",
253
+ teal500: "#14b8a6",
254
+ teal600: "#0d9488",
255
+ teal700: "#0f766e",
256
+ teal800: "#115e59",
257
+ teal900: "#134e4a",
258
+ teal950: "#042f2e",
259
+ cyan50: "#ecfeff",
260
+ cyan100: "#cffafe",
261
+ cyan200: "#a5f3fc",
262
+ cyan300: "#67e8f9",
263
+ cyan400: "#22d3ee",
264
+ cyan500: "#06b6d4",
265
+ cyan600: "#0891b2",
266
+ cyan700: "#0e7490",
267
+ cyan800: "#155e75",
268
+ cyan900: "#164e63",
269
+ cyan950: "#083344",
270
+ sky50: "#f0f9ff",
271
+ sky100: "#e0f2fe",
272
+ sky200: "#bae6fd",
273
+ sky300: "#7dd3fc",
274
+ sky400: "#38bdf8",
275
+ sky500: "#0ea5e9",
276
+ sky600: "#0284c7",
277
+ sky700: "#0369a1",
278
+ sky800: "#075985",
279
+ sky900: "#0c4a6e",
280
+ sky950: "#082f49",
281
+ blue50: "#eff6ff",
282
+ blue100: "#dbeafe",
283
+ blue200: "#bfdbfe",
284
+ blue300: "#93c5fd",
285
+ blue400: "#60a5fa",
286
+ blue500: "#3b82f6",
287
+ blue600: "#2563eb",
288
+ blue700: "#1d4ed8",
289
+ blue800: "#1e40af",
290
+ blue900: "#1e3a8a",
291
+ blue950: "#172554",
292
+ indigo50: "#eef2ff",
293
+ indigo100: "#e0e7ff",
294
+ indigo200: "#c7d2fe",
295
+ indigo300: "#a5b4fc",
296
+ indigo400: "#818cf8",
297
+ indigo500: "#6366f1",
298
+ indigo600: "#4f46e5",
299
+ indigo700: "#4338ca",
300
+ indigo800: "#3730a3",
301
+ indigo900: "#312e81",
302
+ indigo950: "#1e1b4b",
303
+ violet50: "#f5f3ff",
304
+ violet100: "#ede9fe",
305
+ violet200: "#ddd6fe",
306
+ violet300: "#c4b5fd",
307
+ violet400: "#a78bfa",
308
+ violet500: "#8b5cf6",
309
+ violet600: "#7c3aed",
310
+ violet700: "#6d28d9",
311
+ violet800: "#5b21b6",
312
+ violet900: "#4c1d95",
313
+ violet950: "#2e1065",
314
+ purple50: "#faf5ff",
315
+ purple100: "#f3e8ff",
316
+ purple200: "#e9d5ff",
317
+ purple300: "#d8b4fe",
318
+ purple400: "#c084fc",
319
+ purple500: "#a855f7",
320
+ purple600: "#9333ea",
321
+ purple700: "#7e22ce",
322
+ purple800: "#6b21a8",
323
+ purple900: "#581c87",
324
+ purple950: "#3b0764",
325
+ fuchsia50: "#fdf4ff",
326
+ fuchsia100: "#fae8ff",
327
+ fuchsia200: "#f5d0fe",
328
+ fuchsia300: "#f0abfc",
329
+ fuchsia400: "#e879f9",
330
+ fuchsia500: "#d946ef",
331
+ fuchsia600: "#c026d3",
332
+ fuchsia700: "#a21caf",
333
+ fuchsia800: "#86198f",
334
+ fuchsia900: "#701a75",
335
+ fuchsia950: "#4a044e",
336
+ pink50: "#fdf2f8",
337
+ pink100: "#fce7f3",
338
+ pink200: "#fbcfe8",
339
+ pink300: "#f9a8d4",
340
+ pink400: "#f472b6",
341
+ pink500: "#ec4899",
342
+ pink600: "#db2777",
343
+ pink700: "#be185d",
344
+ pink800: "#9d174d",
345
+ pink900: "#831843",
346
+ pink950: "#500724",
347
+ rose50: "#fff1f2",
348
+ rose100: "#ffe4e6",
349
+ rose200: "#fecdd3",
350
+ rose300: "#fda4af",
351
+ rose400: "#fb7185",
352
+ rose500: "#f43f5e",
353
+ rose600: "#e11d48",
354
+ rose700: "#be123c",
355
+ rose800: "#9f1239",
356
+ rose900: "#881337",
357
+ rose950: "#4c0519"
358
+ };
359
+
360
+ // src/lib/color/utils.ts
361
+ var RGB_PATTERNS = {
362
+ /**
363
+ * Matches legacy comma-separated RGB
364
+ * @example rgb(255, 0, 0)
365
+ */
366
+ LEGACY_RGB: /^rgb\(\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*\)$/i,
367
+ /**
368
+ * Matches modern space-separated RGB
369
+ * @example rgb(255 0 0)
370
+ */
371
+ MODERN_RGB: /^rgb\(\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s+(\d{1,3}|\.\d+|\d+\.\d+%?)\s+(\d{1,3}|\.\d+|\d+\.\d+%?)\s*\)$/i,
372
+ /**
373
+ * Matches legacy comma-separated RGBA
374
+ * @example rgba(255, 0, 0, 0.5)
375
+ * @example rgba(255, 0, 0, 50%)
376
+ */
377
+ LEGACY_RGBA: /^rgba\(\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s*,\s*(0|1|0?\.\d+|\d{1,3}%?|\.\d+%?)\s*\)$/i,
378
+ /**
379
+ * Matches modern space-separated RGBA with slash
380
+ * @example rgb(255 0 0 / 0.5)
381
+ * @example rgb(255 0 0 / 50%)
382
+ * @example rgba(255 0 0 / 0.5)
383
+ */
384
+ MODERN_RGBA: /^rgba?\(\s*(\d{1,3}|\.\d+|\d+\.\d+%?)\s+(\d{1,3}|\.\d+|\d+\.\d+%?)\s+(\d{1,3}|\.\d+|\d+\.\d+%?)\s*\/\s*(0|1|0?\.\d+|\d{1,3}%?|\.\d+%?)\s*\)$/i,
385
+ /**
386
+ * Combined pattern that matches all RGB/RGBA variations
387
+ * Supports:
388
+ * - Legacy comma-separated: rgb(255, 0, 0), rgba(255, 0, 0, 0.5)
389
+ * - Modern space-separated: rgb(255 0 0), rgb(255 0 0 / 0.5)
390
+ * - Mixed separators: rgb(255,0,0), rgb(255 0 0)
391
+ * - Percentages: rgb(100% 0% 0%), rgb(100% 0% 0% / 50%)
392
+ * - Decimal numbers: rgb(255.5 0 0), rgba(255, 0, 0, 0.5)
393
+ * - CSS variables: rgb(var(--red) var(--green) var(--blue))
394
+ */
395
+ COMPREHENSIVE: /^rgba?\(\s*((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\)))\s*(?:[,\s]\s*((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\))))?\s*(?:[,\s]\s*((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\))))?\s*(?:(?:\s*[,\s]?\s*\/?\s*|\s*\/\s*)((?:0|1|0?\.\d+|\.\d+|\d{1,3}%?|var\([^)]+\))))?\s*\)$/i,
396
+ /**
397
+ * Strict RGB pattern with validation
398
+ * Matches integers (0-255) or percentages (0-100%)
399
+ */
400
+ STRICT_RGB: /^rgb\(\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*\)$/i,
401
+ /**
402
+ * Strict RGBA pattern with validation
403
+ */
404
+ STRICT_RGBA: /^rgba\(\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5]|\d{1,2}(?:\.\d+)?%|100%|\.\d+%?|var\([^)]+\)))\s*,\s*((?:0|1|0?\.\d+|\.\d+|\d{1,2}(?:\.\d+)?%|100%|var\([^)]+\)))\s*\)$/i,
405
+ /**
406
+ * Modern RGB with optional alpha
407
+ */
408
+ MODERN_RGB_ALPHA: /^rgba?\(\s*((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\)))\s+((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\)))\s+((?:\d{1,3}(?:\.\d+)?%?|\.\d+%?|var\([^)]+\)))\s*(?:\/\s*((?:0|1|0?\.\d+|\.\d+|\d{1,3}%?|var\([^)]+\))))?\s*\)$/i
409
+ };
410
+ var parseRgbaColor = (colorString) => {
411
+ const str = colorString.trim().toLowerCase();
412
+ if (!str || str.includes("var(")) {
413
+ return null;
414
+ }
415
+ const parseComponent = (component) => {
416
+ if (!component) return null;
417
+ const trimmed = component.trim();
418
+ if (!trimmed || trimmed.includes("var(")) return null;
419
+ if (trimmed.endsWith("%")) {
420
+ const percent = parseFloat(trimmed);
421
+ if (isNaN(percent)) return null;
422
+ const clamped = Math.max(0, Math.min(100, percent));
423
+ return Math.round(clamped * 255 / 100);
424
+ }
425
+ const num = parseFloat(trimmed);
426
+ if (isNaN(num)) return null;
427
+ return Math.round(Math.max(0, Math.min(255, num)));
428
+ };
429
+ const parseAlpha = (alpha) => {
430
+ if (!alpha) return 1;
431
+ const trimmed = alpha.trim();
432
+ if (!trimmed || trimmed.includes("var(")) return 1;
433
+ if (trimmed.endsWith("%")) {
434
+ const percent = parseFloat(trimmed);
435
+ if (isNaN(percent)) return 1;
436
+ return Math.max(0, Math.min(100, percent)) / 100;
437
+ }
438
+ const num = parseFloat(trimmed);
439
+ if (isNaN(num)) return 1;
440
+ return Math.max(0, Math.min(1, num));
441
+ };
442
+ const legacyCommaPattern = /^rgba?\(\s*([^,]+)\s*,\s*([^,]+)\s*,\s*([^,]+)\s*(?:,\s*([^\)]+))?\s*\)$/;
443
+ let match = str.match(legacyCommaPattern);
444
+ if (match) {
445
+ const r = parseComponent(match[1]);
446
+ const g = parseComponent(match[2]);
447
+ const b = parseComponent(match[3]);
448
+ const a = parseAlpha(match[4]);
449
+ if (r !== null && g !== null && b !== null) {
450
+ return [r, g, b, a];
451
+ }
452
+ }
453
+ const modernSlashPattern = /^rgba?\(\s*([^\s\/]+)\s+([^\s\/]+)\s+([^\s\/]+)\s*(?:\/\s*([^\)]+))?\s*\)$/;
454
+ match = str.match(modernSlashPattern);
455
+ if (match) {
456
+ const r = parseComponent(match[1]);
457
+ const g = parseComponent(match[2]);
458
+ const b = parseComponent(match[3]);
459
+ const a = parseAlpha(match[4]);
460
+ if (r !== null && g !== null && b !== null) {
461
+ return [r, g, b, a];
462
+ }
463
+ }
464
+ const modernSpacePattern = /^rgb\(\s*([^\s,]+)\s+([^\s,]+)\s+([^\s,]+)\s*\)$/;
465
+ match = str.match(modernSpacePattern);
466
+ if (match) {
467
+ const r = parseComponent(match[1]);
468
+ const g = parseComponent(match[2]);
469
+ const b = parseComponent(match[3]);
470
+ if (r !== null && g !== null && b !== null) {
471
+ return [r, g, b, 1];
472
+ }
473
+ }
474
+ return null;
475
+ };
476
+ var COLOR_PATTERNS = {
477
+ // Hex patterns (unchanged)
478
+ HEX: /^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/,
479
+ // RGB patterns (enhanced)
480
+ RGB: RGB_PATTERNS.COMPREHENSIVE,
481
+ // HSL patterns (supports both hsl and hsla)
482
+ HSL: /^hsla?\(\s*(\d+(?:\.\d+)?)(?:deg|rad|grad|turn)?\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,
483
+ // OKLCH pattern
484
+ OKLCH: /^oklch\(\s*(\d+(?:\.\d+)?%?)\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)(?:\s+[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,
485
+ // OKLAB pattern
486
+ OKLAB: /^oklab\(\s*(\d+(?:\.\d+)?%?)\s+([+-]?\d+(?:\.\d+)?)\s+([+-]?\d+(?:\.\d+)?)(?:\s+[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,
487
+ // HSV pattern
488
+ HSV: /^hsv\(\s*(\d+(?:\.\d+)?)(?:deg|rad|grad|turn)?\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,
489
+ // CMYK pattern
490
+ CMYK: /^cmyk\(\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,
491
+ // CSS color() function
492
+ COLOR_FUNCTION: /^color\(\s*([a-z]+)\s+((?:\d+(?:\.\d+)?%?\s+)*\d+(?:\.\d+)?%?)(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,
493
+ // Lab color
494
+ LAB: /^lab\(\s*(\d+(?:\.\d+)?%?)\s+([+-]?\d+(?:\.\d+)?)\s+([+-]?\d+(?:\.\d+)?)(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i,
495
+ // LCH color
496
+ LCH: /^lch\(\s*(\d+(?:\.\d+)?%?)\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)(?:\s*[,\s/]\s*(\d*\.?\d+%?))?\s*\)$/i
497
+ };
498
+ var parseColor = (color) => {
499
+ if (!color || typeof color !== "string") {
500
+ return null;
501
+ }
502
+ const str = color.trim().toLowerCase();
503
+ if (!str) {
504
+ return null;
505
+ }
506
+ if (str === "transparent") {
507
+ return [0, 0, 0, 0];
508
+ }
509
+ const namedColor = str;
510
+ if (NAMED_COLORS[namedColor]) {
511
+ return parseColor(NAMED_COLORS[namedColor]);
512
+ }
513
+ const rgba = parseRgbaColor(str);
514
+ if (rgba) {
515
+ return rgba;
516
+ }
517
+ const hexMatch = str.match(COLOR_PATTERNS.HEX);
518
+ if (hexMatch) {
519
+ let hex = hexMatch[1];
520
+ if (hex.length === 3 || hex.length === 4) {
521
+ hex = hex.split("").map((c) => c + c).join("");
522
+ }
523
+ const r = parseInt(hex.substring(0, 2), 16);
524
+ const g = parseInt(hex.substring(2, 4), 16);
525
+ const b = parseInt(hex.substring(4, 6), 16);
526
+ const a = hex.length === 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
527
+ if (!isNaN(r) && !isNaN(g) && !isNaN(b) && !isNaN(a)) {
528
+ return [r, g, b, a];
529
+ }
530
+ }
531
+ const hslMatch = str.match(COLOR_PATTERNS.HSL);
532
+ if (hslMatch) {
533
+ const h = parseFloat(hslMatch[1]);
534
+ const s = parseFloat(hslMatch[2]) / 100;
535
+ const l = parseFloat(hslMatch[3]) / 100;
536
+ const a = hslMatch[4] ? parsePercentage(hslMatch[4]) : 1;
537
+ if (!isNaN(h) && !isNaN(s) && !isNaN(l) && !isNaN(a)) {
538
+ return hslToRgb(h, s, l, a);
539
+ }
540
+ }
541
+ const oklchMatch = str.match(COLOR_PATTERNS.OKLCH);
542
+ if (oklchMatch) {
543
+ const L = parsePercentage(oklchMatch[1]);
544
+ const C = parseFloat(oklchMatch[2]);
545
+ const H = parseFloat(oklchMatch[3]);
546
+ const a = oklchMatch[4] ? parsePercentage(oklchMatch[4]) : 1;
547
+ if (!isNaN(L) && !isNaN(C) && !isNaN(H) && !isNaN(a)) {
548
+ return oklchToRgb(L, C, H, a);
549
+ }
550
+ }
551
+ return null;
552
+ };
553
+ var hslToRgb = (h, s, l, a = 1) => {
554
+ h = h % 360;
555
+ if (h < 0) h += 360;
556
+ const c = (1 - Math.abs(2 * l - 1)) * s;
557
+ const x = c * (1 - Math.abs(h / 60 % 2 - 1));
558
+ const m = l - c / 2;
559
+ let r = 0, g = 0, b = 0;
560
+ if (h >= 0 && h < 60) {
561
+ [r, g, b] = [c, x, 0];
562
+ } else if (h >= 60 && h < 120) {
563
+ [r, g, b] = [x, c, 0];
564
+ } else if (h >= 120 && h < 180) {
565
+ [r, g, b] = [0, c, x];
566
+ } else if (h >= 180 && h < 240) {
567
+ [r, g, b] = [0, x, c];
568
+ } else if (h >= 240 && h < 300) {
569
+ [r, g, b] = [x, 0, c];
570
+ } else if (h >= 300 && h < 360) {
571
+ [r, g, b] = [c, 0, x];
572
+ }
573
+ return [
574
+ Math.round((r + m) * 255),
575
+ Math.round((g + m) * 255),
576
+ Math.round((b + m) * 255),
577
+ a
578
+ ];
579
+ };
580
+ var oklchToRgb = (L, C, H, a = 1) => {
581
+ const hue = H % 360;
582
+ const saturation = Math.min(100, C * 100);
583
+ const lightness = L * 100;
584
+ return hslToRgb(hue, saturation / 100, lightness / 100, a);
585
+ };
586
+ var formatRgba = (r, g, b, a = 1) => {
587
+ const isVariable = (value) => typeof value === "string" && value.includes("var(");
588
+ const isAlphaVariable = isVariable(a);
589
+ const hasAlpha = isAlphaVariable || typeof a === "number" && a !== 1;
590
+ if (hasAlpha) {
591
+ return `rgba(${r} ${g} ${b} / ${a})`;
592
+ }
593
+ return `rgb(${r} ${g} ${b})`;
594
+ };
595
+ var numToHex = (value) => {
596
+ const hex = Math.round(value).toString(16);
597
+ return hex.length === 1 ? `0${hex}` : hex;
598
+ };
599
+ var parsePercentage = (value) => {
600
+ if (value.endsWith("%")) {
601
+ return parseFloat(value) / 100;
602
+ }
603
+ return parseFloat(value);
604
+ };
605
+ var isValidColor = (color) => {
606
+ if (color.toLowerCase() in NAMED_COLORS) {
607
+ return true;
608
+ }
609
+ if (color.toLowerCase().trim().startsWith("rgb")) {
610
+ return parseRgbaColor(color) !== null;
611
+ }
612
+ const { RGB, ...otherPatterns } = COLOR_PATTERNS;
613
+ return Object.values(otherPatterns).some((pattern) => pattern.test(color));
614
+ };
615
+ var rgbaToHex = (r, g, b, a = 1) => {
616
+ const hex = `#${numToHex(r)}${numToHex(g)}${numToHex(b)}`;
617
+ return a < 1 ? `${hex}${numToHex(Math.round(a * 255))}` : hex;
618
+ };
619
+ var rgbaToHsl = (r, g, b, a = 1) => {
620
+ const rNorm = r / 255;
621
+ const gNorm = g / 255;
622
+ const bNorm = b / 255;
623
+ const max = Math.max(rNorm, gNorm, bNorm);
624
+ const min = Math.min(rNorm, gNorm, bNorm);
625
+ let h = 0;
626
+ let s = 0;
627
+ const l = (max + min) / 2;
628
+ if (max !== min) {
629
+ const d = max - min;
630
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
631
+ switch (max) {
632
+ case rNorm:
633
+ h = (gNorm - bNorm) / d + (gNorm < bNorm ? 6 : 0);
634
+ break;
635
+ case gNorm:
636
+ h = (bNorm - rNorm) / d + 2;
637
+ break;
638
+ case bNorm:
639
+ h = (rNorm - gNorm) / d + 4;
640
+ break;
641
+ }
642
+ h /= 6;
643
+ }
644
+ h = Math.round(h * 360);
645
+ s = Math.round(s * 100);
646
+ const lPercent = Math.round(l * 100);
647
+ if (a === 1) {
648
+ return `hsl(${h}, ${s}%, ${lPercent}%)`;
649
+ }
650
+ return `hsla(${h}, ${s}%, ${lPercent}%, ${a})`;
651
+ };
652
+ var rgbaToHsv = (r, g, b, a = 1) => {
653
+ const rNorm = r / 255;
654
+ const gNorm = g / 255;
655
+ const bNorm = b / 255;
656
+ const max = Math.max(rNorm, gNorm, bNorm);
657
+ const min = Math.min(rNorm, gNorm, bNorm);
658
+ const d = max - min;
659
+ let h = 0;
660
+ if (d !== 0) {
661
+ switch (max) {
662
+ case rNorm:
663
+ h = (gNorm - bNorm) / d + (gNorm < bNorm ? 6 : 0);
664
+ break;
665
+ case gNorm:
666
+ h = (bNorm - rNorm) / d + 2;
667
+ break;
668
+ case bNorm:
669
+ h = (rNorm - gNorm) / d + 4;
670
+ break;
671
+ }
672
+ h /= 6;
673
+ }
674
+ const s = max === 0 ? 0 : d / max;
675
+ const v = max;
676
+ h = Math.round(h * 360);
677
+ const sPercent = Math.round(s * 100);
678
+ const vPercent = Math.round(v * 100);
679
+ if (a === 1) {
680
+ return `hsv(${h}, ${sPercent}%, ${vPercent}%)`;
681
+ }
682
+ return `hsva(${h}, ${sPercent}%, ${vPercent}%, ${a})`;
683
+ };
684
+ var rgbaToCmyk = (r, g, b, a = 1) => {
685
+ if (r === 0 && g === 0 && b === 0) {
686
+ return `cmyk(0%, 0%, 0%, 100%)`;
687
+ }
688
+ const rNorm = r / 255;
689
+ const gNorm = g / 255;
690
+ const bNorm = b / 255;
691
+ const k = 1 - Math.max(rNorm, gNorm, bNorm);
692
+ const c = (1 - rNorm - k) / (1 - k);
693
+ const m = (1 - gNorm - k) / (1 - k);
694
+ const y = (1 - bNorm - k) / (1 - k);
695
+ const cPercent = Math.round(c * 100);
696
+ const mPercent = Math.round(m * 100);
697
+ const yPercent = Math.round(y * 100);
698
+ const kPercent = Math.round(k * 100);
699
+ return `cmyk(${cPercent}%, ${mPercent}%, ${yPercent}%, ${kPercent}%)`;
700
+ };
701
+ var calculateLuminance = (r, g, b) => {
702
+ const [rs, gs, bs] = [r, g, b].map((c) => {
703
+ c = c / 255;
704
+ return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
705
+ });
706
+ return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
707
+ };
708
+ var calculateContrastRatio = (color1, color2) => {
709
+ const rgb1 = parseColor(color1);
710
+ const rgb2 = parseColor(color2);
711
+ if (!rgb1 || !rgb2) {
712
+ return 1;
713
+ }
714
+ const l1 = calculateLuminance(rgb1[0], rgb1[1], rgb1[2]);
715
+ const l2 = calculateLuminance(rgb2[0], rgb2[1], rgb2[2]);
716
+ const lighter = Math.max(l1, l2);
717
+ const darker = Math.min(l1, l2);
718
+ return (lighter + 0.05) / (darker + 0.05);
719
+ };
720
+ var adjustColor = (color, options) => {
721
+ const rgb = parseColor(color);
722
+ if (!rgb) return color;
723
+ let [r, g, b, a] = rgb;
724
+ if (options.alpha !== void 0) {
725
+ a = Math.max(0, Math.min(1, options.alpha));
726
+ }
727
+ let h = 0, s = 0, l = 0;
728
+ if (options.lightness !== void 0 || options.saturation !== void 0 || options.hue !== void 0) {
729
+ const rNorm = r / 255;
730
+ const gNorm = g / 255;
731
+ const bNorm = b / 255;
732
+ const max = Math.max(rNorm, gNorm, bNorm);
733
+ const min = Math.min(rNorm, gNorm, bNorm);
734
+ l = (max + min) / 2;
735
+ if (max !== min) {
736
+ const d = max - min;
737
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
738
+ switch (max) {
739
+ case rNorm:
740
+ h = (gNorm - bNorm) / d + (gNorm < bNorm ? 6 : 0);
741
+ break;
742
+ case gNorm:
743
+ h = (bNorm - rNorm) / d + 2;
744
+ break;
745
+ case bNorm:
746
+ h = (rNorm - gNorm) / d + 4;
747
+ break;
748
+ }
749
+ h /= 6;
750
+ }
751
+ h *= 360;
752
+ s *= 100;
753
+ l *= 100;
754
+ if (options.hue !== void 0) {
755
+ h = (h + options.hue) % 360;
756
+ if (h < 0) h += 360;
757
+ }
758
+ if (options.saturation !== void 0) {
759
+ s = Math.max(0, Math.min(100, s + options.saturation));
760
+ }
761
+ if (options.lightness !== void 0) {
762
+ l = Math.max(0, Math.min(100, l + options.lightness));
763
+ }
764
+ const hNorm = h / 360;
765
+ const sNorm = s / 100;
766
+ const lNorm = l / 100;
767
+ const chroma = (1 - Math.abs(2 * lNorm - 1)) * sNorm;
768
+ const x = chroma * (1 - Math.abs(hNorm * 6 % 2 - 1));
769
+ const m = lNorm - chroma / 2;
770
+ let rNorm2 = 0, gNorm2 = 0, bNorm2 = 0;
771
+ if (hNorm < 1 / 6) {
772
+ [rNorm2, gNorm2, bNorm2] = [chroma, x, 0];
773
+ } else if (hNorm < 2 / 6) {
774
+ [rNorm2, gNorm2, bNorm2] = [x, chroma, 0];
775
+ } else if (hNorm < 3 / 6) {
776
+ [rNorm2, gNorm2, bNorm2] = [0, chroma, x];
777
+ } else if (hNorm < 4 / 6) {
778
+ [rNorm2, gNorm2, bNorm2] = [0, x, chroma];
779
+ } else if (hNorm < 5 / 6) {
780
+ [rNorm2, gNorm2, bNorm2] = [x, 0, chroma];
781
+ } else {
782
+ [rNorm2, gNorm2, bNorm2] = [chroma, 0, x];
783
+ }
784
+ r = Math.round((rNorm2 + m) * 255);
785
+ g = Math.round((gNorm2 + m) * 255);
786
+ b = Math.round((bNorm2 + m) * 255);
787
+ }
788
+ if (options.contrast !== void 0) {
789
+ const factor = options.contrast / 100 * 2.55;
790
+ const avg = (r + g + b) / 3;
791
+ r = Math.round(avg + (r - avg) * (1 + factor));
792
+ g = Math.round(avg + (g - avg) * (1 + factor));
793
+ b = Math.round(avg + (b - avg) * (1 + factor));
794
+ r = Math.max(0, Math.min(255, r));
795
+ g = Math.max(0, Math.min(255, g));
796
+ b = Math.max(0, Math.min(255, b));
797
+ }
798
+ return rgbaToHex(r, g, b, a);
799
+ };
800
+ var mixColors = (options) => {
801
+ const {
802
+ color,
803
+ with: mixColor = "transparent",
804
+ percentage = 50,
805
+ colorSpace = "srgb"
806
+ } = options;
807
+ const rgb1 = parseColor(color);
808
+ const rgb2 = parseColor(mixColor);
809
+ if (!rgb1 || !rgb2) {
810
+ return color;
811
+ }
812
+ const factor = percentage / 100;
813
+ let [r1, g1, b1, a1] = rgb1;
814
+ let [r2, g2, b2, a2] = rgb2;
815
+ if (options.opacity !== void 0) {
816
+ a1 = typeof options.opacity === "number" ? options.opacity : parsePercentage(options.opacity);
817
+ }
818
+ if (options.withOpacity !== void 0) {
819
+ a2 = typeof options.withOpacity === "number" ? options.withOpacity : parsePercentage(options.withOpacity);
820
+ }
821
+ switch (colorSpace) {
822
+ case "srgb":
823
+ default:
824
+ const r = Math.round(r1 + (r2 - r1) * factor);
825
+ const g = Math.round(g1 + (g2 - g1) * factor);
826
+ const b = Math.round(b1 + (b2 - b1) * factor);
827
+ const a = a1 + (a2 - a1) * factor;
828
+ return rgbaToHex(r, g, b, a);
829
+ case "hsl":
830
+ const hsl1 = parseColor(rgbaToHsl(r1, g1, b1, a1));
831
+ const hsl2 = parseColor(rgbaToHsl(r2, g2, b2, a2));
832
+ if (!hsl1 || !hsl2) {
833
+ return color;
834
+ }
835
+ const h = (hsl1[0] + (hsl2[0] - hsl1[0]) * factor) % 360;
836
+ const s = hsl1[1] + (hsl2[1] - hsl1[1]) * factor;
837
+ const l = hsl1[2] + (hsl2[2] - hsl1[2]) * factor;
838
+ return `hsl(${h}, ${s}%, ${l}%)`;
839
+ }
840
+ };
841
+ var generatePalette = (baseColor, options = {}) => {
842
+ const rgb = parseColor(baseColor);
843
+ if (!rgb) return {};
844
+ const shades = options.shades || 10;
845
+ const lightnessFactor = options.lightnessFactor || 0.1;
846
+ const saturationFactor = options.saturationFactor || 0.05;
847
+ const palette = {};
848
+ for (let i = 0; i < shades; i++) {
849
+ const position = i / (shades - 1);
850
+ const lightnessAdjustment = (position - 0.5) * 2 * lightnessFactor * 100;
851
+ const shadeColor = adjustColor(baseColor, {
852
+ lightness: lightnessAdjustment,
853
+ saturation: (position - 0.5) * 2 * saturationFactor * 100
854
+ });
855
+ const key = i === 0 ? "50" : `${i * 100}`;
856
+ palette[key] = shadeColor;
857
+ }
858
+ if (options.includeComplementary) {
859
+ const hsl = parseColor(rgbaToHsl(rgb[0], rgb[1], rgb[2]));
860
+ if (hsl) {
861
+ let h = hsl[0];
862
+ h = (h + 180) % 360;
863
+ palette.complementary = `hsl(${h}, ${hsl[1]}%, ${hsl[2]}%)`;
864
+ }
865
+ }
866
+ if (options.includeAnalogous) {
867
+ const hsl = parseColor(rgbaToHsl(rgb[0], rgb[1], rgb[2]));
868
+ if (hsl) {
869
+ let h = hsl[0];
870
+ palette.analogous1 = `hsl(${(h - 30 + 360) % 360}, ${hsl[1]}%, ${hsl[2]}%)`;
871
+ palette.analogous2 = `hsl(${(h + 30) % 360}, ${hsl[1]}%, ${hsl[2]}%)`;
872
+ }
873
+ }
874
+ if (options.includeTriadic) {
875
+ const hsl = parseColor(rgbaToHsl(rgb[0], rgb[1], rgb[2]));
876
+ if (hsl) {
877
+ let h = hsl[0];
878
+ palette.triadic1 = `hsl(${(h + 120) % 360}, ${hsl[1]}%, ${hsl[2]}%)`;
879
+ palette.triadic2 = `hsl(${(h + 240) % 360}, ${hsl[1]}%, ${hsl[2]}%)`;
880
+ }
881
+ }
882
+ return palette;
883
+ };
884
+ var createContrastColor = (color, options = {}) => {
885
+ const {
886
+ lightColor = "#ffffff",
887
+ darkColor = "#000000",
888
+ targetRatio = 4.5,
889
+ fallbackColor = "#000000"
890
+ } = options;
891
+ const rgb = parseColor(color);
892
+ if (!rgb) return fallbackColor;
893
+ const luminance = calculateLuminance(rgb[0], rgb[1], rgb[2]);
894
+ const lightLuminance = calculateLuminance(
895
+ ...parseColor(lightColor).slice(0, 3)
896
+ );
897
+ const darkLuminance = calculateLuminance(
898
+ ...parseColor(darkColor).slice(0, 3)
899
+ );
900
+ const lightContrast = (Math.max(luminance, lightLuminance) + 0.05) / (Math.min(luminance, lightLuminance) + 0.05);
901
+ const darkContrast = (Math.max(luminance, darkLuminance) + 0.05) / (Math.min(luminance, darkLuminance) + 0.05);
902
+ if (lightContrast >= targetRatio && darkContrast >= targetRatio) {
903
+ return lightContrast > darkContrast ? lightColor : darkColor;
904
+ } else if (lightContrast >= targetRatio) {
905
+ return lightColor;
906
+ } else if (darkContrast >= targetRatio) {
907
+ return darkColor;
908
+ }
909
+ return lightContrast > darkContrast ? lightColor : darkColor;
910
+ };
911
+
912
+ // src/lib/color/conversions.ts
913
+ var D65_WHITE = { x: 0.95047, y: 1, z: 1.08883 };
914
+ var EPSILON = 8856e-6;
915
+ var KAPPA = 903.3;
916
+ function clamp(value, min, max) {
917
+ return Math.max(min, Math.min(max, value));
918
+ }
919
+ function roundToPrecision(value, precision = 2) {
920
+ const multiplier = Math.pow(10, precision);
921
+ return Math.round(value * multiplier) / multiplier;
922
+ }
923
+ function rgbToHsl(rgb) {
924
+ const r = rgb.r / 255;
925
+ const g = rgb.g / 255;
926
+ const b = rgb.b / 255;
927
+ const max = Math.max(r, g, b);
928
+ const min = Math.min(r, g, b);
929
+ const delta = max - min;
930
+ let h = 0;
931
+ let s = 0;
932
+ const l = (max + min) / 2;
933
+ if (delta !== 0) {
934
+ s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min);
935
+ switch (max) {
936
+ case r:
937
+ h = ((g - b) / delta + (g < b ? 6 : 0)) / 6;
938
+ break;
939
+ case g:
940
+ h = ((b - r) / delta + 2) / 6;
941
+ break;
942
+ case b:
943
+ h = ((r - g) / delta + 4) / 6;
944
+ break;
945
+ }
946
+ }
947
+ return {
948
+ h: h * 360,
949
+ s: s * 100,
950
+ l: l * 100,
951
+ a: rgb.a
952
+ };
953
+ }
954
+ function rgbToHsv(rgb) {
955
+ const r = rgb.r / 255;
956
+ const g = rgb.g / 255;
957
+ const b = rgb.b / 255;
958
+ const max = Math.max(r, g, b);
959
+ const min = Math.min(r, g, b);
960
+ const delta = max - min;
961
+ let h = 0;
962
+ const s = max === 0 ? 0 : delta / max;
963
+ const v = max;
964
+ if (delta !== 0) {
965
+ switch (max) {
966
+ case r:
967
+ h = ((g - b) / delta + (g < b ? 6 : 0)) / 6;
968
+ break;
969
+ case g:
970
+ h = ((b - r) / delta + 2) / 6;
971
+ break;
972
+ case b:
973
+ h = ((r - g) / delta + 4) / 6;
974
+ break;
975
+ }
976
+ }
977
+ return {
978
+ h: h * 360,
979
+ s: s * 100,
980
+ v: v * 100,
981
+ a: rgb.a
982
+ };
983
+ }
984
+ function rgbToHwb(rgb) {
985
+ const hsv = rgbToHsv(rgb);
986
+ const w = (100 - hsv.s) * hsv.v / 100;
987
+ const b = 100 - hsv.v;
988
+ return {
989
+ h: hsv.h,
990
+ w,
991
+ b,
992
+ a: rgb.a
993
+ };
994
+ }
995
+ function rgbToCmyk(rgb) {
996
+ const r = rgb.r / 255;
997
+ const g = rgb.g / 255;
998
+ const b = rgb.b / 255;
999
+ const k = 1 - Math.max(r, g, b);
1000
+ const c = k === 1 ? 0 : (1 - r - k) / (1 - k);
1001
+ const m = k === 1 ? 0 : (1 - g - k) / (1 - k);
1002
+ const y = k === 1 ? 0 : (1 - b - k) / (1 - k);
1003
+ return {
1004
+ c: c * 100,
1005
+ m: m * 100,
1006
+ y: y * 100,
1007
+ k: k * 100,
1008
+ a: rgb.a
1009
+ };
1010
+ }
1011
+ function rgbToXyz(rgb) {
1012
+ let r = rgb.r / 255;
1013
+ let g = rgb.g / 255;
1014
+ let b = rgb.b / 255;
1015
+ r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
1016
+ g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
1017
+ b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
1018
+ const x = r * 0.4124564 + g * 0.3575761 + b * 0.1804375;
1019
+ const y = r * 0.2126729 + g * 0.7151522 + b * 0.072175;
1020
+ const z = r * 0.0193339 + g * 0.119192 + b * 0.9503041;
1021
+ return {
1022
+ x: x * 100,
1023
+ y: y * 100,
1024
+ z: z * 100,
1025
+ alpha: rgb.a
1026
+ };
1027
+ }
1028
+ function rgbToLab(rgb) {
1029
+ const xyz = rgbToXyz(rgb);
1030
+ return xyzToLab(xyz);
1031
+ }
1032
+ function rgbToLch(rgb) {
1033
+ const lab = rgbToLab(rgb);
1034
+ return labToLch(lab);
1035
+ }
1036
+ function rgbToOklab(rgb) {
1037
+ const r = rgb.r / 255;
1038
+ const g = rgb.g / 255;
1039
+ const b = rgb.b / 255;
1040
+ const lr = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
1041
+ const lg = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
1042
+ const lb = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
1043
+ const l = 0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb;
1044
+ const m = 0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb;
1045
+ const s = 0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb;
1046
+ const l_ = Math.cbrt(l);
1047
+ const m_ = Math.cbrt(m);
1048
+ const s_ = Math.cbrt(s);
1049
+ return {
1050
+ l: 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_,
1051
+ a: 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_,
1052
+ b: 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_,
1053
+ alpha: rgb.a
1054
+ };
1055
+ }
1056
+ function rgbToOklch(rgb) {
1057
+ const oklab = rgbToOklab(rgb);
1058
+ return oklabToOklch(oklab);
1059
+ }
1060
+ function hslToRgb2(hsl) {
1061
+ const h = hsl.h / 360;
1062
+ const s = hsl.s / 100;
1063
+ const l = hsl.l / 100;
1064
+ let r, g, b;
1065
+ if (s === 0) {
1066
+ r = g = b = l;
1067
+ } else {
1068
+ const hue2rgb = (p2, q2, t) => {
1069
+ if (t < 0) t += 1;
1070
+ if (t > 1) t -= 1;
1071
+ if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
1072
+ if (t < 1 / 2) return q2;
1073
+ if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
1074
+ return p2;
1075
+ };
1076
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
1077
+ const p = 2 * l - q;
1078
+ r = hue2rgb(p, q, h + 1 / 3);
1079
+ g = hue2rgb(p, q, h);
1080
+ b = hue2rgb(p, q, h - 1 / 3);
1081
+ }
1082
+ return {
1083
+ r: Math.round(r * 255),
1084
+ g: Math.round(g * 255),
1085
+ b: Math.round(b * 255),
1086
+ a: hsl.a
1087
+ };
1088
+ }
1089
+ function hslToHsv(hsl) {
1090
+ const rgb = hslToRgb2(hsl);
1091
+ return rgbToHsv(rgb);
1092
+ }
1093
+ function hslToHwb(hsl) {
1094
+ const rgb = hslToRgb2(hsl);
1095
+ return rgbToHwb(rgb);
1096
+ }
1097
+ function hsvToRgb(hsv) {
1098
+ const h = hsv.h / 360;
1099
+ const s = hsv.s / 100;
1100
+ const v = hsv.v / 100;
1101
+ const i = Math.floor(h * 6);
1102
+ const f = h * 6 - i;
1103
+ const p = v * (1 - s);
1104
+ const q = v * (1 - f * s);
1105
+ const t = v * (1 - (1 - f) * s);
1106
+ let r, g, b;
1107
+ switch (i % 6) {
1108
+ case 0:
1109
+ r = v;
1110
+ g = t;
1111
+ b = p;
1112
+ break;
1113
+ case 1:
1114
+ r = q;
1115
+ g = v;
1116
+ b = p;
1117
+ break;
1118
+ case 2:
1119
+ r = p;
1120
+ g = v;
1121
+ b = t;
1122
+ break;
1123
+ case 3:
1124
+ r = p;
1125
+ g = q;
1126
+ b = v;
1127
+ break;
1128
+ case 4:
1129
+ r = t;
1130
+ g = p;
1131
+ b = v;
1132
+ break;
1133
+ case 5:
1134
+ default:
1135
+ r = v;
1136
+ g = p;
1137
+ b = q;
1138
+ break;
1139
+ }
1140
+ return {
1141
+ r: Math.round(r * 255),
1142
+ g: Math.round(g * 255),
1143
+ b: Math.round(b * 255),
1144
+ a: hsv.a
1145
+ };
1146
+ }
1147
+ function hsvToHsl(hsv) {
1148
+ const rgb = hsvToRgb(hsv);
1149
+ return rgbToHsl(rgb);
1150
+ }
1151
+ function hsvToHwb(hsv) {
1152
+ const w = (100 - hsv.s) * hsv.v / 100;
1153
+ const b = 100 - hsv.v;
1154
+ return {
1155
+ h: hsv.h,
1156
+ w,
1157
+ b,
1158
+ a: hsv.a
1159
+ };
1160
+ }
1161
+ function hwbToRgb(hwb) {
1162
+ const h = hwb.h;
1163
+ let w = hwb.w / 100;
1164
+ let b = hwb.b / 100;
1165
+ const sum = w + b;
1166
+ if (sum > 1) {
1167
+ w /= sum;
1168
+ b /= sum;
1169
+ }
1170
+ const v = 1 - b;
1171
+ const s = v === 0 ? 0 : 1 - w / v;
1172
+ return hsvToRgb({ h, s: s * 100, v: v * 100, a: hwb.a });
1173
+ }
1174
+ function hwbToHsl(hwb) {
1175
+ const rgb = hwbToRgb(hwb);
1176
+ return rgbToHsl(rgb);
1177
+ }
1178
+ function hwbToHsv(hwb) {
1179
+ const rgb = hwbToRgb(hwb);
1180
+ return rgbToHsv(rgb);
1181
+ }
1182
+ function cmykToRgb(cmyk) {
1183
+ const c = cmyk.c / 100;
1184
+ const m = cmyk.m / 100;
1185
+ const y = cmyk.y / 100;
1186
+ const k = cmyk.k / 100;
1187
+ const r = 255 * (1 - c) * (1 - k);
1188
+ const g = 255 * (1 - m) * (1 - k);
1189
+ const b = 255 * (1 - y) * (1 - k);
1190
+ return {
1191
+ r: Math.round(r),
1192
+ g: Math.round(g),
1193
+ b: Math.round(b),
1194
+ a: cmyk.a
1195
+ };
1196
+ }
1197
+ function cmykToHsl(cmyk) {
1198
+ const rgb = cmykToRgb(cmyk);
1199
+ return rgbToHsl(rgb);
1200
+ }
1201
+ function cmykToHsv(cmyk) {
1202
+ const rgb = cmykToRgb(cmyk);
1203
+ return rgbToHsv(rgb);
1204
+ }
1205
+ function xyzToRgb(xyz) {
1206
+ const x = xyz.x / 100;
1207
+ const y = xyz.y / 100;
1208
+ const z = xyz.z / 100;
1209
+ let r = x * 3.2404542 + y * -1.5371385 + z * -0.4985314;
1210
+ let g = x * -0.969266 + y * 1.8760108 + z * 0.041556;
1211
+ let b = x * 0.0556434 + y * -0.2040259 + z * 1.0572252;
1212
+ r = r > 31308e-7 ? 1.055 * Math.pow(r, 1 / 2.4) - 0.055 : 12.92 * r;
1213
+ g = g > 31308e-7 ? 1.055 * Math.pow(g, 1 / 2.4) - 0.055 : 12.92 * g;
1214
+ b = b > 31308e-7 ? 1.055 * Math.pow(b, 1 / 2.4) - 0.055 : 12.92 * b;
1215
+ return {
1216
+ r: Math.round(clamp(r * 255, 0, 255)),
1217
+ g: Math.round(clamp(g * 255, 0, 255)),
1218
+ b: Math.round(clamp(b * 255, 0, 255)),
1219
+ a: xyz.alpha || 1
1220
+ };
1221
+ }
1222
+ function xyzToLab(xyz) {
1223
+ const xr = xyz.x / D65_WHITE.x / 100;
1224
+ const yr = xyz.y / D65_WHITE.y / 100;
1225
+ const zr = xyz.z / D65_WHITE.z / 100;
1226
+ const fx = xr > EPSILON ? Math.cbrt(xr) : (KAPPA * xr + 16) / 116;
1227
+ const fy = yr > EPSILON ? Math.cbrt(yr) : (KAPPA * yr + 16) / 116;
1228
+ const fz = zr > EPSILON ? Math.cbrt(zr) : (KAPPA * zr + 16) / 116;
1229
+ const l = 116 * fy - 16;
1230
+ const a = 500 * (fx - fy);
1231
+ const b = 200 * (fy - fz);
1232
+ return {
1233
+ l: clamp(l, 0, 100),
1234
+ a,
1235
+ b,
1236
+ alpha: xyz.alpha
1237
+ };
1238
+ }
1239
+ function labToXyz(lab) {
1240
+ const fy = (lab.l + 16) / 116;
1241
+ const fx = lab.a / 500 + fy;
1242
+ const fz = fy - lab.b / 200;
1243
+ const xr = fx * fx * fx > EPSILON ? fx * fx * fx : (116 * fx - 16) / KAPPA;
1244
+ const yr = lab.l > KAPPA * EPSILON ? Math.pow((lab.l + 16) / 116, 3) : lab.l / KAPPA;
1245
+ const zr = fz * fz * fz > EPSILON ? fz * fz * fz : (116 * fz - 16) / KAPPA;
1246
+ return {
1247
+ x: xr * D65_WHITE.x * 100,
1248
+ y: yr * D65_WHITE.y * 100,
1249
+ z: zr * D65_WHITE.z * 100,
1250
+ alpha: lab.alpha
1251
+ };
1252
+ }
1253
+ function labToRgb(lab) {
1254
+ const xyz = labToXyz(lab);
1255
+ return xyzToRgb(xyz);
1256
+ }
1257
+ function labToLch(lab) {
1258
+ const c = Math.sqrt(lab.a * lab.a + lab.b * lab.b);
1259
+ let h = Math.atan2(lab.b, lab.a) * 180 / Math.PI;
1260
+ if (h < 0) {
1261
+ h += 360;
1262
+ }
1263
+ return {
1264
+ l: lab.l,
1265
+ c,
1266
+ h,
1267
+ alpha: lab.alpha
1268
+ };
1269
+ }
1270
+ function lchToLab(lch) {
1271
+ const h = lch.h * Math.PI / 180;
1272
+ const a = lch.c * Math.cos(h);
1273
+ const b = lch.c * Math.sin(h);
1274
+ return {
1275
+ l: lch.l,
1276
+ a,
1277
+ b,
1278
+ alpha: lch.alpha
1279
+ };
1280
+ }
1281
+ function lchToRgb(lch) {
1282
+ const lab = lchToLab(lch);
1283
+ return labToRgb(lab);
1284
+ }
1285
+ function lchToXyz(lch) {
1286
+ const lab = lchToLab(lch);
1287
+ return labToXyz(lab);
1288
+ }
1289
+ function oklabToRgb(oklab) {
1290
+ const l_ = oklab.l + 0.3963377774 * oklab.a + 0.2158037573 * oklab.b;
1291
+ const m_ = oklab.l - 0.1055613458 * oklab.a - 0.0638541728 * oklab.b;
1292
+ const s_ = oklab.l - 0.0894841775 * oklab.a - 1.291485548 * oklab.b;
1293
+ const l = l_ * l_ * l_;
1294
+ const m = m_ * m_ * m_;
1295
+ const s = s_ * s_ * s_;
1296
+ let lr = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s;
1297
+ let lg = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s;
1298
+ let lb = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s;
1299
+ lr = lr > 31308e-7 ? 1.055 * Math.pow(lr, 1 / 2.4) - 0.055 : 12.92 * lr;
1300
+ lg = lg > 31308e-7 ? 1.055 * Math.pow(lg, 1 / 2.4) - 0.055 : 12.92 * lg;
1301
+ lb = lb > 31308e-7 ? 1.055 * Math.pow(lb, 1 / 2.4) - 0.055 : 12.92 * lb;
1302
+ return {
1303
+ r: Math.round(clamp(lr * 255, 0, 255)),
1304
+ g: Math.round(clamp(lg * 255, 0, 255)),
1305
+ b: Math.round(clamp(lb * 255, 0, 255)),
1306
+ a: oklab.alpha
1307
+ };
1308
+ }
1309
+ function oklabToOklch(oklab) {
1310
+ const c = Math.sqrt(oklab.a * oklab.a + oklab.b * oklab.b);
1311
+ let h = Math.atan2(oklab.b, oklab.a) * 180 / Math.PI;
1312
+ if (h < 0) {
1313
+ h += 360;
1314
+ }
1315
+ return {
1316
+ l: oklab.l,
1317
+ c,
1318
+ h,
1319
+ alpha: oklab.alpha
1320
+ };
1321
+ }
1322
+ function oklchToOklab(oklch) {
1323
+ const h = oklch.h * Math.PI / 180;
1324
+ const a = oklch.c * Math.cos(h);
1325
+ const b = oklch.c * Math.sin(h);
1326
+ return {
1327
+ l: oklch.l,
1328
+ a,
1329
+ b,
1330
+ alpha: oklch.alpha
1331
+ };
1332
+ }
1333
+ function oklchToRgb2(oklch) {
1334
+ const oklab = oklchToOklab(oklch);
1335
+ return oklabToRgb(oklab);
1336
+ }
1337
+ function anyToRgb(color) {
1338
+ if ("r" in color && "g" in color && "b" in color) {
1339
+ return color;
1340
+ }
1341
+ if ("h" in color && "s" in color && "l" in color) {
1342
+ return hslToRgb2(color);
1343
+ }
1344
+ if ("h" in color && "s" in color && "v" in color) {
1345
+ return hsvToRgb(color);
1346
+ }
1347
+ if ("h" in color && "w" in color && "b" in color) {
1348
+ return hwbToRgb(color);
1349
+ }
1350
+ if ("c" in color && "m" in color && "y" in color && "k" in color) {
1351
+ return cmykToRgb(color);
1352
+ }
1353
+ if ("x" in color && "y" in color && "z" in color) {
1354
+ return xyzToRgb(color);
1355
+ }
1356
+ if ("l" in color && "a" in color && "b" in color && !("c" in color) && !("h" in color)) {
1357
+ return labToRgb(color);
1358
+ }
1359
+ if ("l" in color && "c" in color && "h" in color) {
1360
+ const lchColor = color;
1361
+ if (lchColor.l <= 1) {
1362
+ return oklchToRgb2(color);
1363
+ }
1364
+ return lchToRgb(lchColor);
1365
+ }
1366
+ throw new Error("Unknown color format");
1367
+ }
1368
+ function convertColor(color, targetFormat, options = {}) {
1369
+ const { round = true, precision = 2, preserveAlpha = true } = options;
1370
+ const rgb = anyToRgb(color);
1371
+ let result;
1372
+ switch (targetFormat.toLowerCase()) {
1373
+ case "rgb":
1374
+ result = rgb;
1375
+ break;
1376
+ case "hsl":
1377
+ result = rgbToHsl(rgb);
1378
+ break;
1379
+ case "hsv":
1380
+ result = rgbToHsv(rgb);
1381
+ break;
1382
+ case "hwb":
1383
+ result = rgbToHwb(rgb);
1384
+ break;
1385
+ case "cmyk":
1386
+ result = rgbToCmyk(rgb);
1387
+ break;
1388
+ case "xyz":
1389
+ result = rgbToXyz(rgb);
1390
+ break;
1391
+ case "lab":
1392
+ result = rgbToLab(rgb);
1393
+ break;
1394
+ case "lch":
1395
+ result = rgbToLch(rgb);
1396
+ break;
1397
+ case "oklab":
1398
+ result = rgbToOklab(rgb);
1399
+ break;
1400
+ case "oklch":
1401
+ result = rgbToOklch(rgb);
1402
+ break;
1403
+ default:
1404
+ result = rgb;
1405
+ }
1406
+ if (round && result) {
1407
+ Object.keys(result).forEach((key) => {
1408
+ if (typeof result[key] === "number" && key !== "a" && key !== "alpha") {
1409
+ result[key] = roundToPrecision(result[key], precision);
1410
+ }
1411
+ });
1412
+ }
1413
+ if (!preserveAlpha) {
1414
+ delete result.a;
1415
+ delete result.alpha;
1416
+ }
1417
+ return result;
1418
+ }
1419
+ function batchConvert(colors, targetFormat, options = {}) {
1420
+ return colors.map((color) => convertColor(color, targetFormat, options));
1421
+ }
1422
+ function getConversionPath(from, to) {
1423
+ const directConversions = {
1424
+ rgb: ["hsl", "hsv", "hwb", "cmyk", "xyz", "lab", "lch", "oklab", "oklch"],
1425
+ hsl: ["rgb", "hsv", "hwb"],
1426
+ hsv: ["rgb", "hsl", "hwb"],
1427
+ hwb: ["rgb", "hsl", "hsv"],
1428
+ cmyk: ["rgb", "hsl", "hsv"],
1429
+ xyz: ["rgb", "lab"],
1430
+ lab: ["rgb", "xyz", "lch"],
1431
+ lch: ["rgb", "lab", "xyz"],
1432
+ oklab: ["rgb", "oklch"],
1433
+ oklch: ["rgb", "oklab"]
1434
+ };
1435
+ from = from.toLowerCase();
1436
+ to = to.toLowerCase();
1437
+ if (from === to) {
1438
+ return [from];
1439
+ }
1440
+ if (directConversions[from]?.includes(to)) {
1441
+ return [from, to];
1442
+ }
1443
+ if (directConversions[from]?.includes("rgb") && directConversions["rgb"]?.includes(to)) {
1444
+ return [from, "rgb", to];
1445
+ }
1446
+ if (["lab", "lch"].includes(from) && ["lab", "lch"].includes(to) && from !== to) {
1447
+ return [from, "xyz", to];
1448
+ }
1449
+ if (["oklab", "oklch"].includes(from) && ["oklab", "oklch"].includes(to) && from !== to) {
1450
+ return [from, "oklab", to];
1451
+ }
1452
+ if (directConversions[from] && directConversions["rgb"]?.includes(to)) {
1453
+ return [from, "rgb", to];
1454
+ }
1455
+ return null;
1456
+ }
1457
+ function hasDirectConversion(from, to) {
1458
+ const path = getConversionPath(from, to);
1459
+ return path !== null && path.length <= 2;
1460
+ }
1461
+ function getSupportedFormats() {
1462
+ return [
1463
+ "rgb",
1464
+ "hsl",
1465
+ "hsv",
1466
+ "hwb",
1467
+ "cmyk",
1468
+ "xyz",
1469
+ "lab",
1470
+ "lch",
1471
+ "oklab",
1472
+ "oklch"
1473
+ ];
1474
+ }
1475
+ function isValidFormat(format) {
1476
+ return getSupportedFormats().includes(format.toLowerCase());
1477
+ }
1478
+
1479
+ // src/lib/color/color.ts
1480
+ var Color = class _Color {
1481
+ /**
1482
+ * Creates a new Color instance
1483
+ * @param color - Color representation (string, array, object, or another Color)
1484
+ */
1485
+ constructor(color = "#000000") {
1486
+ this._r = 0;
1487
+ this._g = 0;
1488
+ this._b = 0;
1489
+ this._a = 1;
1490
+ this.set(color);
1491
+ }
1492
+ /**
1493
+ * Parse any RGB/RGBA format
1494
+ */
1495
+ static parseRgbString(colorString) {
1496
+ return parseRgbaColor(colorString);
1497
+ }
1498
+ /**
1499
+ * Check if string matches any RGB pattern
1500
+ */
1501
+ static isRgbFormat(colorString) {
1502
+ return Object.values(RGB_PATTERNS).some(
1503
+ (pattern) => pattern.test(colorString.trim())
1504
+ );
1505
+ }
1506
+ /**
1507
+ * Get the specific RGB pattern that matches
1508
+ */
1509
+ static getRgbPatternMatch(colorString) {
1510
+ const str = colorString.trim();
1511
+ for (const [name, pattern] of Object.entries(RGB_PATTERNS)) {
1512
+ if (pattern.test(str)) {
1513
+ return name;
1514
+ }
1515
+ }
1516
+ return null;
1517
+ }
1518
+ /**
1519
+ * Convert RGB values to modern CSS syntax
1520
+ */
1521
+ static toModernRgbSyntax(r, g, b, a) {
1522
+ const components = [r, g, b];
1523
+ if (a !== void 0 && a !== 1) {
1524
+ return `rgb(${components.join(" ")} / ${a})`;
1525
+ }
1526
+ return `rgb(${components.join(" ")})`;
1527
+ }
1528
+ /**
1529
+ * Convert RGB values to legacy syntax
1530
+ */
1531
+ static toLegacyRgbSyntax(r, g, b, a) {
1532
+ const components = [r, g, b];
1533
+ if (a !== void 0 && a !== 1) {
1534
+ return `rgba(${components.join(", ")}, ${a})`;
1535
+ }
1536
+ return `rgb(${components.join(", ")})`;
1537
+ }
1538
+ /**
1539
+ * Normalize RGB string to a consistent format
1540
+ */
1541
+ static normalizeRgbString(colorString, format = "modern") {
1542
+ const rgba = parseRgbaColor(colorString);
1543
+ if (!rgba) return null;
1544
+ const [r, g, b, a] = rgba;
1545
+ if (format === "modern") {
1546
+ return this.toModernRgbSyntax(r, g, b, a);
1547
+ } else {
1548
+ return this.toLegacyRgbSyntax(r, g, b, a);
1549
+ }
1550
+ }
1551
+ /**
1552
+ * Sets the color from any representation
1553
+ * @param color - Color representation
1554
+ * @returns This Color instance for chaining
1555
+ */
1556
+ set(color) {
1557
+ if (typeof color === "string") {
1558
+ const rgb = parseColor(color);
1559
+ if (rgb) {
1560
+ [this._r, this._g, this._b, this._a] = rgb;
1561
+ }
1562
+ } else if (Array.isArray(color)) {
1563
+ [this._r = 0, this._g = 0, this._b = 0, this._a = 1] = color;
1564
+ } else if (color instanceof _Color) {
1565
+ [this._r, this._g, this._b, this._a] = [
1566
+ color._r,
1567
+ color._g,
1568
+ color._b,
1569
+ color._a
1570
+ ];
1571
+ } else if (typeof color === "object") {
1572
+ return this.setFromObject(color);
1573
+ }
1574
+ this._clamp();
1575
+ return this;
1576
+ }
1577
+ /**
1578
+ * Clamps color values to valid ranges
1579
+ * @private
1580
+ */
1581
+ _clamp() {
1582
+ this._r = Math.max(0, Math.min(255, Math.round(this._r)));
1583
+ this._g = Math.max(0, Math.min(255, Math.round(this._g)));
1584
+ this._b = Math.max(0, Math.min(255, Math.round(this._b)));
1585
+ this._a = Math.max(0, Math.min(1, this._a));
1586
+ }
1587
+ /**
1588
+ * Gets the red component
1589
+ */
1590
+ get r() {
1591
+ return this._r;
1592
+ }
1593
+ /**
1594
+ * Sets the red component
1595
+ */
1596
+ set r(value) {
1597
+ this._r = value;
1598
+ this._clamp();
1599
+ }
1600
+ /**
1601
+ * Gets the green component
1602
+ */
1603
+ get g() {
1604
+ return this._g;
1605
+ }
1606
+ /**
1607
+ * Sets the green component
1608
+ */
1609
+ set g(value) {
1610
+ this._g = value;
1611
+ this._clamp();
1612
+ }
1613
+ /**
1614
+ * Gets the blue component
1615
+ */
1616
+ get b() {
1617
+ return this._b;
1618
+ }
1619
+ /**
1620
+ * Sets the blue component
1621
+ */
1622
+ set b(value) {
1623
+ this._b = value;
1624
+ this._clamp();
1625
+ }
1626
+ /**
1627
+ * Gets the alpha component
1628
+ */
1629
+ get a() {
1630
+ return this._a;
1631
+ }
1632
+ /**
1633
+ * Sets the alpha component
1634
+ */
1635
+ set a(value) {
1636
+ this._a = value;
1637
+ this._clamp();
1638
+ }
1639
+ /**
1640
+ * Gets the RGB array
1641
+ */
1642
+ get rgb() {
1643
+ return [this._r, this._g, this._b];
1644
+ }
1645
+ /**
1646
+ * Gets the RGBA array
1647
+ */
1648
+ get rgba() {
1649
+ return [this._r, this._g, this._b, this._a];
1650
+ }
1651
+ /**
1652
+ * Converts to hex string
1653
+ * @returns Hex color string
1654
+ */
1655
+ toHex() {
1656
+ return rgbaToHex(this._r, this._g, this._b, this._a);
1657
+ }
1658
+ /**
1659
+ * Converts to RGB string
1660
+ * @returns RGB color string
1661
+ */
1662
+ toRgb() {
1663
+ return formatRgba(this._r, this._g, this._b);
1664
+ }
1665
+ /**
1666
+ * Converts to RGBA string
1667
+ * @returns RGBA color string
1668
+ */
1669
+ toRgba() {
1670
+ return formatRgba(this._r, this._g, this._b, this._a);
1671
+ }
1672
+ /**
1673
+ * Gets RGB object
1674
+ * @returns RGB color object
1675
+ */
1676
+ getRgbObject() {
1677
+ return { r: this._r, g: this._g, b: this._b, a: this._a };
1678
+ }
1679
+ /**
1680
+ * Converts to HSL string
1681
+ * @returns HSL/HSLA color string
1682
+ */
1683
+ toHsl() {
1684
+ return rgbaToHsl(this._r, this._g, this._b, this._a);
1685
+ }
1686
+ /**
1687
+ * Gets HSL object
1688
+ * @returns HSL color object
1689
+ */
1690
+ getHslObject() {
1691
+ return rgbToHsl(this.getRgbObject());
1692
+ }
1693
+ /**
1694
+ * Converts to HSV string
1695
+ * @returns HSV/HSVA color string
1696
+ */
1697
+ toHsv() {
1698
+ return rgbaToHsv(this._r, this._g, this._b, this._a);
1699
+ }
1700
+ /**
1701
+ * Gets HSV object
1702
+ * @returns HSV color object
1703
+ */
1704
+ getHsvObject() {
1705
+ return rgbToHsv(this.getRgbObject());
1706
+ }
1707
+ /**
1708
+ * Converts to HWB string
1709
+ * @returns HWB color string
1710
+ */
1711
+ toHwb() {
1712
+ const hwb = rgbToHwb(this.getRgbObject());
1713
+ const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : "";
1714
+ return `hwb(${Math.round(hwb.h)} ${Math.round(hwb.w)}% ${Math.round(
1715
+ hwb.b
1716
+ )}%${alphaStr})`;
1717
+ }
1718
+ /**
1719
+ * Gets HWB object
1720
+ * @returns HWB color object
1721
+ */
1722
+ getHwbObject() {
1723
+ return rgbToHwb(this.getRgbObject());
1724
+ }
1725
+ /**
1726
+ * Converts to CMYK string
1727
+ * @returns CMYK color string
1728
+ */
1729
+ toCmyk() {
1730
+ return rgbaToCmyk(this._r, this._g, this._b, this._a);
1731
+ }
1732
+ /**
1733
+ * Gets CMYK object
1734
+ * @returns CMYK color object
1735
+ */
1736
+ getCmykObject() {
1737
+ return rgbToCmyk(this.getRgbObject());
1738
+ }
1739
+ /**
1740
+ * Converts to XYZ string
1741
+ * @returns XYZ color string
1742
+ */
1743
+ toXyz() {
1744
+ const xyz = rgbToXyz(this.getRgbObject());
1745
+ const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : "";
1746
+ return `color(xyz ${xyz.x.toFixed(4)} ${xyz.y.toFixed(4)} ${xyz.z.toFixed(
1747
+ 4
1748
+ )}${alphaStr})`;
1749
+ }
1750
+ /**
1751
+ * Gets XYZ object
1752
+ * @returns XYZ color object
1753
+ */
1754
+ getXyzObject() {
1755
+ return rgbToXyz(this.getRgbObject());
1756
+ }
1757
+ /**
1758
+ * Converts to LAB string
1759
+ * @returns LAB color string
1760
+ */
1761
+ toLab() {
1762
+ const lab = rgbToLab(this.getRgbObject());
1763
+ const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : "";
1764
+ return `lab(${lab.l.toFixed(2)}% ${lab.a.toFixed(2)} ${lab.b.toFixed(
1765
+ 2
1766
+ )}${alphaStr})`;
1767
+ }
1768
+ /**
1769
+ * Gets LAB object
1770
+ * @returns LAB color object
1771
+ */
1772
+ getLabObject() {
1773
+ return rgbToLab(this.getRgbObject());
1774
+ }
1775
+ /**
1776
+ * Converts to LCH string
1777
+ * @returns LCH color string
1778
+ */
1779
+ toLch() {
1780
+ const lch = rgbToLch(this.getRgbObject());
1781
+ const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : "";
1782
+ return `lch(${lch.l.toFixed(2)}% ${lch.c.toFixed(2)} ${lch.h.toFixed(
1783
+ 2
1784
+ )}${alphaStr})`;
1785
+ }
1786
+ /**
1787
+ * Gets LCH object
1788
+ * @returns LCH color object
1789
+ */
1790
+ getLchObject() {
1791
+ return rgbToLch(this.getRgbObject());
1792
+ }
1793
+ /**
1794
+ * Converts to OKLAB string
1795
+ * @returns OKLAB color string
1796
+ */
1797
+ toOklab() {
1798
+ const oklab = rgbToOklab(this.getRgbObject());
1799
+ const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : "";
1800
+ return `oklab(${oklab.l.toFixed(4)} ${oklab.a.toFixed(4)} ${oklab.b.toFixed(
1801
+ 4
1802
+ )}${alphaStr})`;
1803
+ }
1804
+ /**
1805
+ * Gets OKLAB object
1806
+ * @returns OKLAB color object
1807
+ */
1808
+ getOklabObject() {
1809
+ return rgbToOklab(this.getRgbObject());
1810
+ }
1811
+ /**
1812
+ * Converts to OKLCH string
1813
+ * @returns OKLCH color string
1814
+ */
1815
+ toOklch() {
1816
+ const oklch = rgbToOklch(this.getRgbObject());
1817
+ const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : "";
1818
+ return `oklch(${oklch.l.toFixed(4)} ${oklch.c.toFixed(4)} ${oklch.h.toFixed(
1819
+ 2
1820
+ )}${alphaStr})`;
1821
+ }
1822
+ /**
1823
+ * Gets OKLCH object
1824
+ * @returns OKLCH color object
1825
+ */
1826
+ getOklchObject() {
1827
+ return rgbToOklch(this.getRgbObject());
1828
+ }
1829
+ /**
1830
+ * Adjusts the color
1831
+ * @param options - Adjustment options
1832
+ * @returns This Color instance for chaining
1833
+ */
1834
+ adjust(options) {
1835
+ const adjusted = adjustColor(this.toHex(), options);
1836
+ this.set(adjusted);
1837
+ return this;
1838
+ }
1839
+ /**
1840
+ * Lightens the color
1841
+ * @param amount - Lighten amount (0-100)
1842
+ * @returns This Color instance for chaining
1843
+ */
1844
+ lighten(amount) {
1845
+ return this.adjust({ lightness: amount });
1846
+ }
1847
+ /**
1848
+ * Darkens the color
1849
+ * @param amount - Darken amount (0-100)
1850
+ * @returns This Color instance for chaining
1851
+ */
1852
+ darken(amount) {
1853
+ return this.adjust({ lightness: -amount });
1854
+ }
1855
+ /**
1856
+ * Saturates the color
1857
+ * @param amount - Saturate amount (0-100)
1858
+ * @returns This Color instance for chaining
1859
+ */
1860
+ saturate(amount) {
1861
+ return this.adjust({ saturation: amount });
1862
+ }
1863
+ /**
1864
+ * Desaturates the color
1865
+ * @param amount - Desaturate amount (0-100)
1866
+ * @returns This Color instance for chaining
1867
+ */
1868
+ desaturate(amount) {
1869
+ return this.adjust({ saturation: -amount });
1870
+ }
1871
+ /**
1872
+ * Rotates the hue
1873
+ * @param degrees - Hue rotation in degrees
1874
+ * @returns This Color instance for chaining
1875
+ */
1876
+ rotate(degrees) {
1877
+ return this.adjust({ hue: degrees });
1878
+ }
1879
+ /**
1880
+ * Sets the alpha value
1881
+ * @param alpha - Alpha value (0-1)
1882
+ * @returns This Color instance for chaining
1883
+ */
1884
+ alpha(alpha) {
1885
+ this._a = Math.max(0, Math.min(1, alpha));
1886
+ return this;
1887
+ }
1888
+ /**
1889
+ * Mixes with another color
1890
+ * @param color - Color to mix with
1891
+ * @param percentage - Mix percentage (0-100)
1892
+ * @param colorSpace - Color space for mixing
1893
+ * @returns This Color instance for chaining
1894
+ */
1895
+ mix(color, percentage = 50, colorSpace = "srgb") {
1896
+ const mixed = mixColors({
1897
+ color: this.toHex(),
1898
+ with: color,
1899
+ percentage,
1900
+ colorSpace
1901
+ });
1902
+ this.set(mixed);
1903
+ return this;
1904
+ }
1905
+ /**
1906
+ * Gets the contrasting color
1907
+ * @param options - Contrast options
1908
+ * @returns Contrasting Color instance
1909
+ */
1910
+ getContrastColor(options = {}) {
1911
+ const contrast = createContrastColor(this.toHex(), options);
1912
+ return new _Color(contrast);
1913
+ }
1914
+ /**
1915
+ * Gets the relative luminance
1916
+ * @returns Relative luminance (0-1)
1917
+ */
1918
+ getLuminance() {
1919
+ return calculateLuminance(this._r, this._g, this._b);
1920
+ }
1921
+ /**
1922
+ * Calculates contrast ratio with another color
1923
+ * @param color - Color to compare with
1924
+ * @returns Contrast ratio (1-21)
1925
+ */
1926
+ getContrastRatio(color) {
1927
+ const otherColor = color instanceof _Color ? color.toHex() : color;
1928
+ return calculateContrastRatio(this.toHex(), otherColor);
1929
+ }
1930
+ /**
1931
+ * Generates a palette from this color
1932
+ * @param options - Palette options
1933
+ * @returns Object with color shades
1934
+ */
1935
+ getPalette(options = {}) {
1936
+ return generatePalette(this.toHex(), options);
1937
+ }
1938
+ /**
1939
+ * Clones the color
1940
+ * @returns New Color instance with same values
1941
+ */
1942
+ clone() {
1943
+ return new _Color(this.rgba);
1944
+ }
1945
+ /**
1946
+ * Converts to string in specified format
1947
+ * @param format - Output format
1948
+ * @returns Color string
1949
+ */
1950
+ toString(format = "hex") {
1951
+ switch (format) {
1952
+ case "hex":
1953
+ return this.toHex();
1954
+ case "rgb":
1955
+ return this.toRgb();
1956
+ case "rgba":
1957
+ return this.toRgba();
1958
+ case "hsl":
1959
+ return this.toHsl();
1960
+ case "hsla":
1961
+ return this.toHsl();
1962
+ case "hsv":
1963
+ return this.toHsv();
1964
+ case "hsva":
1965
+ return this.toHsv();
1966
+ case "hwb":
1967
+ return this.toHwb();
1968
+ case "cmyk":
1969
+ return this.toCmyk();
1970
+ case "xyz":
1971
+ return this.toXyz();
1972
+ case "lab":
1973
+ return this.toLab();
1974
+ case "lch":
1975
+ return this.toLch();
1976
+ case "oklab":
1977
+ return this.toOklab();
1978
+ case "oklch":
1979
+ return this.toOklch();
1980
+ default:
1981
+ return this.toHex();
1982
+ }
1983
+ }
1984
+ /**
1985
+ * Convert to any format with options
1986
+ * @param format - Target format
1987
+ * @param options - Conversion options
1988
+ * @returns Converted color object
1989
+ */
1990
+ convertTo(format, options = {}) {
1991
+ return convertColor(this.getRgbObject(), format, options);
1992
+ }
1993
+ /**
1994
+ * Set color from any color space object
1995
+ * @param color - Color object in any supported format
1996
+ * @returns This Color instance for chaining
1997
+ */
1998
+ setFromObject(color) {
1999
+ let rgb;
2000
+ if ("r" in color && "g" in color && "b" in color) {
2001
+ rgb = color;
2002
+ } else if ("h" in color && "s" in color && "l" in color) {
2003
+ rgb = hslToRgb2(color);
2004
+ } else if ("h" in color && "s" in color && "v" in color) {
2005
+ rgb = hsvToRgb(color);
2006
+ } else if ("h" in color && "w" in color && "b" in color) {
2007
+ rgb = hwbToRgb(color);
2008
+ } else if ("c" in color && "m" in color && "y" in color && "k" in color) {
2009
+ rgb = cmykToRgb(color);
2010
+ } else if ("x" in color && "y" in color && "z" in color) {
2011
+ rgb = xyzToRgb(color);
2012
+ } else if ("l" in color && "a" in color && "b" in color) {
2013
+ rgb = labToRgb(color);
2014
+ } else if ("l" in color && "c" in color && "h" in color) {
2015
+ const lchColor = color;
2016
+ rgb = lchColor.l <= 1 ? oklchToRgb2(color) : lchToRgb(lchColor);
2017
+ } else {
2018
+ throw new Error("Unknown color format");
2019
+ }
2020
+ this._r = rgb.r;
2021
+ this._g = rgb.g;
2022
+ this._b = rgb.b;
2023
+ this._a = rgb.a ?? 1;
2024
+ this._clamp();
2025
+ return this;
2026
+ }
2027
+ /**
2028
+ * Get color harmony colors
2029
+ * @param options - Harmony options
2030
+ * @returns Array of Color instances
2031
+ */
2032
+ getHarmony(options = {}) {
2033
+ const { type = "complementary", count = 5, angleOffset = 30 } = options;
2034
+ const hsl = this.getHslObject();
2035
+ const colors = [];
2036
+ switch (type) {
2037
+ case "complementary":
2038
+ colors.push(
2039
+ new _Color({ h: (hsl.h + 180) % 360, s: hsl.s, l: hsl.l, a: hsl.a })
2040
+ );
2041
+ break;
2042
+ case "analogous":
2043
+ colors.push(
2044
+ new _Color({
2045
+ h: (hsl.h - angleOffset + 360) % 360,
2046
+ s: hsl.s,
2047
+ l: hsl.l,
2048
+ a: hsl.a
2049
+ }),
2050
+ new _Color({
2051
+ h: (hsl.h + angleOffset) % 360,
2052
+ s: hsl.s,
2053
+ l: hsl.l,
2054
+ a: hsl.a
2055
+ })
2056
+ );
2057
+ break;
2058
+ case "triadic":
2059
+ colors.push(
2060
+ new _Color({ h: (hsl.h + 120) % 360, s: hsl.s, l: hsl.l, a: hsl.a }),
2061
+ new _Color({ h: (hsl.h + 240) % 360, s: hsl.s, l: hsl.l, a: hsl.a })
2062
+ );
2063
+ break;
2064
+ case "tetradic":
2065
+ colors.push(
2066
+ new _Color({ h: (hsl.h + 90) % 360, s: hsl.s, l: hsl.l, a: hsl.a }),
2067
+ new _Color({ h: (hsl.h + 180) % 360, s: hsl.s, l: hsl.l, a: hsl.a }),
2068
+ new _Color({ h: (hsl.h + 270) % 360, s: hsl.s, l: hsl.l, a: hsl.a })
2069
+ );
2070
+ break;
2071
+ case "split-complementary":
2072
+ colors.push(
2073
+ new _Color({ h: (hsl.h + 150) % 360, s: hsl.s, l: hsl.l, a: hsl.a }),
2074
+ new _Color({ h: (hsl.h + 210) % 360, s: hsl.s, l: hsl.l, a: hsl.a })
2075
+ );
2076
+ break;
2077
+ case "square":
2078
+ colors.push(
2079
+ new _Color({ h: (hsl.h + 90) % 360, s: hsl.s, l: hsl.l, a: hsl.a }),
2080
+ new _Color({ h: (hsl.h + 180) % 360, s: hsl.s, l: hsl.l, a: hsl.a }),
2081
+ new _Color({ h: (hsl.h + 270) % 360, s: hsl.s, l: hsl.l, a: hsl.a })
2082
+ );
2083
+ break;
2084
+ case "monochromatic":
2085
+ const step = 100 / (count + 1);
2086
+ for (let i = 1; i <= count; i++) {
2087
+ colors.push(
2088
+ new _Color({
2089
+ h: hsl.h,
2090
+ s: hsl.s,
2091
+ l: Math.max(0, Math.min(100, step * i)),
2092
+ a: hsl.a
2093
+ })
2094
+ );
2095
+ }
2096
+ break;
2097
+ }
2098
+ return colors;
2099
+ }
2100
+ /**
2101
+ * Get supported color formats
2102
+ * @returns Array of supported format names
2103
+ */
2104
+ static getSupportedFormats() {
2105
+ return getSupportedFormats();
2106
+ }
2107
+ /**
2108
+ * Check if format is valid
2109
+ * @param format - Format to check
2110
+ * @returns True if format is supported
2111
+ */
2112
+ static isValidFormat(format) {
2113
+ return isValidFormat(format);
2114
+ }
2115
+ /**
2116
+ * Get conversion path between formats
2117
+ * @param from - Source format
2118
+ * @param to - Target format
2119
+ * @returns Array of formats in conversion path
2120
+ */
2121
+ static getConversionPath(from, to) {
2122
+ return getConversionPath(from, to);
2123
+ }
2124
+ /**
2125
+ * Checks if the color is valid
2126
+ * @returns True if color is valid
2127
+ */
2128
+ isValid() {
2129
+ return isValidColor(this.toHex());
2130
+ }
2131
+ /**
2132
+ * Creates a Color instance from string
2133
+ * @param color - Color string
2134
+ * @returns Color instance or null if invalid
2135
+ */
2136
+ static fromString(color) {
2137
+ if (!isValidColor(color)) {
2138
+ return null;
2139
+ }
2140
+ return new _Color(color);
2141
+ }
2142
+ /**
2143
+ * Creates a random Color
2144
+ * @returns Random Color instance
2145
+ */
2146
+ static random() {
2147
+ const r = Math.floor(Math.random() * 256);
2148
+ const g = Math.floor(Math.random() * 256);
2149
+ const b = Math.floor(Math.random() * 256);
2150
+ return new _Color([r, g, b, 1]);
2151
+ }
2152
+ /**
2153
+ * Predefined colors
2154
+ */
2155
+ static get transparent() {
2156
+ return new _Color("transparent");
2157
+ }
2158
+ static get white() {
2159
+ return new _Color("#ffffff");
2160
+ }
2161
+ static get black() {
2162
+ return new _Color("#000000");
2163
+ }
2164
+ static get red() {
2165
+ return new _Color("#ff0000");
2166
+ }
2167
+ static get green() {
2168
+ return new _Color("#00ff00");
2169
+ }
2170
+ static get blue() {
2171
+ return new _Color("#0000ff");
2172
+ }
2173
+ static get yellow() {
2174
+ return new _Color("#ffff00");
2175
+ }
2176
+ static get cyan() {
2177
+ return new _Color("#00ffff");
2178
+ }
2179
+ static get magenta() {
2180
+ return new _Color("#ff00ff");
2181
+ }
2182
+ static get gray() {
2183
+ return new _Color("#808080");
2184
+ }
2185
+ static get lightGray() {
2186
+ return new _Color("#d3d3d3");
2187
+ }
2188
+ static get darkGray() {
2189
+ return new _Color("#a9a9a9");
2190
+ }
2191
+ static get orange() {
2192
+ return new _Color("#ffa500");
2193
+ }
2194
+ static get purple() {
2195
+ return new _Color("#800080");
2196
+ }
2197
+ static get pink() {
2198
+ return new _Color("#ffc0cb");
2199
+ }
2200
+ static get brown() {
2201
+ return new _Color("#a52a2a");
2202
+ }
2203
+ static get teal() {
2204
+ return new _Color("#008080");
2205
+ }
2206
+ static get lime() {
2207
+ return new _Color("#00ff00");
2208
+ }
2209
+ static get indigo() {
2210
+ return new _Color("#4b0082");
2211
+ }
2212
+ static get violet() {
2213
+ return new _Color("#ee82ee");
2214
+ }
2215
+ };
2216
+
2217
+ // src/lib/color/helpers.ts
2218
+ function adjustTemperature(color, options = {}) {
2219
+ const { temperature = 0, intensity = 0.5 } = options;
2220
+ const colorObj = color instanceof Color ? color : new Color(color);
2221
+ const rgb = colorObj.getRgbObject();
2222
+ const normalizedTemp = Math.max(-1, Math.min(1, temperature / 1e4));
2223
+ let r = rgb.r;
2224
+ let g = rgb.g;
2225
+ let b = rgb.b;
2226
+ if (normalizedTemp > 0) {
2227
+ r = Math.min(255, r + normalizedTemp * 255 * intensity);
2228
+ g = Math.min(255, g + normalizedTemp * 200 * intensity);
2229
+ b = Math.max(0, b - normalizedTemp * 100 * intensity);
2230
+ } else {
2231
+ const coolness = Math.abs(normalizedTemp);
2232
+ r = Math.max(0, r - coolness * 100 * intensity);
2233
+ g = Math.max(0, g - coolness * 50 * intensity);
2234
+ b = Math.min(255, b + coolness * 255 * intensity);
2235
+ }
2236
+ return new Color([Math.round(r), Math.round(g), Math.round(b), rgb.a || 1]);
2237
+ }
2238
+ function simulateColorBlindness(color, type = "protanopia") {
2239
+ const colorObj = color instanceof Color ? color : new Color(color);
2240
+ const rgb = colorObj.getRgbObject();
2241
+ let r = rgb.r / 255;
2242
+ let g = rgb.g / 255;
2243
+ let b = rgb.b / 255;
2244
+ let matrix;
2245
+ switch (type) {
2246
+ case "protanopia":
2247
+ matrix = [
2248
+ [0.56667, 0.43333, 0],
2249
+ [0.55833, 0.44167, 0],
2250
+ [0, 0.24167, 0.75833]
2251
+ ];
2252
+ break;
2253
+ case "deuteranopia":
2254
+ matrix = [
2255
+ [0.625, 0.375, 0],
2256
+ [0.7, 0.3, 0],
2257
+ [0, 0.3, 0.7]
2258
+ ];
2259
+ break;
2260
+ case "tritanopia":
2261
+ matrix = [
2262
+ [0.95, 0.05, 0],
2263
+ [0, 0.43333, 0.56667],
2264
+ [0, 0.475, 0.525]
2265
+ ];
2266
+ break;
2267
+ case "achromatopsia":
2268
+ const gray = 0.299 * r + 0.587 * g + 0.114 * b;
2269
+ return new Color([
2270
+ Math.round(gray * 255),
2271
+ Math.round(gray * 255),
2272
+ Math.round(gray * 255),
2273
+ rgb.a || 1
2274
+ ]);
2275
+ default:
2276
+ matrix = [
2277
+ [1, 0, 0],
2278
+ [0, 1, 0],
2279
+ [0, 0, 1]
2280
+ ];
2281
+ }
2282
+ const newR = matrix[0][0] * r + matrix[0][1] * g + matrix[0][2] * b;
2283
+ const newG = matrix[1][0] * r + matrix[1][1] * g + matrix[1][2] * b;
2284
+ const newB = matrix[2][0] * r + matrix[2][1] * g + matrix[2][2] * b;
2285
+ return new Color([
2286
+ Math.round(Math.max(0, Math.min(255, newR * 255))),
2287
+ Math.round(Math.max(0, Math.min(255, newG * 255))),
2288
+ Math.round(Math.max(0, Math.min(255, newB * 255))),
2289
+ rgb.a || 1
2290
+ ]);
2291
+ }
2292
+ function invertColor(color, bw = false) {
2293
+ const colorObj = color instanceof Color ? color : new Color(color);
2294
+ const rgb = colorObj.getRgbObject();
2295
+ if (bw) {
2296
+ const luminance = (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255;
2297
+ return luminance > 0.5 ? Color.black : Color.white;
2298
+ }
2299
+ return new Color([255 - rgb.r, 255 - rgb.g, 255 - rgb.b, rgb.a || 1]);
2300
+ }
2301
+ function toGrayscale(color, method = "luminosity") {
2302
+ const colorObj = color instanceof Color ? color : new Color(color);
2303
+ const rgb = colorObj.getRgbObject();
2304
+ let gray;
2305
+ switch (method) {
2306
+ case "average":
2307
+ gray = (rgb.r + rgb.g + rgb.b) / 3;
2308
+ break;
2309
+ case "luminosity":
2310
+ gray = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b;
2311
+ break;
2312
+ case "lightness":
2313
+ gray = (Math.max(rgb.r, rgb.g, rgb.b) + Math.min(rgb.r, rgb.g, rgb.b)) / 2;
2314
+ break;
2315
+ default:
2316
+ gray = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b;
2317
+ }
2318
+ const value = Math.round(gray);
2319
+ return new Color([value, value, value, rgb.a || 1]);
2320
+ }
2321
+ function toSepia(color, intensity = 1) {
2322
+ const colorObj = color instanceof Color ? color : new Color(color);
2323
+ const rgb = colorObj.getRgbObject();
2324
+ const r = rgb.r / 255;
2325
+ const g = rgb.g / 255;
2326
+ const b = rgb.b / 255;
2327
+ let newR = 0.393 * r + 0.769 * g + 0.189 * b;
2328
+ let newG = 0.349 * r + 0.686 * g + 0.168 * b;
2329
+ let newB = 0.272 * r + 0.534 * g + 0.131 * b;
2330
+ newR = r + (newR - r) * intensity;
2331
+ newG = g + (newG - g) * intensity;
2332
+ newB = b + (newB - b) * intensity;
2333
+ return new Color([
2334
+ Math.round(Math.max(0, Math.min(255, newR * 255))),
2335
+ Math.round(Math.max(0, Math.min(255, newG * 255))),
2336
+ Math.round(Math.max(0, Math.min(255, newB * 255))),
2337
+ rgb.a || 1
2338
+ ]);
2339
+ }
2340
+ function colorDistance(color1, color2) {
2341
+ const c1 = color1 instanceof Color ? color1 : new Color(color1);
2342
+ const c2 = color2 instanceof Color ? color2 : new Color(color2);
2343
+ const lab1 = rgbToLab(c1.getRgbObject());
2344
+ const lab2 = rgbToLab(c2.getRgbObject());
2345
+ const deltaL = lab1.l - lab2.l;
2346
+ const deltaA = lab1.a - lab2.a;
2347
+ const deltaB = lab1.b - lab2.b;
2348
+ return Math.sqrt(deltaL * deltaL + deltaA * deltaA + deltaB * deltaB);
2349
+ }
2350
+ function findClosestColor(color, palette) {
2351
+ const targetColor = color instanceof Color ? color : new Color(color);
2352
+ let closestColor = null;
2353
+ let minDistance = Infinity;
2354
+ for (const paletteColor of palette) {
2355
+ const distance = colorDistance(targetColor, paletteColor);
2356
+ if (distance < minDistance) {
2357
+ minDistance = distance;
2358
+ closestColor = paletteColor instanceof Color ? paletteColor : new Color(paletteColor);
2359
+ }
2360
+ }
2361
+ return closestColor || targetColor;
2362
+ }
2363
+ function generateGradient(startColor, endColor, steps = 5, colorSpace = "rgb") {
2364
+ const start = startColor instanceof Color ? startColor : new Color(startColor);
2365
+ const end = endColor instanceof Color ? endColor : new Color(endColor);
2366
+ const colors = [];
2367
+ if (steps < 2) {
2368
+ return [start];
2369
+ }
2370
+ for (let i = 0; i < steps; i++) {
2371
+ const t = i / (steps - 1);
2372
+ let interpolated;
2373
+ switch (colorSpace) {
2374
+ case "hsl": {
2375
+ const hsl1 = rgbToHsl(start.getRgbObject());
2376
+ const hsl2 = rgbToHsl(end.getRgbObject());
2377
+ let h1 = hsl1.h;
2378
+ let h2 = hsl2.h;
2379
+ const diff = h2 - h1;
2380
+ if (Math.abs(diff) > 180) {
2381
+ if (h1 < h2) {
2382
+ h1 += 360;
2383
+ } else {
2384
+ h2 += 360;
2385
+ }
2386
+ }
2387
+ const h = (h1 + (h2 - h1) * t) % 360;
2388
+ const s = hsl1.s + (hsl2.s - hsl1.s) * t;
2389
+ const l = hsl1.l + (hsl2.l - hsl1.l) * t;
2390
+ const a = (hsl1.a ?? 1) + ((hsl2.a ?? 1) - (hsl1.a ?? 1)) * t;
2391
+ interpolated = hslToRgb2({ h, s, l, a });
2392
+ break;
2393
+ }
2394
+ case "lab": {
2395
+ const lab1 = rgbToLab(start.getRgbObject());
2396
+ const lab2 = rgbToLab(end.getRgbObject());
2397
+ const l = lab1.l + (lab2.l - lab1.l) * t;
2398
+ const a = lab1.a + (lab2.a - lab1.a) * t;
2399
+ const b = lab1.b + (lab2.b - lab1.b) * t;
2400
+ const alpha = (lab1.alpha ?? 1) + ((lab2.alpha ?? 1) - (lab1.alpha ?? 1)) * t;
2401
+ interpolated = labToRgb({ l, a, b, alpha });
2402
+ break;
2403
+ }
2404
+ case "oklab": {
2405
+ const oklab1 = rgbToOklab(start.getRgbObject());
2406
+ const oklab2 = rgbToOklab(end.getRgbObject());
2407
+ const l = oklab1.l + (oklab2.l - oklab1.l) * t;
2408
+ const a = oklab1.a + (oklab2.a - oklab1.a) * t;
2409
+ const b = oklab1.b + (oklab2.b - oklab1.b) * t;
2410
+ const alpha = (oklab1.alpha ?? 1) + ((oklab2.alpha ?? 1) - (oklab1.alpha ?? 1)) * t;
2411
+ interpolated = oklabToRgb({ l, a, b, alpha });
2412
+ break;
2413
+ }
2414
+ case "oklch": {
2415
+ const oklch1 = rgbToOklch(start.getRgbObject());
2416
+ const oklch2 = rgbToOklch(end.getRgbObject());
2417
+ let h1 = oklch1.h;
2418
+ let h2 = oklch2.h;
2419
+ const diff = h2 - h1;
2420
+ if (Math.abs(diff) > 180) {
2421
+ if (h1 < h2) {
2422
+ h1 += 360;
2423
+ } else {
2424
+ h2 += 360;
2425
+ }
2426
+ }
2427
+ const l = oklch1.l + (oklch2.l - oklch1.l) * t;
2428
+ const c = oklch1.c + (oklch2.c - oklch1.c) * t;
2429
+ const h = (h1 + (h2 - h1) * t) % 360;
2430
+ const alpha = (oklch1.alpha ?? 1) + ((oklch2.alpha ?? 1) - (oklch1.alpha ?? 1)) * t;
2431
+ interpolated = oklchToRgb2({ l, c, h, alpha });
2432
+ break;
2433
+ }
2434
+ case "rgb":
2435
+ default: {
2436
+ const rgb1 = start.getRgbObject();
2437
+ const rgb2 = end.getRgbObject();
2438
+ interpolated = {
2439
+ r: Math.round(rgb1.r + (rgb2.r - rgb1.r) * t),
2440
+ g: Math.round(rgb1.g + (rgb2.g - rgb1.g) * t),
2441
+ b: Math.round(rgb1.b + (rgb2.b - rgb1.b) * t),
2442
+ a: (rgb1.a ?? 1) + ((rgb2.a ?? 1) - (rgb1.a ?? 1)) * t
2443
+ };
2444
+ break;
2445
+ }
2446
+ }
2447
+ colors.push(new Color(interpolated));
2448
+ }
2449
+ return colors;
2450
+ }
2451
+ function getPerceivedBrightness(color) {
2452
+ const colorObj = color instanceof Color ? color : new Color(color);
2453
+ const rgb = colorObj.getRgbObject();
2454
+ return (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255;
2455
+ }
2456
+ function isLight(color) {
2457
+ return getPerceivedBrightness(color) > 0.5;
2458
+ }
2459
+ function isDark(color) {
2460
+ return !isLight(color);
2461
+ }
2462
+ function blendColors(base, blend, mode = "normal", opacity = 1) {
2463
+ const baseColor = base instanceof Color ? base : new Color(base);
2464
+ const blendColor = blend instanceof Color ? blend : new Color(blend);
2465
+ const b = baseColor.getRgbObject();
2466
+ const a = blendColor.getRgbObject();
2467
+ const blendChannel = (base2, blend2) => {
2468
+ const b2 = base2 / 255;
2469
+ const a2 = blend2 / 255;
2470
+ let result;
2471
+ switch (mode) {
2472
+ case "multiply":
2473
+ result = b2 * a2;
2474
+ break;
2475
+ case "screen":
2476
+ result = 1 - (1 - b2) * (1 - a2);
2477
+ break;
2478
+ case "overlay":
2479
+ result = b2 < 0.5 ? 2 * b2 * a2 : 1 - 2 * (1 - b2) * (1 - a2);
2480
+ break;
2481
+ case "normal":
2482
+ default:
2483
+ result = a2 * opacity + b2 * (1 - opacity);
2484
+ break;
2485
+ }
2486
+ return Math.round(Math.max(0, Math.min(255, result * 255)));
2487
+ };
2488
+ return new Color([
2489
+ blendChannel(b.r, a.r),
2490
+ blendChannel(b.g, a.g),
2491
+ blendChannel(b.b, a.b),
2492
+ b.a || 1
2493
+ ]);
2494
+ }
2495
+ function getDominantComponent(color) {
2496
+ const colorObj = color instanceof Color ? color : new Color(color);
2497
+ const rgb = colorObj.getRgbObject();
2498
+ const max = Math.max(rgb.r, rgb.g, rgb.b);
2499
+ const min = Math.min(rgb.r, rgb.g, rgb.b);
2500
+ if (max - min < 20) {
2501
+ return "gray";
2502
+ }
2503
+ if (rgb.r === max) return "red";
2504
+ if (rgb.g === max) return "green";
2505
+ return "blue";
2506
+ }
2507
+ function getColorName(color) {
2508
+ const colorObj = color instanceof Color ? color : new Color(color);
2509
+ const hsl = rgbToHsl(colorObj.getRgbObject());
2510
+ if (hsl.s < 10) {
2511
+ if (hsl.l > 90) return "white";
2512
+ if (hsl.l < 10) return "black";
2513
+ if (hsl.l > 60) return "light gray";
2514
+ if (hsl.l < 40) return "dark gray";
2515
+ return "gray";
2516
+ }
2517
+ const h = hsl.h;
2518
+ let hueName;
2519
+ if (h < 15 || h >= 345) hueName = "red";
2520
+ else if (h < 45) hueName = "orange";
2521
+ else if (h < 75) hueName = "yellow";
2522
+ else if (h < 165) hueName = "green";
2523
+ else if (h < 255) hueName = "blue";
2524
+ else if (h < 285) hueName = "purple";
2525
+ else if (h < 315) hueName = "magenta";
2526
+ else hueName = "pink";
2527
+ if (hsl.l < 30) return `dark ${hueName}`;
2528
+ if (hsl.l > 70) return `light ${hueName}`;
2529
+ if (hsl.s < 30) return `dull ${hueName}`;
2530
+ if (hsl.s > 70) return `vivid ${hueName}`;
2531
+ return hueName;
2532
+ }
2533
+ function randomColor(options = {}) {
2534
+ const {
2535
+ hue = [0, 360],
2536
+ saturation = [0, 100],
2537
+ lightness = [0, 100],
2538
+ alpha = 1
2539
+ } = options;
2540
+ const h = hue[0] + Math.random() * (hue[1] - hue[0]);
2541
+ const s = saturation[0] + Math.random() * (saturation[1] - saturation[0]);
2542
+ const l = lightness[0] + Math.random() * (lightness[1] - lightness[0]);
2543
+ const rgb = hslToRgb2({ h, s, l, a: alpha });
2544
+ return new Color(rgb);
2545
+ }
2546
+ export {
2547
+ Color,
2548
+ NAMED_COLORS,
2549
+ RGB_PATTERNS,
2550
+ adjustColor,
2551
+ adjustTemperature,
2552
+ anyToRgb,
2553
+ batchConvert,
2554
+ blendColors,
2555
+ calculateContrastRatio,
2556
+ calculateLuminance,
2557
+ cmykToHsl,
2558
+ cmykToHsv,
2559
+ cmykToRgb,
2560
+ colorDistance,
2561
+ convertColor,
2562
+ createContrastColor,
2563
+ findClosestColor,
2564
+ formatRgba,
2565
+ generateGradient,
2566
+ generatePalette,
2567
+ getColorName,
2568
+ getConversionPath,
2569
+ getDominantComponent,
2570
+ getPerceivedBrightness,
2571
+ getSupportedFormats,
2572
+ hasDirectConversion,
2573
+ hslToHsv,
2574
+ hslToHwb,
2575
+ hslToRgb2 as hslToRgb,
2576
+ hsvToHsl,
2577
+ hsvToHwb,
2578
+ hsvToRgb,
2579
+ hwbToHsl,
2580
+ hwbToHsv,
2581
+ hwbToRgb,
2582
+ invertColor,
2583
+ isDark,
2584
+ isLight,
2585
+ isValidColor,
2586
+ isValidFormat,
2587
+ labToLch,
2588
+ labToRgb,
2589
+ labToXyz,
2590
+ lchToLab,
2591
+ lchToRgb,
2592
+ lchToXyz,
2593
+ mixColors,
2594
+ oklabToOklch,
2595
+ oklabToRgb,
2596
+ oklchToOklab,
2597
+ oklchToRgb2 as oklchToRgb,
2598
+ parseColor,
2599
+ parseRgbaColor,
2600
+ randomColor,
2601
+ rgbToCmyk,
2602
+ rgbToHsl,
2603
+ rgbToHsv,
2604
+ rgbToHwb,
2605
+ rgbToLab,
2606
+ rgbToLch,
2607
+ rgbToOklab,
2608
+ rgbToOklch,
2609
+ rgbToXyz,
2610
+ rgbaToCmyk,
2611
+ rgbaToHex,
2612
+ rgbaToHsl,
2613
+ rgbaToHsv,
2614
+ simulateColorBlindness,
2615
+ toGrayscale,
2616
+ toSepia,
2617
+ xyzToLab,
2618
+ xyzToRgb
2619
+ };