chunk.WBOEJF4H.js 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281
  1. import {
  2. clamp
  3. } from "./chunk.T56CG5BM.js";
  4. import {
  5. i
  6. } from "./chunk.DA3UDEH5.js";
  7. import {
  8. l
  9. } from "./chunk.5MED2A3H.js";
  10. import {
  11. event,
  12. watch
  13. } from "./chunk.XX234VRK.js";
  14. import {
  15. e as e2
  16. } from "./chunk.YXKHB4AC.js";
  17. import {
  18. T,
  19. e,
  20. h,
  21. n,
  22. o,
  23. r,
  24. r2
  25. } from "./chunk.5PIDMFOE.js";
  26. import {
  27. __commonJS,
  28. __decorateClass,
  29. __toModule
  30. } from "./chunk.IHGPZX35.js";
  31. // node_modules/color-name/index.js
  32. var require_color_name = __commonJS({
  33. "node_modules/color-name/index.js"(exports, module) {
  34. "use strict";
  35. module.exports = {
  36. "aliceblue": [240, 248, 255],
  37. "antiquewhite": [250, 235, 215],
  38. "aqua": [0, 255, 255],
  39. "aquamarine": [127, 255, 212],
  40. "azure": [240, 255, 255],
  41. "beige": [245, 245, 220],
  42. "bisque": [255, 228, 196],
  43. "black": [0, 0, 0],
  44. "blanchedalmond": [255, 235, 205],
  45. "blue": [0, 0, 255],
  46. "blueviolet": [138, 43, 226],
  47. "brown": [165, 42, 42],
  48. "burlywood": [222, 184, 135],
  49. "cadetblue": [95, 158, 160],
  50. "chartreuse": [127, 255, 0],
  51. "chocolate": [210, 105, 30],
  52. "coral": [255, 127, 80],
  53. "cornflowerblue": [100, 149, 237],
  54. "cornsilk": [255, 248, 220],
  55. "crimson": [220, 20, 60],
  56. "cyan": [0, 255, 255],
  57. "darkblue": [0, 0, 139],
  58. "darkcyan": [0, 139, 139],
  59. "darkgoldenrod": [184, 134, 11],
  60. "darkgray": [169, 169, 169],
  61. "darkgreen": [0, 100, 0],
  62. "darkgrey": [169, 169, 169],
  63. "darkkhaki": [189, 183, 107],
  64. "darkmagenta": [139, 0, 139],
  65. "darkolivegreen": [85, 107, 47],
  66. "darkorange": [255, 140, 0],
  67. "darkorchid": [153, 50, 204],
  68. "darkred": [139, 0, 0],
  69. "darksalmon": [233, 150, 122],
  70. "darkseagreen": [143, 188, 143],
  71. "darkslateblue": [72, 61, 139],
  72. "darkslategray": [47, 79, 79],
  73. "darkslategrey": [47, 79, 79],
  74. "darkturquoise": [0, 206, 209],
  75. "darkviolet": [148, 0, 211],
  76. "deeppink": [255, 20, 147],
  77. "deepskyblue": [0, 191, 255],
  78. "dimgray": [105, 105, 105],
  79. "dimgrey": [105, 105, 105],
  80. "dodgerblue": [30, 144, 255],
  81. "firebrick": [178, 34, 34],
  82. "floralwhite": [255, 250, 240],
  83. "forestgreen": [34, 139, 34],
  84. "fuchsia": [255, 0, 255],
  85. "gainsboro": [220, 220, 220],
  86. "ghostwhite": [248, 248, 255],
  87. "gold": [255, 215, 0],
  88. "goldenrod": [218, 165, 32],
  89. "gray": [128, 128, 128],
  90. "green": [0, 128, 0],
  91. "greenyellow": [173, 255, 47],
  92. "grey": [128, 128, 128],
  93. "honeydew": [240, 255, 240],
  94. "hotpink": [255, 105, 180],
  95. "indianred": [205, 92, 92],
  96. "indigo": [75, 0, 130],
  97. "ivory": [255, 255, 240],
  98. "khaki": [240, 230, 140],
  99. "lavender": [230, 230, 250],
  100. "lavenderblush": [255, 240, 245],
  101. "lawngreen": [124, 252, 0],
  102. "lemonchiffon": [255, 250, 205],
  103. "lightblue": [173, 216, 230],
  104. "lightcoral": [240, 128, 128],
  105. "lightcyan": [224, 255, 255],
  106. "lightgoldenrodyellow": [250, 250, 210],
  107. "lightgray": [211, 211, 211],
  108. "lightgreen": [144, 238, 144],
  109. "lightgrey": [211, 211, 211],
  110. "lightpink": [255, 182, 193],
  111. "lightsalmon": [255, 160, 122],
  112. "lightseagreen": [32, 178, 170],
  113. "lightskyblue": [135, 206, 250],
  114. "lightslategray": [119, 136, 153],
  115. "lightslategrey": [119, 136, 153],
  116. "lightsteelblue": [176, 196, 222],
  117. "lightyellow": [255, 255, 224],
  118. "lime": [0, 255, 0],
  119. "limegreen": [50, 205, 50],
  120. "linen": [250, 240, 230],
  121. "magenta": [255, 0, 255],
  122. "maroon": [128, 0, 0],
  123. "mediumaquamarine": [102, 205, 170],
  124. "mediumblue": [0, 0, 205],
  125. "mediumorchid": [186, 85, 211],
  126. "mediumpurple": [147, 112, 219],
  127. "mediumseagreen": [60, 179, 113],
  128. "mediumslateblue": [123, 104, 238],
  129. "mediumspringgreen": [0, 250, 154],
  130. "mediumturquoise": [72, 209, 204],
  131. "mediumvioletred": [199, 21, 133],
  132. "midnightblue": [25, 25, 112],
  133. "mintcream": [245, 255, 250],
  134. "mistyrose": [255, 228, 225],
  135. "moccasin": [255, 228, 181],
  136. "navajowhite": [255, 222, 173],
  137. "navy": [0, 0, 128],
  138. "oldlace": [253, 245, 230],
  139. "olive": [128, 128, 0],
  140. "olivedrab": [107, 142, 35],
  141. "orange": [255, 165, 0],
  142. "orangered": [255, 69, 0],
  143. "orchid": [218, 112, 214],
  144. "palegoldenrod": [238, 232, 170],
  145. "palegreen": [152, 251, 152],
  146. "paleturquoise": [175, 238, 238],
  147. "palevioletred": [219, 112, 147],
  148. "papayawhip": [255, 239, 213],
  149. "peachpuff": [255, 218, 185],
  150. "peru": [205, 133, 63],
  151. "pink": [255, 192, 203],
  152. "plum": [221, 160, 221],
  153. "powderblue": [176, 224, 230],
  154. "purple": [128, 0, 128],
  155. "rebeccapurple": [102, 51, 153],
  156. "red": [255, 0, 0],
  157. "rosybrown": [188, 143, 143],
  158. "royalblue": [65, 105, 225],
  159. "saddlebrown": [139, 69, 19],
  160. "salmon": [250, 128, 114],
  161. "sandybrown": [244, 164, 96],
  162. "seagreen": [46, 139, 87],
  163. "seashell": [255, 245, 238],
  164. "sienna": [160, 82, 45],
  165. "silver": [192, 192, 192],
  166. "skyblue": [135, 206, 235],
  167. "slateblue": [106, 90, 205],
  168. "slategray": [112, 128, 144],
  169. "slategrey": [112, 128, 144],
  170. "snow": [255, 250, 250],
  171. "springgreen": [0, 255, 127],
  172. "steelblue": [70, 130, 180],
  173. "tan": [210, 180, 140],
  174. "teal": [0, 128, 128],
  175. "thistle": [216, 191, 216],
  176. "tomato": [255, 99, 71],
  177. "turquoise": [64, 224, 208],
  178. "violet": [238, 130, 238],
  179. "wheat": [245, 222, 179],
  180. "white": [255, 255, 255],
  181. "whitesmoke": [245, 245, 245],
  182. "yellow": [255, 255, 0],
  183. "yellowgreen": [154, 205, 50]
  184. };
  185. }
  186. });
  187. // node_modules/is-arrayish/index.js
  188. var require_is_arrayish = __commonJS({
  189. "node_modules/is-arrayish/index.js"(exports, module) {
  190. module.exports = function isArrayish(obj) {
  191. if (!obj || typeof obj === "string") {
  192. return false;
  193. }
  194. return obj instanceof Array || Array.isArray(obj) || obj.length >= 0 && (obj.splice instanceof Function || Object.getOwnPropertyDescriptor(obj, obj.length - 1) && obj.constructor.name !== "String");
  195. };
  196. }
  197. });
  198. // node_modules/simple-swizzle/index.js
  199. var require_simple_swizzle = __commonJS({
  200. "node_modules/simple-swizzle/index.js"(exports, module) {
  201. "use strict";
  202. var isArrayish = require_is_arrayish();
  203. var concat = Array.prototype.concat;
  204. var slice = Array.prototype.slice;
  205. var swizzle = module.exports = function swizzle2(args) {
  206. var results = [];
  207. for (var i2 = 0, len = args.length; i2 < len; i2++) {
  208. var arg = args[i2];
  209. if (isArrayish(arg)) {
  210. results = concat.call(results, slice.call(arg));
  211. } else {
  212. results.push(arg);
  213. }
  214. }
  215. return results;
  216. };
  217. swizzle.wrap = function(fn) {
  218. return function() {
  219. return fn(swizzle(arguments));
  220. };
  221. };
  222. }
  223. });
  224. // node_modules/color-string/index.js
  225. var require_color_string = __commonJS({
  226. "node_modules/color-string/index.js"(exports, module) {
  227. var colorNames = require_color_name();
  228. var swizzle = require_simple_swizzle();
  229. var reverseNames = {};
  230. for (var name in colorNames) {
  231. if (colorNames.hasOwnProperty(name)) {
  232. reverseNames[colorNames[name]] = name;
  233. }
  234. }
  235. var cs = module.exports = {
  236. to: {},
  237. get: {}
  238. };
  239. cs.get = function(string) {
  240. var prefix = string.substring(0, 3).toLowerCase();
  241. var val;
  242. var model;
  243. switch (prefix) {
  244. case "hsl":
  245. val = cs.get.hsl(string);
  246. model = "hsl";
  247. break;
  248. case "hwb":
  249. val = cs.get.hwb(string);
  250. model = "hwb";
  251. break;
  252. default:
  253. val = cs.get.rgb(string);
  254. model = "rgb";
  255. break;
  256. }
  257. if (!val) {
  258. return null;
  259. }
  260. return { model, value: val };
  261. };
  262. cs.get.rgb = function(string) {
  263. if (!string) {
  264. return null;
  265. }
  266. var abbr = /^#([a-f0-9]{3,4})$/i;
  267. var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
  268. var rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
  269. var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
  270. var keyword = /(\D+)/;
  271. var rgb = [0, 0, 0, 1];
  272. var match;
  273. var i2;
  274. var hexAlpha;
  275. if (match = string.match(hex)) {
  276. hexAlpha = match[2];
  277. match = match[1];
  278. for (i2 = 0; i2 < 3; i2++) {
  279. var i22 = i2 * 2;
  280. rgb[i2] = parseInt(match.slice(i22, i22 + 2), 16);
  281. }
  282. if (hexAlpha) {
  283. rgb[3] = parseInt(hexAlpha, 16) / 255;
  284. }
  285. } else if (match = string.match(abbr)) {
  286. match = match[1];
  287. hexAlpha = match[3];
  288. for (i2 = 0; i2 < 3; i2++) {
  289. rgb[i2] = parseInt(match[i2] + match[i2], 16);
  290. }
  291. if (hexAlpha) {
  292. rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
  293. }
  294. } else if (match = string.match(rgba)) {
  295. for (i2 = 0; i2 < 3; i2++) {
  296. rgb[i2] = parseInt(match[i2 + 1], 0);
  297. }
  298. if (match[4]) {
  299. rgb[3] = parseFloat(match[4]);
  300. }
  301. } else if (match = string.match(per)) {
  302. for (i2 = 0; i2 < 3; i2++) {
  303. rgb[i2] = Math.round(parseFloat(match[i2 + 1]) * 2.55);
  304. }
  305. if (match[4]) {
  306. rgb[3] = parseFloat(match[4]);
  307. }
  308. } else if (match = string.match(keyword)) {
  309. if (match[1] === "transparent") {
  310. return [0, 0, 0, 0];
  311. }
  312. rgb = colorNames[match[1]];
  313. if (!rgb) {
  314. return null;
  315. }
  316. rgb[3] = 1;
  317. return rgb;
  318. } else {
  319. return null;
  320. }
  321. for (i2 = 0; i2 < 3; i2++) {
  322. rgb[i2] = clamp2(rgb[i2], 0, 255);
  323. }
  324. rgb[3] = clamp2(rgb[3], 0, 1);
  325. return rgb;
  326. };
  327. cs.get.hsl = function(string) {
  328. if (!string) {
  329. return null;
  330. }
  331. var hsl = /^hsla?\(\s*([+-]?(?:\d*\.)?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
  332. var match = string.match(hsl);
  333. if (match) {
  334. var alpha = parseFloat(match[4]);
  335. var h2 = (parseFloat(match[1]) + 360) % 360;
  336. var s = clamp2(parseFloat(match[2]), 0, 100);
  337. var l2 = clamp2(parseFloat(match[3]), 0, 100);
  338. var a = clamp2(isNaN(alpha) ? 1 : alpha, 0, 1);
  339. return [h2, s, l2, a];
  340. }
  341. return null;
  342. };
  343. cs.get.hwb = function(string) {
  344. if (!string) {
  345. return null;
  346. }
  347. var hwb = /^hwb\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
  348. var match = string.match(hwb);
  349. if (match) {
  350. var alpha = parseFloat(match[4]);
  351. var h2 = (parseFloat(match[1]) % 360 + 360) % 360;
  352. var w = clamp2(parseFloat(match[2]), 0, 100);
  353. var b = clamp2(parseFloat(match[3]), 0, 100);
  354. var a = clamp2(isNaN(alpha) ? 1 : alpha, 0, 1);
  355. return [h2, w, b, a];
  356. }
  357. return null;
  358. };
  359. cs.to.hex = function() {
  360. var rgba = swizzle(arguments);
  361. return "#" + hexDouble(rgba[0]) + hexDouble(rgba[1]) + hexDouble(rgba[2]) + (rgba[3] < 1 ? hexDouble(Math.round(rgba[3] * 255)) : "");
  362. };
  363. cs.to.rgb = function() {
  364. var rgba = swizzle(arguments);
  365. return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + Math.round(rgba[0]) + ", " + Math.round(rgba[1]) + ", " + Math.round(rgba[2]) + ")" : "rgba(" + Math.round(rgba[0]) + ", " + Math.round(rgba[1]) + ", " + Math.round(rgba[2]) + ", " + rgba[3] + ")";
  366. };
  367. cs.to.rgb.percent = function() {
  368. var rgba = swizzle(arguments);
  369. var r3 = Math.round(rgba[0] / 255 * 100);
  370. var g = Math.round(rgba[1] / 255 * 100);
  371. var b = Math.round(rgba[2] / 255 * 100);
  372. return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + r3 + "%, " + g + "%, " + b + "%)" : "rgba(" + r3 + "%, " + g + "%, " + b + "%, " + rgba[3] + ")";
  373. };
  374. cs.to.hsl = function() {
  375. var hsla = swizzle(arguments);
  376. return hsla.length < 4 || hsla[3] === 1 ? "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)" : "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, " + hsla[3] + ")";
  377. };
  378. cs.to.hwb = function() {
  379. var hwba = swizzle(arguments);
  380. var a = "";
  381. if (hwba.length >= 4 && hwba[3] !== 1) {
  382. a = ", " + hwba[3];
  383. }
  384. return "hwb(" + hwba[0] + ", " + hwba[1] + "%, " + hwba[2] + "%" + a + ")";
  385. };
  386. cs.to.keyword = function(rgb) {
  387. return reverseNames[rgb.slice(0, 3)];
  388. };
  389. function clamp2(num, min, max) {
  390. return Math.min(Math.max(min, num), max);
  391. }
  392. function hexDouble(num) {
  393. var str = num.toString(16).toUpperCase();
  394. return str.length < 2 ? "0" + str : str;
  395. }
  396. }
  397. });
  398. // node_modules/color-convert/conversions.js
  399. var require_conversions = __commonJS({
  400. "node_modules/color-convert/conversions.js"(exports, module) {
  401. var cssKeywords = require_color_name();
  402. var reverseKeywords = {};
  403. for (var key in cssKeywords) {
  404. if (cssKeywords.hasOwnProperty(key)) {
  405. reverseKeywords[cssKeywords[key]] = key;
  406. }
  407. }
  408. var convert = module.exports = {
  409. rgb: { channels: 3, labels: "rgb" },
  410. hsl: { channels: 3, labels: "hsl" },
  411. hsv: { channels: 3, labels: "hsv" },
  412. hwb: { channels: 3, labels: "hwb" },
  413. cmyk: { channels: 4, labels: "cmyk" },
  414. xyz: { channels: 3, labels: "xyz" },
  415. lab: { channels: 3, labels: "lab" },
  416. lch: { channels: 3, labels: "lch" },
  417. hex: { channels: 1, labels: ["hex"] },
  418. keyword: { channels: 1, labels: ["keyword"] },
  419. ansi16: { channels: 1, labels: ["ansi16"] },
  420. ansi256: { channels: 1, labels: ["ansi256"] },
  421. hcg: { channels: 3, labels: ["h", "c", "g"] },
  422. apple: { channels: 3, labels: ["r16", "g16", "b16"] },
  423. gray: { channels: 1, labels: ["gray"] }
  424. };
  425. for (var model in convert) {
  426. if (convert.hasOwnProperty(model)) {
  427. if (!("channels" in convert[model])) {
  428. throw new Error("missing channels property: " + model);
  429. }
  430. if (!("labels" in convert[model])) {
  431. throw new Error("missing channel labels property: " + model);
  432. }
  433. if (convert[model].labels.length !== convert[model].channels) {
  434. throw new Error("channel and label counts mismatch: " + model);
  435. }
  436. channels = convert[model].channels;
  437. labels = convert[model].labels;
  438. delete convert[model].channels;
  439. delete convert[model].labels;
  440. Object.defineProperty(convert[model], "channels", { value: channels });
  441. Object.defineProperty(convert[model], "labels", { value: labels });
  442. }
  443. }
  444. var channels;
  445. var labels;
  446. convert.rgb.hsl = function(rgb) {
  447. var r3 = rgb[0] / 255;
  448. var g = rgb[1] / 255;
  449. var b = rgb[2] / 255;
  450. var min = Math.min(r3, g, b);
  451. var max = Math.max(r3, g, b);
  452. var delta = max - min;
  453. var h2;
  454. var s;
  455. var l2;
  456. if (max === min) {
  457. h2 = 0;
  458. } else if (r3 === max) {
  459. h2 = (g - b) / delta;
  460. } else if (g === max) {
  461. h2 = 2 + (b - r3) / delta;
  462. } else if (b === max) {
  463. h2 = 4 + (r3 - g) / delta;
  464. }
  465. h2 = Math.min(h2 * 60, 360);
  466. if (h2 < 0) {
  467. h2 += 360;
  468. }
  469. l2 = (min + max) / 2;
  470. if (max === min) {
  471. s = 0;
  472. } else if (l2 <= 0.5) {
  473. s = delta / (max + min);
  474. } else {
  475. s = delta / (2 - max - min);
  476. }
  477. return [h2, s * 100, l2 * 100];
  478. };
  479. convert.rgb.hsv = function(rgb) {
  480. var rdif;
  481. var gdif;
  482. var bdif;
  483. var h2;
  484. var s;
  485. var r3 = rgb[0] / 255;
  486. var g = rgb[1] / 255;
  487. var b = rgb[2] / 255;
  488. var v = Math.max(r3, g, b);
  489. var diff = v - Math.min(r3, g, b);
  490. var diffc = function(c) {
  491. return (v - c) / 6 / diff + 1 / 2;
  492. };
  493. if (diff === 0) {
  494. h2 = s = 0;
  495. } else {
  496. s = diff / v;
  497. rdif = diffc(r3);
  498. gdif = diffc(g);
  499. bdif = diffc(b);
  500. if (r3 === v) {
  501. h2 = bdif - gdif;
  502. } else if (g === v) {
  503. h2 = 1 / 3 + rdif - bdif;
  504. } else if (b === v) {
  505. h2 = 2 / 3 + gdif - rdif;
  506. }
  507. if (h2 < 0) {
  508. h2 += 1;
  509. } else if (h2 > 1) {
  510. h2 -= 1;
  511. }
  512. }
  513. return [
  514. h2 * 360,
  515. s * 100,
  516. v * 100
  517. ];
  518. };
  519. convert.rgb.hwb = function(rgb) {
  520. var r3 = rgb[0];
  521. var g = rgb[1];
  522. var b = rgb[2];
  523. var h2 = convert.rgb.hsl(rgb)[0];
  524. var w = 1 / 255 * Math.min(r3, Math.min(g, b));
  525. b = 1 - 1 / 255 * Math.max(r3, Math.max(g, b));
  526. return [h2, w * 100, b * 100];
  527. };
  528. convert.rgb.cmyk = function(rgb) {
  529. var r3 = rgb[0] / 255;
  530. var g = rgb[1] / 255;
  531. var b = rgb[2] / 255;
  532. var c;
  533. var m;
  534. var y;
  535. var k;
  536. k = Math.min(1 - r3, 1 - g, 1 - b);
  537. c = (1 - r3 - k) / (1 - k) || 0;
  538. m = (1 - g - k) / (1 - k) || 0;
  539. y = (1 - b - k) / (1 - k) || 0;
  540. return [c * 100, m * 100, y * 100, k * 100];
  541. };
  542. function comparativeDistance(x, y) {
  543. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  544. }
  545. convert.rgb.keyword = function(rgb) {
  546. var reversed = reverseKeywords[rgb];
  547. if (reversed) {
  548. return reversed;
  549. }
  550. var currentClosestDistance = Infinity;
  551. var currentClosestKeyword;
  552. for (var keyword in cssKeywords) {
  553. if (cssKeywords.hasOwnProperty(keyword)) {
  554. var value = cssKeywords[keyword];
  555. var distance = comparativeDistance(rgb, value);
  556. if (distance < currentClosestDistance) {
  557. currentClosestDistance = distance;
  558. currentClosestKeyword = keyword;
  559. }
  560. }
  561. }
  562. return currentClosestKeyword;
  563. };
  564. convert.keyword.rgb = function(keyword) {
  565. return cssKeywords[keyword];
  566. };
  567. convert.rgb.xyz = function(rgb) {
  568. var r3 = rgb[0] / 255;
  569. var g = rgb[1] / 255;
  570. var b = rgb[2] / 255;
  571. r3 = r3 > 0.04045 ? Math.pow((r3 + 0.055) / 1.055, 2.4) : r3 / 12.92;
  572. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  573. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  574. var x = r3 * 0.4124 + g * 0.3576 + b * 0.1805;
  575. var y = r3 * 0.2126 + g * 0.7152 + b * 0.0722;
  576. var z = r3 * 0.0193 + g * 0.1192 + b * 0.9505;
  577. return [x * 100, y * 100, z * 100];
  578. };
  579. convert.rgb.lab = function(rgb) {
  580. var xyz = convert.rgb.xyz(rgb);
  581. var x = xyz[0];
  582. var y = xyz[1];
  583. var z = xyz[2];
  584. var l2;
  585. var a;
  586. var b;
  587. x /= 95.047;
  588. y /= 100;
  589. z /= 108.883;
  590. x = x > 8856e-6 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  591. y = y > 8856e-6 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  592. z = z > 8856e-6 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  593. l2 = 116 * y - 16;
  594. a = 500 * (x - y);
  595. b = 200 * (y - z);
  596. return [l2, a, b];
  597. };
  598. convert.hsl.rgb = function(hsl) {
  599. var h2 = hsl[0] / 360;
  600. var s = hsl[1] / 100;
  601. var l2 = hsl[2] / 100;
  602. var t1;
  603. var t2;
  604. var t3;
  605. var rgb;
  606. var val;
  607. if (s === 0) {
  608. val = l2 * 255;
  609. return [val, val, val];
  610. }
  611. if (l2 < 0.5) {
  612. t2 = l2 * (1 + s);
  613. } else {
  614. t2 = l2 + s - l2 * s;
  615. }
  616. t1 = 2 * l2 - t2;
  617. rgb = [0, 0, 0];
  618. for (var i2 = 0; i2 < 3; i2++) {
  619. t3 = h2 + 1 / 3 * -(i2 - 1);
  620. if (t3 < 0) {
  621. t3++;
  622. }
  623. if (t3 > 1) {
  624. t3--;
  625. }
  626. if (6 * t3 < 1) {
  627. val = t1 + (t2 - t1) * 6 * t3;
  628. } else if (2 * t3 < 1) {
  629. val = t2;
  630. } else if (3 * t3 < 2) {
  631. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  632. } else {
  633. val = t1;
  634. }
  635. rgb[i2] = val * 255;
  636. }
  637. return rgb;
  638. };
  639. convert.hsl.hsv = function(hsl) {
  640. var h2 = hsl[0];
  641. var s = hsl[1] / 100;
  642. var l2 = hsl[2] / 100;
  643. var smin = s;
  644. var lmin = Math.max(l2, 0.01);
  645. var sv;
  646. var v;
  647. l2 *= 2;
  648. s *= l2 <= 1 ? l2 : 2 - l2;
  649. smin *= lmin <= 1 ? lmin : 2 - lmin;
  650. v = (l2 + s) / 2;
  651. sv = l2 === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l2 + s);
  652. return [h2, sv * 100, v * 100];
  653. };
  654. convert.hsv.rgb = function(hsv) {
  655. var h2 = hsv[0] / 60;
  656. var s = hsv[1] / 100;
  657. var v = hsv[2] / 100;
  658. var hi = Math.floor(h2) % 6;
  659. var f = h2 - Math.floor(h2);
  660. var p = 255 * v * (1 - s);
  661. var q = 255 * v * (1 - s * f);
  662. var t = 255 * v * (1 - s * (1 - f));
  663. v *= 255;
  664. switch (hi) {
  665. case 0:
  666. return [v, t, p];
  667. case 1:
  668. return [q, v, p];
  669. case 2:
  670. return [p, v, t];
  671. case 3:
  672. return [p, q, v];
  673. case 4:
  674. return [t, p, v];
  675. case 5:
  676. return [v, p, q];
  677. }
  678. };
  679. convert.hsv.hsl = function(hsv) {
  680. var h2 = hsv[0];
  681. var s = hsv[1] / 100;
  682. var v = hsv[2] / 100;
  683. var vmin = Math.max(v, 0.01);
  684. var lmin;
  685. var sl;
  686. var l2;
  687. l2 = (2 - s) * v;
  688. lmin = (2 - s) * vmin;
  689. sl = s * vmin;
  690. sl /= lmin <= 1 ? lmin : 2 - lmin;
  691. sl = sl || 0;
  692. l2 /= 2;
  693. return [h2, sl * 100, l2 * 100];
  694. };
  695. convert.hwb.rgb = function(hwb) {
  696. var h2 = hwb[0] / 360;
  697. var wh = hwb[1] / 100;
  698. var bl = hwb[2] / 100;
  699. var ratio = wh + bl;
  700. var i2;
  701. var v;
  702. var f;
  703. var n2;
  704. if (ratio > 1) {
  705. wh /= ratio;
  706. bl /= ratio;
  707. }
  708. i2 = Math.floor(6 * h2);
  709. v = 1 - bl;
  710. f = 6 * h2 - i2;
  711. if ((i2 & 1) !== 0) {
  712. f = 1 - f;
  713. }
  714. n2 = wh + f * (v - wh);
  715. var r3;
  716. var g;
  717. var b;
  718. switch (i2) {
  719. default:
  720. case 6:
  721. case 0:
  722. r3 = v;
  723. g = n2;
  724. b = wh;
  725. break;
  726. case 1:
  727. r3 = n2;
  728. g = v;
  729. b = wh;
  730. break;
  731. case 2:
  732. r3 = wh;
  733. g = v;
  734. b = n2;
  735. break;
  736. case 3:
  737. r3 = wh;
  738. g = n2;
  739. b = v;
  740. break;
  741. case 4:
  742. r3 = n2;
  743. g = wh;
  744. b = v;
  745. break;
  746. case 5:
  747. r3 = v;
  748. g = wh;
  749. b = n2;
  750. break;
  751. }
  752. return [r3 * 255, g * 255, b * 255];
  753. };
  754. convert.cmyk.rgb = function(cmyk) {
  755. var c = cmyk[0] / 100;
  756. var m = cmyk[1] / 100;
  757. var y = cmyk[2] / 100;
  758. var k = cmyk[3] / 100;
  759. var r3;
  760. var g;
  761. var b;
  762. r3 = 1 - Math.min(1, c * (1 - k) + k);
  763. g = 1 - Math.min(1, m * (1 - k) + k);
  764. b = 1 - Math.min(1, y * (1 - k) + k);
  765. return [r3 * 255, g * 255, b * 255];
  766. };
  767. convert.xyz.rgb = function(xyz) {
  768. var x = xyz[0] / 100;
  769. var y = xyz[1] / 100;
  770. var z = xyz[2] / 100;
  771. var r3;
  772. var g;
  773. var b;
  774. r3 = x * 3.2406 + y * -1.5372 + z * -0.4986;
  775. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  776. b = x * 0.0557 + y * -0.204 + z * 1.057;
  777. r3 = r3 > 31308e-7 ? 1.055 * Math.pow(r3, 1 / 2.4) - 0.055 : r3 * 12.92;
  778. g = g > 31308e-7 ? 1.055 * Math.pow(g, 1 / 2.4) - 0.055 : g * 12.92;
  779. b = b > 31308e-7 ? 1.055 * Math.pow(b, 1 / 2.4) - 0.055 : b * 12.92;
  780. r3 = Math.min(Math.max(0, r3), 1);
  781. g = Math.min(Math.max(0, g), 1);
  782. b = Math.min(Math.max(0, b), 1);
  783. return [r3 * 255, g * 255, b * 255];
  784. };
  785. convert.xyz.lab = function(xyz) {
  786. var x = xyz[0];
  787. var y = xyz[1];
  788. var z = xyz[2];
  789. var l2;
  790. var a;
  791. var b;
  792. x /= 95.047;
  793. y /= 100;
  794. z /= 108.883;
  795. x = x > 8856e-6 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  796. y = y > 8856e-6 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  797. z = z > 8856e-6 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  798. l2 = 116 * y - 16;
  799. a = 500 * (x - y);
  800. b = 200 * (y - z);
  801. return [l2, a, b];
  802. };
  803. convert.lab.xyz = function(lab) {
  804. var l2 = lab[0];
  805. var a = lab[1];
  806. var b = lab[2];
  807. var x;
  808. var y;
  809. var z;
  810. y = (l2 + 16) / 116;
  811. x = a / 500 + y;
  812. z = y - b / 200;
  813. var y2 = Math.pow(y, 3);
  814. var x2 = Math.pow(x, 3);
  815. var z2 = Math.pow(z, 3);
  816. y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
  817. x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
  818. z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
  819. x *= 95.047;
  820. y *= 100;
  821. z *= 108.883;
  822. return [x, y, z];
  823. };
  824. convert.lab.lch = function(lab) {
  825. var l2 = lab[0];
  826. var a = lab[1];
  827. var b = lab[2];
  828. var hr;
  829. var h2;
  830. var c;
  831. hr = Math.atan2(b, a);
  832. h2 = hr * 360 / 2 / Math.PI;
  833. if (h2 < 0) {
  834. h2 += 360;
  835. }
  836. c = Math.sqrt(a * a + b * b);
  837. return [l2, c, h2];
  838. };
  839. convert.lch.lab = function(lch) {
  840. var l2 = lch[0];
  841. var c = lch[1];
  842. var h2 = lch[2];
  843. var a;
  844. var b;
  845. var hr;
  846. hr = h2 / 360 * 2 * Math.PI;
  847. a = c * Math.cos(hr);
  848. b = c * Math.sin(hr);
  849. return [l2, a, b];
  850. };
  851. convert.rgb.ansi16 = function(args) {
  852. var r3 = args[0];
  853. var g = args[1];
  854. var b = args[2];
  855. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2];
  856. value = Math.round(value / 50);
  857. if (value === 0) {
  858. return 30;
  859. }
  860. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r3 / 255));
  861. if (value === 2) {
  862. ansi += 60;
  863. }
  864. return ansi;
  865. };
  866. convert.hsv.ansi16 = function(args) {
  867. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  868. };
  869. convert.rgb.ansi256 = function(args) {
  870. var r3 = args[0];
  871. var g = args[1];
  872. var b = args[2];
  873. if (r3 === g && g === b) {
  874. if (r3 < 8) {
  875. return 16;
  876. }
  877. if (r3 > 248) {
  878. return 231;
  879. }
  880. return Math.round((r3 - 8) / 247 * 24) + 232;
  881. }
  882. var ansi = 16 + 36 * Math.round(r3 / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  883. return ansi;
  884. };
  885. convert.ansi16.rgb = function(args) {
  886. var color2 = args % 10;
  887. if (color2 === 0 || color2 === 7) {
  888. if (args > 50) {
  889. color2 += 3.5;
  890. }
  891. color2 = color2 / 10.5 * 255;
  892. return [color2, color2, color2];
  893. }
  894. var mult = (~~(args > 50) + 1) * 0.5;
  895. var r3 = (color2 & 1) * mult * 255;
  896. var g = (color2 >> 1 & 1) * mult * 255;
  897. var b = (color2 >> 2 & 1) * mult * 255;
  898. return [r3, g, b];
  899. };
  900. convert.ansi256.rgb = function(args) {
  901. if (args >= 232) {
  902. var c = (args - 232) * 10 + 8;
  903. return [c, c, c];
  904. }
  905. args -= 16;
  906. var rem;
  907. var r3 = Math.floor(args / 36) / 5 * 255;
  908. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  909. var b = rem % 6 / 5 * 255;
  910. return [r3, g, b];
  911. };
  912. convert.rgb.hex = function(args) {
  913. var integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
  914. var string = integer.toString(16).toUpperCase();
  915. return "000000".substring(string.length) + string;
  916. };
  917. convert.hex.rgb = function(args) {
  918. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  919. if (!match) {
  920. return [0, 0, 0];
  921. }
  922. var colorString = match[0];
  923. if (match[0].length === 3) {
  924. colorString = colorString.split("").map(function(char) {
  925. return char + char;
  926. }).join("");
  927. }
  928. var integer = parseInt(colorString, 16);
  929. var r3 = integer >> 16 & 255;
  930. var g = integer >> 8 & 255;
  931. var b = integer & 255;
  932. return [r3, g, b];
  933. };
  934. convert.rgb.hcg = function(rgb) {
  935. var r3 = rgb[0] / 255;
  936. var g = rgb[1] / 255;
  937. var b = rgb[2] / 255;
  938. var max = Math.max(Math.max(r3, g), b);
  939. var min = Math.min(Math.min(r3, g), b);
  940. var chroma = max - min;
  941. var grayscale;
  942. var hue;
  943. if (chroma < 1) {
  944. grayscale = min / (1 - chroma);
  945. } else {
  946. grayscale = 0;
  947. }
  948. if (chroma <= 0) {
  949. hue = 0;
  950. } else if (max === r3) {
  951. hue = (g - b) / chroma % 6;
  952. } else if (max === g) {
  953. hue = 2 + (b - r3) / chroma;
  954. } else {
  955. hue = 4 + (r3 - g) / chroma + 4;
  956. }
  957. hue /= 6;
  958. hue %= 1;
  959. return [hue * 360, chroma * 100, grayscale * 100];
  960. };
  961. convert.hsl.hcg = function(hsl) {
  962. var s = hsl[1] / 100;
  963. var l2 = hsl[2] / 100;
  964. var c = 1;
  965. var f = 0;
  966. if (l2 < 0.5) {
  967. c = 2 * s * l2;
  968. } else {
  969. c = 2 * s * (1 - l2);
  970. }
  971. if (c < 1) {
  972. f = (l2 - 0.5 * c) / (1 - c);
  973. }
  974. return [hsl[0], c * 100, f * 100];
  975. };
  976. convert.hsv.hcg = function(hsv) {
  977. var s = hsv[1] / 100;
  978. var v = hsv[2] / 100;
  979. var c = s * v;
  980. var f = 0;
  981. if (c < 1) {
  982. f = (v - c) / (1 - c);
  983. }
  984. return [hsv[0], c * 100, f * 100];
  985. };
  986. convert.hcg.rgb = function(hcg) {
  987. var h2 = hcg[0] / 360;
  988. var c = hcg[1] / 100;
  989. var g = hcg[2] / 100;
  990. if (c === 0) {
  991. return [g * 255, g * 255, g * 255];
  992. }
  993. var pure = [0, 0, 0];
  994. var hi = h2 % 1 * 6;
  995. var v = hi % 1;
  996. var w = 1 - v;
  997. var mg = 0;
  998. switch (Math.floor(hi)) {
  999. case 0:
  1000. pure[0] = 1;
  1001. pure[1] = v;
  1002. pure[2] = 0;
  1003. break;
  1004. case 1:
  1005. pure[0] = w;
  1006. pure[1] = 1;
  1007. pure[2] = 0;
  1008. break;
  1009. case 2:
  1010. pure[0] = 0;
  1011. pure[1] = 1;
  1012. pure[2] = v;
  1013. break;
  1014. case 3:
  1015. pure[0] = 0;
  1016. pure[1] = w;
  1017. pure[2] = 1;
  1018. break;
  1019. case 4:
  1020. pure[0] = v;
  1021. pure[1] = 0;
  1022. pure[2] = 1;
  1023. break;
  1024. default:
  1025. pure[0] = 1;
  1026. pure[1] = 0;
  1027. pure[2] = w;
  1028. }
  1029. mg = (1 - c) * g;
  1030. return [
  1031. (c * pure[0] + mg) * 255,
  1032. (c * pure[1] + mg) * 255,
  1033. (c * pure[2] + mg) * 255
  1034. ];
  1035. };
  1036. convert.hcg.hsv = function(hcg) {
  1037. var c = hcg[1] / 100;
  1038. var g = hcg[2] / 100;
  1039. var v = c + g * (1 - c);
  1040. var f = 0;
  1041. if (v > 0) {
  1042. f = c / v;
  1043. }
  1044. return [hcg[0], f * 100, v * 100];
  1045. };
  1046. convert.hcg.hsl = function(hcg) {
  1047. var c = hcg[1] / 100;
  1048. var g = hcg[2] / 100;
  1049. var l2 = g * (1 - c) + 0.5 * c;
  1050. var s = 0;
  1051. if (l2 > 0 && l2 < 0.5) {
  1052. s = c / (2 * l2);
  1053. } else if (l2 >= 0.5 && l2 < 1) {
  1054. s = c / (2 * (1 - l2));
  1055. }
  1056. return [hcg[0], s * 100, l2 * 100];
  1057. };
  1058. convert.hcg.hwb = function(hcg) {
  1059. var c = hcg[1] / 100;
  1060. var g = hcg[2] / 100;
  1061. var v = c + g * (1 - c);
  1062. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  1063. };
  1064. convert.hwb.hcg = function(hwb) {
  1065. var w = hwb[1] / 100;
  1066. var b = hwb[2] / 100;
  1067. var v = 1 - b;
  1068. var c = v - w;
  1069. var g = 0;
  1070. if (c < 1) {
  1071. g = (v - c) / (1 - c);
  1072. }
  1073. return [hwb[0], c * 100, g * 100];
  1074. };
  1075. convert.apple.rgb = function(apple) {
  1076. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  1077. };
  1078. convert.rgb.apple = function(rgb) {
  1079. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  1080. };
  1081. convert.gray.rgb = function(args) {
  1082. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  1083. };
  1084. convert.gray.hsl = convert.gray.hsv = function(args) {
  1085. return [0, 0, args[0]];
  1086. };
  1087. convert.gray.hwb = function(gray) {
  1088. return [0, 100, gray[0]];
  1089. };
  1090. convert.gray.cmyk = function(gray) {
  1091. return [0, 0, 0, gray[0]];
  1092. };
  1093. convert.gray.lab = function(gray) {
  1094. return [gray[0], 0, 0];
  1095. };
  1096. convert.gray.hex = function(gray) {
  1097. var val = Math.round(gray[0] / 100 * 255) & 255;
  1098. var integer = (val << 16) + (val << 8) + val;
  1099. var string = integer.toString(16).toUpperCase();
  1100. return "000000".substring(string.length) + string;
  1101. };
  1102. convert.rgb.gray = function(rgb) {
  1103. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  1104. return [val / 255 * 100];
  1105. };
  1106. }
  1107. });
  1108. // node_modules/color-convert/route.js
  1109. var require_route = __commonJS({
  1110. "node_modules/color-convert/route.js"(exports, module) {
  1111. var conversions = require_conversions();
  1112. function buildGraph() {
  1113. var graph = {};
  1114. var models = Object.keys(conversions);
  1115. for (var len = models.length, i2 = 0; i2 < len; i2++) {
  1116. graph[models[i2]] = {
  1117. distance: -1,
  1118. parent: null
  1119. };
  1120. }
  1121. return graph;
  1122. }
  1123. function deriveBFS(fromModel) {
  1124. var graph = buildGraph();
  1125. var queue = [fromModel];
  1126. graph[fromModel].distance = 0;
  1127. while (queue.length) {
  1128. var current = queue.pop();
  1129. var adjacents = Object.keys(conversions[current]);
  1130. for (var len = adjacents.length, i2 = 0; i2 < len; i2++) {
  1131. var adjacent = adjacents[i2];
  1132. var node = graph[adjacent];
  1133. if (node.distance === -1) {
  1134. node.distance = graph[current].distance + 1;
  1135. node.parent = current;
  1136. queue.unshift(adjacent);
  1137. }
  1138. }
  1139. }
  1140. return graph;
  1141. }
  1142. function link(from, to) {
  1143. return function(args) {
  1144. return to(from(args));
  1145. };
  1146. }
  1147. function wrapConversion(toModel, graph) {
  1148. var path = [graph[toModel].parent, toModel];
  1149. var fn = conversions[graph[toModel].parent][toModel];
  1150. var cur = graph[toModel].parent;
  1151. while (graph[cur].parent) {
  1152. path.unshift(graph[cur].parent);
  1153. fn = link(conversions[graph[cur].parent][cur], fn);
  1154. cur = graph[cur].parent;
  1155. }
  1156. fn.conversion = path;
  1157. return fn;
  1158. }
  1159. module.exports = function(fromModel) {
  1160. var graph = deriveBFS(fromModel);
  1161. var conversion = {};
  1162. var models = Object.keys(graph);
  1163. for (var len = models.length, i2 = 0; i2 < len; i2++) {
  1164. var toModel = models[i2];
  1165. var node = graph[toModel];
  1166. if (node.parent === null) {
  1167. continue;
  1168. }
  1169. conversion[toModel] = wrapConversion(toModel, graph);
  1170. }
  1171. return conversion;
  1172. };
  1173. }
  1174. });
  1175. // node_modules/color-convert/index.js
  1176. var require_color_convert = __commonJS({
  1177. "node_modules/color-convert/index.js"(exports, module) {
  1178. var conversions = require_conversions();
  1179. var route = require_route();
  1180. var convert = {};
  1181. var models = Object.keys(conversions);
  1182. function wrapRaw(fn) {
  1183. var wrappedFn = function(args) {
  1184. if (args === void 0 || args === null) {
  1185. return args;
  1186. }
  1187. if (arguments.length > 1) {
  1188. args = Array.prototype.slice.call(arguments);
  1189. }
  1190. return fn(args);
  1191. };
  1192. if ("conversion" in fn) {
  1193. wrappedFn.conversion = fn.conversion;
  1194. }
  1195. return wrappedFn;
  1196. }
  1197. function wrapRounded(fn) {
  1198. var wrappedFn = function(args) {
  1199. if (args === void 0 || args === null) {
  1200. return args;
  1201. }
  1202. if (arguments.length > 1) {
  1203. args = Array.prototype.slice.call(arguments);
  1204. }
  1205. var result = fn(args);
  1206. if (typeof result === "object") {
  1207. for (var len = result.length, i2 = 0; i2 < len; i2++) {
  1208. result[i2] = Math.round(result[i2]);
  1209. }
  1210. }
  1211. return result;
  1212. };
  1213. if ("conversion" in fn) {
  1214. wrappedFn.conversion = fn.conversion;
  1215. }
  1216. return wrappedFn;
  1217. }
  1218. models.forEach(function(fromModel) {
  1219. convert[fromModel] = {};
  1220. Object.defineProperty(convert[fromModel], "channels", { value: conversions[fromModel].channels });
  1221. Object.defineProperty(convert[fromModel], "labels", { value: conversions[fromModel].labels });
  1222. var routes = route(fromModel);
  1223. var routeModels = Object.keys(routes);
  1224. routeModels.forEach(function(toModel) {
  1225. var fn = routes[toModel];
  1226. convert[fromModel][toModel] = wrapRounded(fn);
  1227. convert[fromModel][toModel].raw = wrapRaw(fn);
  1228. });
  1229. });
  1230. module.exports = convert;
  1231. }
  1232. });
  1233. // node_modules/color/index.js
  1234. var require_color = __commonJS({
  1235. "node_modules/color/index.js"(exports, module) {
  1236. "use strict";
  1237. var colorString = require_color_string();
  1238. var convert = require_color_convert();
  1239. var _slice = [].slice;
  1240. var skippedModels = [
  1241. "keyword",
  1242. "gray",
  1243. "hex"
  1244. ];
  1245. var hashedModelKeys = {};
  1246. Object.keys(convert).forEach(function(model) {
  1247. hashedModelKeys[_slice.call(convert[model].labels).sort().join("")] = model;
  1248. });
  1249. var limiters = {};
  1250. function Color(obj, model) {
  1251. if (!(this instanceof Color)) {
  1252. return new Color(obj, model);
  1253. }
  1254. if (model && model in skippedModels) {
  1255. model = null;
  1256. }
  1257. if (model && !(model in convert)) {
  1258. throw new Error("Unknown model: " + model);
  1259. }
  1260. var i2;
  1261. var channels;
  1262. if (obj == null) {
  1263. this.model = "rgb";
  1264. this.color = [0, 0, 0];
  1265. this.valpha = 1;
  1266. } else if (obj instanceof Color) {
  1267. this.model = obj.model;
  1268. this.color = obj.color.slice();
  1269. this.valpha = obj.valpha;
  1270. } else if (typeof obj === "string") {
  1271. var result = colorString.get(obj);
  1272. if (result === null) {
  1273. throw new Error("Unable to parse color from string: " + obj);
  1274. }
  1275. this.model = result.model;
  1276. channels = convert[this.model].channels;
  1277. this.color = result.value.slice(0, channels);
  1278. this.valpha = typeof result.value[channels] === "number" ? result.value[channels] : 1;
  1279. } else if (obj.length) {
  1280. this.model = model || "rgb";
  1281. channels = convert[this.model].channels;
  1282. var newArr = _slice.call(obj, 0, channels);
  1283. this.color = zeroArray(newArr, channels);
  1284. this.valpha = typeof obj[channels] === "number" ? obj[channels] : 1;
  1285. } else if (typeof obj === "number") {
  1286. obj &= 16777215;
  1287. this.model = "rgb";
  1288. this.color = [
  1289. obj >> 16 & 255,
  1290. obj >> 8 & 255,
  1291. obj & 255
  1292. ];
  1293. this.valpha = 1;
  1294. } else {
  1295. this.valpha = 1;
  1296. var keys = Object.keys(obj);
  1297. if ("alpha" in obj) {
  1298. keys.splice(keys.indexOf("alpha"), 1);
  1299. this.valpha = typeof obj.alpha === "number" ? obj.alpha : 0;
  1300. }
  1301. var hashedKeys = keys.sort().join("");
  1302. if (!(hashedKeys in hashedModelKeys)) {
  1303. throw new Error("Unable to parse color from object: " + JSON.stringify(obj));
  1304. }
  1305. this.model = hashedModelKeys[hashedKeys];
  1306. var labels = convert[this.model].labels;
  1307. var color2 = [];
  1308. for (i2 = 0; i2 < labels.length; i2++) {
  1309. color2.push(obj[labels[i2]]);
  1310. }
  1311. this.color = zeroArray(color2);
  1312. }
  1313. if (limiters[this.model]) {
  1314. channels = convert[this.model].channels;
  1315. for (i2 = 0; i2 < channels; i2++) {
  1316. var limit = limiters[this.model][i2];
  1317. if (limit) {
  1318. this.color[i2] = limit(this.color[i2]);
  1319. }
  1320. }
  1321. }
  1322. this.valpha = Math.max(0, Math.min(1, this.valpha));
  1323. if (Object.freeze) {
  1324. Object.freeze(this);
  1325. }
  1326. }
  1327. Color.prototype = {
  1328. toString: function() {
  1329. return this.string();
  1330. },
  1331. toJSON: function() {
  1332. return this[this.model]();
  1333. },
  1334. string: function(places) {
  1335. var self = this.model in colorString.to ? this : this.rgb();
  1336. self = self.round(typeof places === "number" ? places : 1);
  1337. var args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);
  1338. return colorString.to[self.model](args);
  1339. },
  1340. percentString: function(places) {
  1341. var self = this.rgb().round(typeof places === "number" ? places : 1);
  1342. var args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);
  1343. return colorString.to.rgb.percent(args);
  1344. },
  1345. array: function() {
  1346. return this.valpha === 1 ? this.color.slice() : this.color.concat(this.valpha);
  1347. },
  1348. object: function() {
  1349. var result = {};
  1350. var channels = convert[this.model].channels;
  1351. var labels = convert[this.model].labels;
  1352. for (var i2 = 0; i2 < channels; i2++) {
  1353. result[labels[i2]] = this.color[i2];
  1354. }
  1355. if (this.valpha !== 1) {
  1356. result.alpha = this.valpha;
  1357. }
  1358. return result;
  1359. },
  1360. unitArray: function() {
  1361. var rgb = this.rgb().color;
  1362. rgb[0] /= 255;
  1363. rgb[1] /= 255;
  1364. rgb[2] /= 255;
  1365. if (this.valpha !== 1) {
  1366. rgb.push(this.valpha);
  1367. }
  1368. return rgb;
  1369. },
  1370. unitObject: function() {
  1371. var rgb = this.rgb().object();
  1372. rgb.r /= 255;
  1373. rgb.g /= 255;
  1374. rgb.b /= 255;
  1375. if (this.valpha !== 1) {
  1376. rgb.alpha = this.valpha;
  1377. }
  1378. return rgb;
  1379. },
  1380. round: function(places) {
  1381. places = Math.max(places || 0, 0);
  1382. return new Color(this.color.map(roundToPlace(places)).concat(this.valpha), this.model);
  1383. },
  1384. alpha: function(val) {
  1385. if (arguments.length) {
  1386. return new Color(this.color.concat(Math.max(0, Math.min(1, val))), this.model);
  1387. }
  1388. return this.valpha;
  1389. },
  1390. red: getset("rgb", 0, maxfn(255)),
  1391. green: getset("rgb", 1, maxfn(255)),
  1392. blue: getset("rgb", 2, maxfn(255)),
  1393. hue: getset(["hsl", "hsv", "hsl", "hwb", "hcg"], 0, function(val) {
  1394. return (val % 360 + 360) % 360;
  1395. }),
  1396. saturationl: getset("hsl", 1, maxfn(100)),
  1397. lightness: getset("hsl", 2, maxfn(100)),
  1398. saturationv: getset("hsv", 1, maxfn(100)),
  1399. value: getset("hsv", 2, maxfn(100)),
  1400. chroma: getset("hcg", 1, maxfn(100)),
  1401. gray: getset("hcg", 2, maxfn(100)),
  1402. white: getset("hwb", 1, maxfn(100)),
  1403. wblack: getset("hwb", 2, maxfn(100)),
  1404. cyan: getset("cmyk", 0, maxfn(100)),
  1405. magenta: getset("cmyk", 1, maxfn(100)),
  1406. yellow: getset("cmyk", 2, maxfn(100)),
  1407. black: getset("cmyk", 3, maxfn(100)),
  1408. x: getset("xyz", 0, maxfn(100)),
  1409. y: getset("xyz", 1, maxfn(100)),
  1410. z: getset("xyz", 2, maxfn(100)),
  1411. l: getset("lab", 0, maxfn(100)),
  1412. a: getset("lab", 1),
  1413. b: getset("lab", 2),
  1414. keyword: function(val) {
  1415. if (arguments.length) {
  1416. return new Color(val);
  1417. }
  1418. return convert[this.model].keyword(this.color);
  1419. },
  1420. hex: function(val) {
  1421. if (arguments.length) {
  1422. return new Color(val);
  1423. }
  1424. return colorString.to.hex(this.rgb().round().color);
  1425. },
  1426. rgbNumber: function() {
  1427. var rgb = this.rgb().color;
  1428. return (rgb[0] & 255) << 16 | (rgb[1] & 255) << 8 | rgb[2] & 255;
  1429. },
  1430. luminosity: function() {
  1431. var rgb = this.rgb().color;
  1432. var lum = [];
  1433. for (var i2 = 0; i2 < rgb.length; i2++) {
  1434. var chan = rgb[i2] / 255;
  1435. lum[i2] = chan <= 0.03928 ? chan / 12.92 : Math.pow((chan + 0.055) / 1.055, 2.4);
  1436. }
  1437. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  1438. },
  1439. contrast: function(color2) {
  1440. var lum1 = this.luminosity();
  1441. var lum2 = color2.luminosity();
  1442. if (lum1 > lum2) {
  1443. return (lum1 + 0.05) / (lum2 + 0.05);
  1444. }
  1445. return (lum2 + 0.05) / (lum1 + 0.05);
  1446. },
  1447. level: function(color2) {
  1448. var contrastRatio = this.contrast(color2);
  1449. if (contrastRatio >= 7.1) {
  1450. return "AAA";
  1451. }
  1452. return contrastRatio >= 4.5 ? "AA" : "";
  1453. },
  1454. isDark: function() {
  1455. var rgb = this.rgb().color;
  1456. var yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1e3;
  1457. return yiq < 128;
  1458. },
  1459. isLight: function() {
  1460. return !this.isDark();
  1461. },
  1462. negate: function() {
  1463. var rgb = this.rgb();
  1464. for (var i2 = 0; i2 < 3; i2++) {
  1465. rgb.color[i2] = 255 - rgb.color[i2];
  1466. }
  1467. return rgb;
  1468. },
  1469. lighten: function(ratio) {
  1470. var hsl = this.hsl();
  1471. hsl.color[2] += hsl.color[2] * ratio;
  1472. return hsl;
  1473. },
  1474. darken: function(ratio) {
  1475. var hsl = this.hsl();
  1476. hsl.color[2] -= hsl.color[2] * ratio;
  1477. return hsl;
  1478. },
  1479. saturate: function(ratio) {
  1480. var hsl = this.hsl();
  1481. hsl.color[1] += hsl.color[1] * ratio;
  1482. return hsl;
  1483. },
  1484. desaturate: function(ratio) {
  1485. var hsl = this.hsl();
  1486. hsl.color[1] -= hsl.color[1] * ratio;
  1487. return hsl;
  1488. },
  1489. whiten: function(ratio) {
  1490. var hwb = this.hwb();
  1491. hwb.color[1] += hwb.color[1] * ratio;
  1492. return hwb;
  1493. },
  1494. blacken: function(ratio) {
  1495. var hwb = this.hwb();
  1496. hwb.color[2] += hwb.color[2] * ratio;
  1497. return hwb;
  1498. },
  1499. grayscale: function() {
  1500. var rgb = this.rgb().color;
  1501. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  1502. return Color.rgb(val, val, val);
  1503. },
  1504. fade: function(ratio) {
  1505. return this.alpha(this.valpha - this.valpha * ratio);
  1506. },
  1507. opaquer: function(ratio) {
  1508. return this.alpha(this.valpha + this.valpha * ratio);
  1509. },
  1510. rotate: function(degrees) {
  1511. var hsl = this.hsl();
  1512. var hue = hsl.color[0];
  1513. hue = (hue + degrees) % 360;
  1514. hue = hue < 0 ? 360 + hue : hue;
  1515. hsl.color[0] = hue;
  1516. return hsl;
  1517. },
  1518. mix: function(mixinColor, weight) {
  1519. if (!mixinColor || !mixinColor.rgb) {
  1520. throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
  1521. }
  1522. var color1 = mixinColor.rgb();
  1523. var color2 = this.rgb();
  1524. var p = weight === void 0 ? 0.5 : weight;
  1525. var w = 2 * p - 1;
  1526. var a = color1.alpha() - color2.alpha();
  1527. var w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
  1528. var w2 = 1 - w1;
  1529. return Color.rgb(w1 * color1.red() + w2 * color2.red(), w1 * color1.green() + w2 * color2.green(), w1 * color1.blue() + w2 * color2.blue(), color1.alpha() * p + color2.alpha() * (1 - p));
  1530. }
  1531. };
  1532. Object.keys(convert).forEach(function(model) {
  1533. if (skippedModels.indexOf(model) !== -1) {
  1534. return;
  1535. }
  1536. var channels = convert[model].channels;
  1537. Color.prototype[model] = function() {
  1538. if (this.model === model) {
  1539. return new Color(this);
  1540. }
  1541. if (arguments.length) {
  1542. return new Color(arguments, model);
  1543. }
  1544. var newAlpha = typeof arguments[channels] === "number" ? channels : this.valpha;
  1545. return new Color(assertArray(convert[this.model][model].raw(this.color)).concat(newAlpha), model);
  1546. };
  1547. Color[model] = function(color2) {
  1548. if (typeof color2 === "number") {
  1549. color2 = zeroArray(_slice.call(arguments), channels);
  1550. }
  1551. return new Color(color2, model);
  1552. };
  1553. });
  1554. function roundTo(num, places) {
  1555. return Number(num.toFixed(places));
  1556. }
  1557. function roundToPlace(places) {
  1558. return function(num) {
  1559. return roundTo(num, places);
  1560. };
  1561. }
  1562. function getset(model, channel, modifier) {
  1563. model = Array.isArray(model) ? model : [model];
  1564. model.forEach(function(m) {
  1565. (limiters[m] || (limiters[m] = []))[channel] = modifier;
  1566. });
  1567. model = model[0];
  1568. return function(val) {
  1569. var result;
  1570. if (arguments.length) {
  1571. if (modifier) {
  1572. val = modifier(val);
  1573. }
  1574. result = this[model]();
  1575. result.color[channel] = val;
  1576. return result;
  1577. }
  1578. result = this[model]().color[channel];
  1579. if (modifier) {
  1580. result = modifier(result);
  1581. }
  1582. return result;
  1583. };
  1584. }
  1585. function maxfn(max) {
  1586. return function(v) {
  1587. return Math.max(0, Math.min(max, v));
  1588. };
  1589. }
  1590. function assertArray(val) {
  1591. return Array.isArray(val) ? val : [val];
  1592. }
  1593. function zeroArray(arr, length) {
  1594. for (var i2 = 0; i2 < length; i2++) {
  1595. if (typeof arr[i2] !== "number") {
  1596. arr[i2] = 0;
  1597. }
  1598. }
  1599. return arr;
  1600. }
  1601. module.exports = Color;
  1602. }
  1603. });
  1604. // src/components/color-picker/color-picker.ts
  1605. var import_color = __toModule(require_color());
  1606. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/color-picker/color-picker.scss
  1607. var color_picker_default = ':host {\n position: relative;\n box-sizing: border-box;\n}\n:host *, :host *:before, :host *:after {\n box-sizing: inherit;\n}\n\n[hidden] {\n display: none !important;\n}\n\n:host {\n --grid-width: 260px;\n --grid-height: 200px;\n --grid-handle-size: 16px;\n --slider-height: 12px;\n --slider-handle-size: 14px;\n display: inline-block;\n}\n\n.color-picker {\n width: var(--grid-width);\n font-family: var(--sl-font-sans);\n font-size: var(--sl-font-size-medium);\n font-weight: var(--sl-font-weight-normal);\n color: var(--color);\n background-color: var(--sl-panel-background-color);\n border-radius: var(--sl-border-radius-medium);\n user-select: none;\n}\n\n.color-picker--inline {\n border: solid 1px var(--sl-panel-border-color);\n box-shadow: var(--sl-shadow-small);\n}\n\n.color-picker__grid {\n position: relative;\n height: var(--grid-height);\n background-image: linear-gradient(to bottom, white 0%, rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0) 50%, black 100%), linear-gradient(to right, gray 0%, rgba(128, 128, 128, 0) 100%);\n border-top-left-radius: var(--sl-border-radius-medium);\n border-top-right-radius: var(--sl-border-radius-medium);\n cursor: crosshair;\n}\n\n.color-picker__grid-handle {\n position: absolute;\n width: var(--grid-handle-size);\n height: var(--grid-handle-size);\n border-radius: 50%;\n box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);\n border: solid 2px white;\n margin-top: calc(var(--grid-handle-size) / -2);\n margin-left: calc(var(--grid-handle-size) / -2);\n}\n.color-picker__grid-handle:focus {\n outline: none;\n box-shadow: 0 0 0 1px var(--sl-color-primary-500), 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n}\n\n.color-picker__controls {\n padding: var(--sl-spacing-small);\n display: flex;\n align-items: center;\n}\n\n.color-picker__sliders {\n flex: 1 1 auto;\n}\n\n.color-picker__slider {\n position: relative;\n height: var(--slider-height);\n border-radius: var(--sl-border-radius-pill);\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);\n}\n.color-picker__slider:not(:last-of-type) {\n margin-bottom: var(--sl-spacing-small);\n}\n\n.color-picker__slider-handle {\n position: absolute;\n top: calc(50% - var(--slider-handle-size) / 2);\n width: var(--slider-handle-size);\n height: var(--slider-handle-size);\n background-color: white;\n border-radius: 50%;\n box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);\n margin-left: calc(var(--slider-handle-size) / -2);\n}\n.color-picker__slider-handle:focus {\n outline: none;\n box-shadow: 0 0 0 1px var(--sl-color-primary-500), 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n}\n\n.color-picker__hue {\n background-image: linear-gradient(to right, red 0%, yellow 17%, lime 33%, aqua 50%, blue 67%, fuchsia 83%, red 100%);\n}\n\n.color-picker__alpha .color-picker__alpha-gradient {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n border-radius: inherit;\n}\n\n.color-picker__preview {\n flex: 0 0 auto;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n position: relative;\n width: 3.125rem;\n height: var(--sl-input-height-small);\n border: none;\n border-radius: var(--sl-input-border-radius-small);\n background: none;\n margin-left: var(--sl-spacing-small);\n cursor: copy;\n}\n.color-picker__preview:before {\n content: "";\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n border-radius: inherit;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);\n background-color: var(--preview-color);\n}\n.color-picker__preview:focus {\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n outline: none;\n}\n\n.color-picker__preview-color {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n border: solid 1px rgba(0, 0, 0, 0.125);\n}\n\n.color-picker__copy-feedback {\n width: calc(var(--sl-input-height-small) / 2);\n height: calc(var(--sl-input-height-small) / 2);\n color: white;\n background-color: var(--sl-color-gray-900);\n border-radius: var(--sl-border-radius-circle);\n opacity: 0;\n}\n.color-picker__copy-feedback.color-picker__copy-feedback--visible {\n animation: copied 1s;\n}\n\n@keyframes copied {\n 0% {\n transform: scale(0.8);\n opacity: 0;\n }\n 30% {\n transform: scale(1.2);\n opacity: 1;\n }\n 70% {\n transform: scale(1.2);\n opacity: 1;\n }\n 100% {\n transform: scale(1.4);\n opacity: 0;\n }\n}\n.color-picker__user-input {\n display: flex;\n padding: 0 var(--sl-spacing-small) var(--sl-spacing-small) var(--sl-spacing-small);\n}\n.color-picker__user-input sl-input {\n min-width: 0;\n flex: 1 1 auto;\n}\n.color-picker__user-input sl-button {\n min-width: 3.125rem;\n max-width: 3.125rem;\n font-size: 1rem;\n margin-left: var(--sl-spacing-small);\n}\n\n.color-picker__swatches {\n display: grid;\n grid-template-columns: repeat(8, 1fr);\n grid-gap: 6px;\n justify-items: center;\n border-top: solid 1px var(--sl-color-gray-200);\n padding: var(--sl-spacing-small);\n}\n\n.color-picker__swatch {\n flex: 0 0 auto;\n position: relative;\n width: 20px;\n height: 20px;\n border-radius: 2px;\n}\n.color-picker__swatch .color-picker__swatch-color {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n border: solid 1px rgba(0, 0, 0, 0.125);\n border-radius: inherit;\n cursor: pointer;\n}\n.color-picker__swatch:focus {\n outline: none;\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n}\n\n.color-picker__transparent-bg {\n background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(45deg, #eee 25%, transparent 25%);\n background-size: 10px 10px;\n background-position: 0 0, 0 0, -5px -5px, 5px 5px;\n}\n\n.color-picker--disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n.color-picker--disabled .color-picker__grid,\n.color-picker--disabled .color-picker__grid-handle,\n.color-picker--disabled .color-picker__slider,\n.color-picker--disabled .color-picker__slider-handle,\n.color-picker--disabled .color-picker__preview,\n.color-picker--disabled .color-picker__swatch,\n.color-picker--disabled .color-picker__swatch-color {\n pointer-events: none;\n}\n\n.color-dropdown::part(panel) {\n max-height: none;\n overflow: visible;\n}\n\n.color-dropdown__trigger {\n display: inline-block;\n position: relative;\n background-color: transparent;\n border: none;\n cursor: pointer;\n transition: var(--sl-transition-fast) box-shadow;\n}\n.color-dropdown__trigger.color-dropdown__trigger--small {\n width: var(--sl-input-height-small);\n height: var(--sl-input-height-small);\n border-radius: var(--sl-border-radius-circle);\n}\n.color-dropdown__trigger.color-dropdown__trigger--medium {\n width: var(--sl-input-height-medium);\n height: var(--sl-input-height-medium);\n border-radius: var(--sl-border-radius-circle);\n}\n.color-dropdown__trigger.color-dropdown__trigger--large {\n width: var(--sl-input-height-large);\n height: var(--sl-input-height-large);\n border-radius: var(--sl-border-radius-circle);\n}\n.color-dropdown__trigger:before {\n content: "";\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n border-radius: inherit;\n background-color: currentColor;\n box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);\n transition: inherit;\n}\n.color-dropdown__trigger:focus {\n outline: none;\n}\n.color-dropdown__trigger:focus:not(.color-dropdown__trigger--disabled) {\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n outline: none;\n}\n.color-dropdown__trigger:focus:not(.color-dropdown__trigger--disabled):before {\n box-shadow: inset 0 0 0 1px var(--sl-color-primary-500);\n}\n.color-dropdown__trigger.color-dropdown__trigger--disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}';
  1608. // src/components/color-picker/color-picker.ts
  1609. var SlColorPicker = class extends h {
  1610. constructor() {
  1611. super(...arguments);
  1612. this.inputValue = "";
  1613. this.hue = 0;
  1614. this.saturation = 100;
  1615. this.lightness = 100;
  1616. this.alpha = 100;
  1617. this.showCopyFeedback = false;
  1618. this.value = "#ffffff";
  1619. this.format = "hex";
  1620. this.inline = false;
  1621. this.size = "medium";
  1622. this.noFormatToggle = false;
  1623. this.name = "";
  1624. this.disabled = false;
  1625. this.invalid = false;
  1626. this.hoist = false;
  1627. this.opacity = false;
  1628. this.uppercase = false;
  1629. this.swatches = [
  1630. "#d0021b",
  1631. "#f5a623",
  1632. "#f8e71c",
  1633. "#8b572a",
  1634. "#7ed321",
  1635. "#417505",
  1636. "#bd10e0",
  1637. "#9013fe",
  1638. "#4a90e2",
  1639. "#50e3c2",
  1640. "#b8e986",
  1641. "#000",
  1642. "#444",
  1643. "#888",
  1644. "#ccc",
  1645. "#fff"
  1646. ];
  1647. }
  1648. connectedCallback() {
  1649. super.connectedCallback();
  1650. if (!this.setColor(this.value)) {
  1651. this.setColor(`#ffff`);
  1652. }
  1653. this.inputValue = this.value;
  1654. this.lastValueEmitted = this.value;
  1655. this.syncValues();
  1656. }
  1657. getFormattedValue(format = "hex") {
  1658. const currentColor = this.parseColor(`hsla(${this.hue}, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`);
  1659. if (!currentColor) {
  1660. return "";
  1661. }
  1662. switch (format) {
  1663. case "hex":
  1664. return currentColor.hex;
  1665. case "hexa":
  1666. return currentColor.hexa;
  1667. case "rgb":
  1668. return currentColor.rgb.string;
  1669. case "rgba":
  1670. return currentColor.rgba.string;
  1671. case "hsl":
  1672. return currentColor.hsl.string;
  1673. case "hsla":
  1674. return currentColor.hsla.string;
  1675. default:
  1676. return "";
  1677. }
  1678. }
  1679. reportValidity() {
  1680. if (!this.inline && this.input.invalid) {
  1681. return new Promise((resolve) => {
  1682. this.dropdown.addEventListener("sl-after-show", () => {
  1683. this.input.reportValidity();
  1684. resolve();
  1685. }, { once: true });
  1686. this.dropdown.show();
  1687. });
  1688. } else {
  1689. return this.input.reportValidity();
  1690. }
  1691. }
  1692. setCustomValidity(message) {
  1693. this.input.setCustomValidity(message);
  1694. this.invalid = this.input.invalid;
  1695. }
  1696. handleCopy() {
  1697. this.input.select();
  1698. document.execCommand("copy");
  1699. this.previewButton.focus();
  1700. this.showCopyFeedback = true;
  1701. this.previewButton.addEventListener("animationend", () => this.showCopyFeedback = false, { once: true });
  1702. }
  1703. handleFormatToggle() {
  1704. const formats = ["hex", "rgb", "hsl"];
  1705. const nextIndex = (formats.indexOf(this.format) + 1) % formats.length;
  1706. this.format = formats[nextIndex];
  1707. }
  1708. handleAlphaDrag(event2) {
  1709. const container = this.shadowRoot.querySelector(".color-picker__slider.color-picker__alpha");
  1710. const handle = container.querySelector(".color-picker__slider-handle");
  1711. const { width } = container.getBoundingClientRect();
  1712. handle.focus();
  1713. event2.preventDefault();
  1714. this.handleDrag(event2, container, (x) => {
  1715. this.alpha = clamp(x / width * 100, 0, 100);
  1716. this.syncValues();
  1717. });
  1718. }
  1719. handleHueDrag(event2) {
  1720. const container = this.shadowRoot.querySelector(".color-picker__slider.color-picker__hue");
  1721. const handle = container.querySelector(".color-picker__slider-handle");
  1722. const { width } = container.getBoundingClientRect();
  1723. handle.focus();
  1724. event2.preventDefault();
  1725. this.handleDrag(event2, container, (x) => {
  1726. this.hue = clamp(x / width * 360, 0, 360);
  1727. this.syncValues();
  1728. });
  1729. }
  1730. handleGridDrag(event2) {
  1731. const grid = this.shadowRoot.querySelector(".color-picker__grid");
  1732. const handle = grid.querySelector(".color-picker__grid-handle");
  1733. const { width, height } = grid.getBoundingClientRect();
  1734. handle.focus();
  1735. event2.preventDefault();
  1736. this.handleDrag(event2, grid, (x, y) => {
  1737. this.saturation = clamp(x / width * 100, 0, 100);
  1738. this.lightness = clamp(100 - y / height * 100, 0, 100);
  1739. this.syncValues();
  1740. });
  1741. }
  1742. handleDrag(event2, container, onMove) {
  1743. if (this.disabled) {
  1744. return;
  1745. }
  1746. const move = (event3) => {
  1747. const dims = container.getBoundingClientRect();
  1748. const defaultView = container.ownerDocument.defaultView;
  1749. const offsetX = dims.left + defaultView.pageXOffset;
  1750. const offsetY = dims.top + defaultView.pageYOffset;
  1751. const x = (event3.changedTouches ? event3.changedTouches[0].pageX : event3.pageX) - offsetX;
  1752. const y = (event3.changedTouches ? event3.changedTouches[0].pageY : event3.pageY) - offsetY;
  1753. onMove(x, y);
  1754. };
  1755. move(event2);
  1756. const stop = () => {
  1757. document.removeEventListener("mousemove", move);
  1758. document.removeEventListener("touchmove", move);
  1759. document.removeEventListener("mouseup", stop);
  1760. document.removeEventListener("touchend", stop);
  1761. };
  1762. document.addEventListener("mousemove", move);
  1763. document.addEventListener("touchmove", move);
  1764. document.addEventListener("mouseup", stop);
  1765. document.addEventListener("touchend", stop);
  1766. }
  1767. handleAlphaKeyDown(event2) {
  1768. const increment = event2.shiftKey ? 10 : 1;
  1769. if (event2.key === "ArrowLeft") {
  1770. event2.preventDefault();
  1771. this.alpha = clamp(this.alpha - increment, 0, 100);
  1772. this.syncValues();
  1773. }
  1774. if (event2.key === "ArrowRight") {
  1775. event2.preventDefault();
  1776. this.alpha = clamp(this.alpha + increment, 0, 100);
  1777. this.syncValues();
  1778. }
  1779. if (event2.key === "Home") {
  1780. event2.preventDefault();
  1781. this.alpha = 0;
  1782. this.syncValues();
  1783. }
  1784. if (event2.key === "End") {
  1785. event2.preventDefault();
  1786. this.alpha = 100;
  1787. this.syncValues();
  1788. }
  1789. }
  1790. handleHueKeyDown(event2) {
  1791. const increment = event2.shiftKey ? 10 : 1;
  1792. if (event2.key === "ArrowLeft") {
  1793. event2.preventDefault();
  1794. this.hue = clamp(this.hue - increment, 0, 360);
  1795. this.syncValues();
  1796. }
  1797. if (event2.key === "ArrowRight") {
  1798. event2.preventDefault();
  1799. this.hue = clamp(this.hue + increment, 0, 360);
  1800. this.syncValues();
  1801. }
  1802. if (event2.key === "Home") {
  1803. event2.preventDefault();
  1804. this.hue = 0;
  1805. this.syncValues();
  1806. }
  1807. if (event2.key === "End") {
  1808. event2.preventDefault();
  1809. this.hue = 360;
  1810. this.syncValues();
  1811. }
  1812. }
  1813. handleGridKeyDown(event2) {
  1814. const increment = event2.shiftKey ? 10 : 1;
  1815. if (event2.key === "ArrowLeft") {
  1816. event2.preventDefault();
  1817. this.saturation = clamp(this.saturation - increment, 0, 100);
  1818. this.syncValues();
  1819. }
  1820. if (event2.key === "ArrowRight") {
  1821. event2.preventDefault();
  1822. this.saturation = clamp(this.saturation + increment, 0, 100);
  1823. this.syncValues();
  1824. }
  1825. if (event2.key === "ArrowUp") {
  1826. event2.preventDefault();
  1827. this.lightness = clamp(this.lightness + increment, 0, 100);
  1828. this.syncValues();
  1829. }
  1830. if (event2.key === "ArrowDown") {
  1831. event2.preventDefault();
  1832. this.lightness = clamp(this.lightness - increment, 0, 100);
  1833. this.syncValues();
  1834. }
  1835. }
  1836. handleInputChange(event2) {
  1837. const target = event2.target;
  1838. this.setColor(target.value);
  1839. target.value = this.value;
  1840. event2.stopPropagation();
  1841. }
  1842. handleInputKeyDown(event2) {
  1843. if (event2.key === "Enter") {
  1844. this.setColor(this.input.value);
  1845. this.input.value = this.value;
  1846. setTimeout(() => this.input.select());
  1847. }
  1848. }
  1849. handleDropdownAfterHide() {
  1850. this.showCopyFeedback = false;
  1851. }
  1852. normalizeColorString(colorString) {
  1853. if (/rgba?/i.test(colorString)) {
  1854. const rgba = colorString.replace(/[^\d.%]/g, " ").split(" ").map((val) => val.trim()).filter((val) => val.length);
  1855. if (rgba.length < 4) {
  1856. rgba[3] = "1";
  1857. }
  1858. if (rgba[3].indexOf("%") > -1) {
  1859. rgba[3] = (Number(rgba[3].replace(/%/g, "")) / 100).toString();
  1860. }
  1861. return `rgba(${rgba[0]}, ${rgba[1]}, ${rgba[2]}, ${rgba[3]})`;
  1862. }
  1863. if (/hsla?/i.test(colorString)) {
  1864. const hsla = colorString.replace(/[^\d.%]/g, " ").split(" ").map((val) => val.trim()).filter((val) => val.length);
  1865. if (hsla.length < 4) {
  1866. hsla[3] = "1";
  1867. }
  1868. if (hsla[3].indexOf("%") > -1) {
  1869. hsla[3] = (Number(hsla[3].replace(/%/g, "")) / 100).toString();
  1870. }
  1871. return `hsla(${hsla[0]}, ${hsla[1]}, ${hsla[2]}, ${hsla[3]})`;
  1872. }
  1873. if (/^[0-9a-f]+$/i.test(colorString)) {
  1874. return `#${colorString}`;
  1875. }
  1876. return colorString;
  1877. }
  1878. parseColor(colorString) {
  1879. function toHex(value) {
  1880. const hex2 = Math.round(value).toString(16);
  1881. return hex2.length === 1 ? `0${hex2}` : hex2;
  1882. }
  1883. let parsed;
  1884. colorString = this.normalizeColorString(colorString);
  1885. try {
  1886. parsed = (0, import_color.default)(colorString);
  1887. } catch (e3) {
  1888. return false;
  1889. }
  1890. const hsl = {
  1891. h: parsed.hsl().color[0],
  1892. s: parsed.hsl().color[1],
  1893. l: parsed.hsl().color[2],
  1894. a: parsed.hsl().valpha
  1895. };
  1896. const rgb = {
  1897. r: parsed.rgb().color[0],
  1898. g: parsed.rgb().color[1],
  1899. b: parsed.rgb().color[2],
  1900. a: parsed.rgb().valpha
  1901. };
  1902. const hex = {
  1903. r: toHex(parsed.rgb().color[0]),
  1904. g: toHex(parsed.rgb().color[1]),
  1905. b: toHex(parsed.rgb().color[2]),
  1906. a: toHex(parsed.rgb().valpha * 255)
  1907. };
  1908. return {
  1909. hsl: {
  1910. h: hsl.h,
  1911. s: hsl.s,
  1912. l: hsl.l,
  1913. string: this.setLetterCase(`hsl(${Math.round(hsl.h)}, ${Math.round(hsl.s)}%, ${Math.round(hsl.l)}%)`)
  1914. },
  1915. hsla: {
  1916. h: hsl.h,
  1917. s: hsl.s,
  1918. l: hsl.l,
  1919. a: hsl.a,
  1920. string: this.setLetterCase(`hsla(${Math.round(hsl.h)}, ${Math.round(hsl.s)}%, ${Math.round(hsl.l)}%, ${Number(hsl.a.toFixed(2).toString())})`)
  1921. },
  1922. rgb: {
  1923. r: rgb.r,
  1924. g: rgb.g,
  1925. b: rgb.b,
  1926. string: this.setLetterCase(`rgb(${Math.round(rgb.r)}, ${Math.round(rgb.g)}, ${Math.round(rgb.b)})`)
  1927. },
  1928. rgba: {
  1929. r: rgb.r,
  1930. g: rgb.g,
  1931. b: rgb.b,
  1932. a: rgb.a,
  1933. string: this.setLetterCase(`rgba(${Math.round(rgb.r)}, ${Math.round(rgb.g)}, ${Math.round(rgb.b)}, ${Number(rgb.a.toFixed(2).toString())})`)
  1934. },
  1935. hex: this.setLetterCase(`#${hex.r}${hex.g}${hex.b}`),
  1936. hexa: this.setLetterCase(`#${hex.r}${hex.g}${hex.b}${hex.a}`)
  1937. };
  1938. }
  1939. setColor(colorString) {
  1940. const newColor = this.parseColor(colorString);
  1941. if (!newColor) {
  1942. return false;
  1943. }
  1944. this.hue = newColor.hsla.h;
  1945. this.saturation = newColor.hsla.s;
  1946. this.lightness = newColor.hsla.l;
  1947. this.alpha = this.opacity ? newColor.hsla.a * 100 : 100;
  1948. this.syncValues();
  1949. return true;
  1950. }
  1951. setLetterCase(string) {
  1952. if (typeof string !== "string")
  1953. return "";
  1954. return this.uppercase ? string.toUpperCase() : string.toLowerCase();
  1955. }
  1956. syncValues() {
  1957. const currentColor = this.parseColor(`hsla(${this.hue}, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`);
  1958. if (!currentColor) {
  1959. return;
  1960. }
  1961. if (this.format === "hsl") {
  1962. this.inputValue = this.opacity ? currentColor.hsla.string : currentColor.hsl.string;
  1963. } else if (this.format === "rgb") {
  1964. this.inputValue = this.opacity ? currentColor.rgba.string : currentColor.rgb.string;
  1965. } else {
  1966. this.inputValue = this.opacity ? currentColor.hexa : currentColor.hex;
  1967. }
  1968. this.value = this.inputValue;
  1969. }
  1970. handleFormatChange() {
  1971. this.syncValues();
  1972. }
  1973. handleOpacityChange() {
  1974. this.alpha = 100;
  1975. }
  1976. handleValueChange(oldValue, newValue) {
  1977. const newColor = this.parseColor(newValue);
  1978. if (newColor) {
  1979. this.inputValue = this.value;
  1980. this.hue = newColor.hsla.h;
  1981. this.saturation = newColor.hsla.s;
  1982. this.lightness = newColor.hsla.l;
  1983. this.alpha = newColor.hsla.a * 100;
  1984. } else {
  1985. this.inputValue = oldValue;
  1986. }
  1987. if (this.value !== this.lastValueEmitted) {
  1988. this.slChange.emit();
  1989. this.lastValueEmitted = this.value;
  1990. }
  1991. }
  1992. render() {
  1993. const x = this.saturation;
  1994. const y = 100 - this.lightness;
  1995. const colorPicker = T`
  1996. <div
  1997. part="base"
  1998. class=${e2({
  1999. "color-picker": true,
  2000. "color-picker--inline": this.inline,
  2001. "color-picker--disabled": this.disabled
  2002. })}
  2003. aria-disabled=${this.disabled ? "true" : "false"}
  2004. >
  2005. <div
  2006. part="grid"
  2007. class="color-picker__grid"
  2008. style=${i({ backgroundColor: `hsl(${this.hue}deg, 100%, 50%)` })}
  2009. @mousedown=${this.handleGridDrag}
  2010. @touchstart=${this.handleGridDrag}
  2011. >
  2012. <span
  2013. part="grid-handle"
  2014. class="color-picker__grid-handle"
  2015. style=${i({
  2016. top: `${y}%`,
  2017. left: `${x}%`,
  2018. backgroundColor: `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%)`
  2019. })}
  2020. role="slider"
  2021. aria-label="HSL"
  2022. aria-valuetext=${`hsl(${Math.round(this.hue)}, ${Math.round(this.saturation)}%, ${Math.round(this.lightness)}%)`}
  2023. tabindex=${l(this.disabled ? void 0 : "0")}
  2024. @keydown=${this.handleGridKeyDown}
  2025. ></span>
  2026. </div>
  2027. <div class="color-picker__controls">
  2028. <div class="color-picker__sliders">
  2029. <div
  2030. part="slider hue-slider"
  2031. class="color-picker__hue color-picker__slider"
  2032. @mousedown=${this.handleHueDrag}
  2033. @touchstart=${this.handleHueDrag}
  2034. >
  2035. <span
  2036. part="slider-handle"
  2037. class="color-picker__slider-handle"
  2038. style=${i({
  2039. left: `${this.hue === 0 ? 0 : 100 / (360 / this.hue)}%`
  2040. })}
  2041. role="slider"
  2042. aria-label="hue"
  2043. aria-orientation="horizontal"
  2044. aria-valuemin="0"
  2045. aria-valuemax="360"
  2046. aria-valuenow=${Math.round(this.hue)}
  2047. tabindex=${l(this.disabled ? void 0 : "0")}
  2048. @keydown=${this.handleHueKeyDown}
  2049. ></span>
  2050. </div>
  2051. ${this.opacity ? T`
  2052. <div
  2053. part="slider opacity-slider"
  2054. class="color-picker__alpha color-picker__slider color-picker__transparent-bg"
  2055. @mousedown="${this.handleAlphaDrag}"
  2056. @touchstart="${this.handleAlphaDrag}"
  2057. >
  2058. <div
  2059. class="color-picker__alpha-gradient"
  2060. style=${i({
  2061. backgroundImage: `linear-gradient(
  2062. to right,
  2063. hsl(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, 0%) 0%,
  2064. hsl(${this.hue}deg, ${this.saturation}%, ${this.lightness}%) 100%
  2065. )`
  2066. })}
  2067. ></div>
  2068. <span
  2069. part="slider-handle"
  2070. class="color-picker__slider-handle"
  2071. style=${i({
  2072. left: `${this.alpha}%`
  2073. })}
  2074. role="slider"
  2075. aria-label="alpha"
  2076. aria-orientation="horizontal"
  2077. aria-valuemin="0"
  2078. aria-valuemax="100"
  2079. aria-valuenow=${Math.round(this.alpha)}
  2080. tabindex=${l(this.disabled ? void 0 : "0")}
  2081. @keydown=${this.handleAlphaKeyDown}
  2082. ></span>
  2083. </div>
  2084. ` : ""}
  2085. </div>
  2086. <button
  2087. type="button"
  2088. part="preview"
  2089. class="color-picker__preview color-picker__transparent-bg"
  2090. style=${i({
  2091. "--preview-color": `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`
  2092. })}
  2093. @click=${this.handleCopy}
  2094. >
  2095. <sl-icon
  2096. name="check"
  2097. library="system"
  2098. class=${e2({
  2099. "color-picker__copy-feedback": true,
  2100. "color-picker__copy-feedback--visible": this.showCopyFeedback,
  2101. "color-picker__copy-feedback--dark": this.lightness > 50
  2102. })}
  2103. ></sl-icon>
  2104. </button>
  2105. </div>
  2106. <div class="color-picker__user-input">
  2107. <sl-input
  2108. part="input"
  2109. size="small"
  2110. type="text"
  2111. name=${this.name}
  2112. autocomplete="off"
  2113. autocorrect="off"
  2114. autocapitalize="off"
  2115. spellcheck="false"
  2116. .value=${this.inputValue}
  2117. ?disabled=${this.disabled}
  2118. @keydown=${this.handleInputKeyDown}
  2119. @sl-change=${this.handleInputChange}
  2120. ></sl-input>
  2121. ${!this.noFormatToggle ? T`
  2122. <sl-button exportparts="base:format-button" size="small" @click=${this.handleFormatToggle}>
  2123. ${this.setLetterCase(this.format)}
  2124. </sl-button>
  2125. ` : ""}
  2126. </div>
  2127. ${this.swatches ? T`
  2128. <div part="swatches" class="color-picker__swatches">
  2129. ${this.swatches.map((swatch) => {
  2130. return T`
  2131. <div
  2132. part="swatch"
  2133. class="color-picker__swatch color-picker__transparent-bg"
  2134. tabindex=${l(this.disabled ? void 0 : "0")}
  2135. role="button"
  2136. aria-label=${swatch}
  2137. @click=${() => !this.disabled && this.setColor(swatch)}
  2138. @keydown=${(event2) => !this.disabled && event2.key === "Enter" && this.setColor(swatch)}
  2139. >
  2140. <div class="color-picker__swatch-color" style=${i({ backgroundColor: swatch })}></div>
  2141. </div>
  2142. `;
  2143. })}
  2144. </div>
  2145. ` : ""}
  2146. </div>
  2147. `;
  2148. if (this.inline) {
  2149. return colorPicker;
  2150. }
  2151. return T`
  2152. <sl-dropdown
  2153. class="color-dropdown"
  2154. aria-disabled=${this.disabled ? "true" : "false"}
  2155. .containing-element=${this}
  2156. ?disabled=${this.disabled}
  2157. ?hoist=${this.hoist}
  2158. @sl-after-hide=${this.handleDropdownAfterHide}
  2159. >
  2160. <button
  2161. part="trigger"
  2162. slot="trigger"
  2163. class=${e2({
  2164. "color-dropdown__trigger": true,
  2165. "color-dropdown__trigger--disabled": this.disabled,
  2166. "color-dropdown__trigger--small": this.size === "small",
  2167. "color-dropdown__trigger--medium": this.size === "medium",
  2168. "color-dropdown__trigger--large": this.size === "large",
  2169. "color-picker__transparent-bg": true
  2170. })}
  2171. style=${i({
  2172. color: `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`
  2173. })}
  2174. type="button"
  2175. ></button>
  2176. ${colorPicker}
  2177. </sl-dropdown>
  2178. `;
  2179. }
  2180. };
  2181. SlColorPicker.styles = r(color_picker_default);
  2182. __decorateClass([
  2183. o('[part="input"]')
  2184. ], SlColorPicker.prototype, "input", 2);
  2185. __decorateClass([
  2186. o('[part="preview"]')
  2187. ], SlColorPicker.prototype, "previewButton", 2);
  2188. __decorateClass([
  2189. o(".color-dropdown")
  2190. ], SlColorPicker.prototype, "dropdown", 2);
  2191. __decorateClass([
  2192. r2()
  2193. ], SlColorPicker.prototype, "inputValue", 2);
  2194. __decorateClass([
  2195. r2()
  2196. ], SlColorPicker.prototype, "hue", 2);
  2197. __decorateClass([
  2198. r2()
  2199. ], SlColorPicker.prototype, "saturation", 2);
  2200. __decorateClass([
  2201. r2()
  2202. ], SlColorPicker.prototype, "lightness", 2);
  2203. __decorateClass([
  2204. r2()
  2205. ], SlColorPicker.prototype, "alpha", 2);
  2206. __decorateClass([
  2207. r2()
  2208. ], SlColorPicker.prototype, "showCopyFeedback", 2);
  2209. __decorateClass([
  2210. e()
  2211. ], SlColorPicker.prototype, "value", 2);
  2212. __decorateClass([
  2213. e()
  2214. ], SlColorPicker.prototype, "format", 2);
  2215. __decorateClass([
  2216. e({ type: Boolean, reflect: true })
  2217. ], SlColorPicker.prototype, "inline", 2);
  2218. __decorateClass([
  2219. e()
  2220. ], SlColorPicker.prototype, "size", 2);
  2221. __decorateClass([
  2222. e({ attribute: "no-format-toggle", type: Boolean })
  2223. ], SlColorPicker.prototype, "noFormatToggle", 2);
  2224. __decorateClass([
  2225. e()
  2226. ], SlColorPicker.prototype, "name", 2);
  2227. __decorateClass([
  2228. e({ type: Boolean, reflect: true })
  2229. ], SlColorPicker.prototype, "disabled", 2);
  2230. __decorateClass([
  2231. e({ type: Boolean, reflect: true })
  2232. ], SlColorPicker.prototype, "invalid", 2);
  2233. __decorateClass([
  2234. e({ type: Boolean })
  2235. ], SlColorPicker.prototype, "hoist", 2);
  2236. __decorateClass([
  2237. e({ type: Boolean })
  2238. ], SlColorPicker.prototype, "opacity", 2);
  2239. __decorateClass([
  2240. e({ type: Boolean })
  2241. ], SlColorPicker.prototype, "uppercase", 2);
  2242. __decorateClass([
  2243. e({ attribute: false })
  2244. ], SlColorPicker.prototype, "swatches", 2);
  2245. __decorateClass([
  2246. event("sl-change")
  2247. ], SlColorPicker.prototype, "slChange", 2);
  2248. __decorateClass([
  2249. watch("format")
  2250. ], SlColorPicker.prototype, "handleFormatChange", 1);
  2251. __decorateClass([
  2252. watch("opacity")
  2253. ], SlColorPicker.prototype, "handleOpacityChange", 1);
  2254. __decorateClass([
  2255. watch("value")
  2256. ], SlColorPicker.prototype, "handleValueChange", 1);
  2257. SlColorPicker = __decorateClass([
  2258. n("sl-color-picker")
  2259. ], SlColorPicker);
  2260. var color_picker_default2 = SlColorPicker;
  2261. export {
  2262. color_picker_default2 as color_picker_default
  2263. };