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