UNPKG

color-sorter

Version:
2 lines (1 loc) 1.3 kB
(function(o,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("colorjs.io/fn")):typeof define=="function"&&define.amd?define(["exports","colorjs.io/fn"],r):(o=typeof globalThis<"u"?globalThis:o||self,r(o.colorSorter={},o.fn))})(this,function(o,r){"use strict";r.ColorSpace.register(r.sRGB),r.ColorSpace.register(r.P3),r.ColorSpace.register(r.HSL),r.ColorSpace.register(r.LCH),r.ColorSpace.register(r.OKLCH);function n(e){return typeof e=="number"&&Number.isFinite(e)?e:0}function u(e){try{let t=r.parse(e),s=t.spaceId==="hsl"?t:r.to(t,r.HSL),i=s.coords,h=n(i[0]),p=n(i[1]),f=n(i[2]),d=n(s.alpha);return{hue:h,saturation:p,lightness:f,alpha:d,authored:e}}catch{return{hue:0,saturation:0,lightness:0,alpha:0,authored:e}}}function a(e,t){return(e.saturation===0||t.saturation===0)&&e.saturation!==t.saturation?t.saturation-e.saturation:e.hue!==t.hue?e.hue-t.hue:e.saturation!==t.saturation?e.saturation-t.saturation:e.saturation===0&&t.saturation===0&&e.lightness!==t.lightness?t.lightness-e.lightness:e.alpha===t.alpha?e.authored.toLowerCase().localeCompare(t.authored.toLowerCase()):t.alpha-e.alpha}function l(e,t){let s=u(e),i=u(t);return a(s,i)}function c(e){return e.sort(l)}o.compare=a,o.convert=u,o.sort=c,o.sortFn=l,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});