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