@omi-io/color-css 0.1.0
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.
- package/README.md +92 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/parse/index.cjs +1 -0
- package/dist/cjs/serialize/index.cjs +1 -0
- package/dist/esm/chunk-7G5PE7V2.js +1 -0
- package/dist/esm/chunk-FGDLWKLI.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/parse/index.js +1 -0
- package/dist/esm/serialize/index.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/named-colors.d.ts +1 -0
- package/dist/types/parse/channels.d.ts +5 -0
- package/dist/types/parse/functions-lab.d.ts +2 -0
- package/dist/types/parse/functions-rgb.d.ts +2 -0
- package/dist/types/parse/hex.d.ts +2 -0
- package/dist/types/parse/index.d.ts +2 -0
- package/dist/types/parse/parse.d.ts +2 -0
- package/dist/types/parse/scales.d.ts +13 -0
- package/dist/types/parse/tokens.d.ts +8 -0
- package/dist/types/parse/types.d.ts +20 -0
- package/dist/types/serialize/display.d.ts +7 -0
- package/dist/types/serialize/index.d.ts +3 -0
- package/dist/types/serialize/model.d.ts +6 -0
- package/dist/types/serialize/shared.d.ts +8 -0
- package/dist/types/serialize/types.d.ts +9 -0
- package/package.json +81 -0
- package/parse/package.json +7 -0
- package/serialize/package.json +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# `@omi-io/color-css`
|
|
2
|
+
|
|
3
|
+
CSS color strings ⇄ engine values. `parseColor` normalizes any supported
|
|
4
|
+
syntax to canonical `[0,1]` sRGB-encoded RGB plus alpha; the `format*`
|
|
5
|
+
serializers render engine tuples back as CSS tokens. No math beyond
|
|
6
|
+
rounding happens here — every conversion goes through
|
|
7
|
+
`@omi-io/color-convert`.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn add @omi-io/color-css
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Example — keeping formats in sync
|
|
16
|
+
|
|
17
|
+
The classic converter-UI loop: parse whatever the user typed, then render
|
|
18
|
+
every representation from the one canonical value.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { parseColor, formatHex, formatRgb, formatHsl, formatOklch } from "@omi-io/color-css";
|
|
22
|
+
import { rgbToOklch } from "@omi-io/color-convert";
|
|
23
|
+
|
|
24
|
+
const parsed = parseColor("oklch(70% 0.1 180 / 50%)");
|
|
25
|
+
if (parsed) {
|
|
26
|
+
const { rgb, alpha } = parsed;
|
|
27
|
+
formatHex(rgb, alpha); // "#4bb3a180"
|
|
28
|
+
formatRgb(rgb, alpha); // "rgb(75 179 161 / 0.5)"
|
|
29
|
+
formatHsl(rgb, alpha); // "hsl(169.568 41.063% 49.692% / 0.5)"
|
|
30
|
+
formatOklch(rgbToOklch(rgb), alpha); // "oklch(0.7 0.1 180 / 0.5)"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
parseColor("garbage"); // null — callers keep the previous valid color
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Supported syntaxes (`parseColor`)
|
|
37
|
+
|
|
38
|
+
| Syntax | Examples | Notes |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| hex | `#f00`, `#ff0000`, `#ff000080`, `663399` | leading `#` optional; 4/8 digits carry alpha |
|
|
41
|
+
| named | `rebeccapurple`, `transparent` | full 148-keyword table (`CSS_NAMED_COLORS`); `transparent` → alpha 0 |
|
|
42
|
+
| `rgb()` / `rgba()` | `rgb(255 0 0 / 50%)`, `rgb(100% 0% 0%)`, `rgba(255, 0, 0, .5)` | number ×1/255, `%` ×0.01 |
|
|
43
|
+
| `hsl()` / `hsla()` | `hsl(210 50% 50%)`, `hsl(0.5turn 100 50)` | s/l: number = percentage; hue units `deg`/`grad`/`rad`/`turn` |
|
|
44
|
+
| `hsv()` / `hsva()` | `hsv(120 100% 100%)` | same scales as `hsl()` |
|
|
45
|
+
| `cmyk()` / `device-cmyk()` | `cmyk(0% 81% 81% 30%)`, `device-cmyk(0 .81 .81 .3)` | number = `[0,1]` unit, `%` ×0.01 |
|
|
46
|
+
| `lab()` / `lch()` | `lab(50% 40 30)`, `lch(50 40% 30deg)` | D50 → sRGB via Bradford; `L%` ×1, `a`/`b%` ×1.25, `C%` ×1.5 |
|
|
47
|
+
| `oklab()` / `oklch()` | `oklch(70% 0.1 180)`, `oklab(0.7 -0.05 0.05)` | `L%` ×0.01, `a`/`b`/`C` `%` ×0.004 (100% = 0.4) |
|
|
48
|
+
| `color()` | `color(srgb 1 0 0)`, `color(display-p3 1 0 0 / .5)` | spaces: `srgb`, `display-p3` (D65, exact matrix path) |
|
|
49
|
+
|
|
50
|
+
Everything is case-insensitive; modern space-separated and legacy
|
|
51
|
+
comma-separated argument forms are both accepted, alpha after `/` (or as
|
|
52
|
+
the legacy 4th argument), `none` → `0` (powerless hue included).
|
|
53
|
+
Unrecognised input → `null`.
|
|
54
|
+
|
|
55
|
+
**No clamping.** Wide-gamut and high-chroma input yields out-of-gamut RGB
|
|
56
|
+
as computed (e.g. `color(display-p3 1 0 0)` → `r > 1`, `g,b < 0`); gamut
|
|
57
|
+
mapping is the explicit opt-in layer in `@omi-io/color-gamut`. Alpha is
|
|
58
|
+
the exception and clamps to `[0,1]`.
|
|
59
|
+
|
|
60
|
+
## Serializers
|
|
61
|
+
|
|
62
|
+
| Export | Input | Output | Clamps? |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `formatHex(rgb, alpha?)` | `[0,1]` RGB | `#rrggbb` / `#rrggbbaa` (lowercase, alpha omitted when opaque) | yes |
|
|
65
|
+
| `formatRgb(rgb, alpha?, opts?)` | `[0,1]` RGB | `rgb(R G B)` or `rgb(R% G% B%)` (+` / A`) | yes |
|
|
66
|
+
| `formatHsl(rgb, alpha?, opts?)` | `[0,1]` RGB | `hsl(H S% L%)` (+` / A`) | yes |
|
|
67
|
+
| `formatHsv(rgb, alpha?, opts?)` | `[0,1]` RGB | `hsv(H S% V%)` (+` / A`) | yes |
|
|
68
|
+
| `formatCmyk(rgb, opts?)` | `[0,1]` RGB | `cmyk(C% M% Y% K%)` | yes |
|
|
69
|
+
| `formatOklch(oklch, alpha?, opts?)` | `Oklch` | `oklch(L C H)`; `percentLightness` → `oklch(70% …)` | no |
|
|
70
|
+
| `formatOklab(oklab, alpha?, opts?)` | `Oklab` | `oklab(L a b)` | no |
|
|
71
|
+
| `formatLab(lab, alpha?, opts?)` | `Lab` (D50) | `lab(L a b)` | no |
|
|
72
|
+
| `formatLch(lch, alpha?, opts?)` | `LCh` (D50) | `lch(L C H)` | no |
|
|
73
|
+
|
|
74
|
+
Display-referred formats (hex/rgb/hsl/hsv/cmyk) clamp — they describe
|
|
75
|
+
pixels — and are byte-for-byte compatible with the app-local
|
|
76
|
+
`_engine/format.ts` they replace. Model formats serialize out-of-gamut
|
|
77
|
+
values as-is and emit `none` for the hue when chroma ≤ `EPSILON_CHROMA`
|
|
78
|
+
(the parser reads `none` back as `0`). `opts.decimals` controls precision
|
|
79
|
+
(default: 3; 4 for `oklab`/`oklch`; rgb bytes 0, rgb percent 1).
|
|
80
|
+
|
|
81
|
+
## Subpath exports
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { parseColor } from "@omi-io/color-css/parse";
|
|
85
|
+
import { formatOklch } from "@omi-io/color-css/serialize";
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Related packages
|
|
89
|
+
|
|
90
|
+
- `@omi-io/color-convert` — the conversions this package delegates to.
|
|
91
|
+
- `@omi-io/color-gamut` — in-gamut checks and CSS Color 4 gamut mapping.
|
|
92
|
+
- `@omi-io/color-models` — branded tuples incl. alpha-bearing `RGBA`, `Oklcha`, ….
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var P=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var de=(e,r)=>{for(var n in r)P(e,n,{get:r[n],enumerable:!0})},ge=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of me(r))!pe.call(e,o)&&o!==n&&P(e,o,{get:()=>r[o],enumerable:!(t=ue(r,o))||t.enumerable});return e};var be=e=>ge(P({},"__esModule",{value:!0}),e);var Se={};de(Se,{CSS_NAMED_COLORS:()=>A,formatCmyk:()=>X,formatHex:()=>D,formatHsl:()=>V,formatHsv:()=>q,formatLab:()=>j,formatLch:()=>W,formatOklab:()=>Y,formatOklch:()=>z,formatRgb:()=>K,parseColor:()=>M});module.exports=be(Se);var A={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",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};var h=require("@omi-io/color-convert"),F=require("@omi-io/color-models");var B=require("@omi-io/color-convert"),te=require("@omi-io/color-models");var S={number:.00392156862745098,percent:.01},x={number:.01,percent:.01},g={number:1,percent:.01},N={number:1,percent:1},G={number:1,percent:1.25},J={number:1,percent:1.5},v={number:1,percent:.01},$={number:1,percent:.004},Q={number:1,percent:.01},Z={srgb:"sRGB","display-p3":"Display P3"},w={adaptation:{transform:"Bradford"}};var ee=require("@omi-io/color-core");var re=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$/i,he=/^(deg|grad|rad|turn)$/;function ne(e,r){if(e==="none")return 0;let n=e.endsWith("%"),t=n?e.slice(0,-1):e;return re.test(t)?parseFloat(t)*(n?r.percent:r.number):null}function ye(e){if(e==="none")return 0;let r=/(deg|grad|rad|turn)$/.exec(e),n=r?.[1]??"deg",t=r?e.slice(0,-n.length):e;if(!re.test(t)||!he.test(n))return null;let o=parseFloat(t);return n==="grad"?o*.9:n==="rad"?o*(180/Math.PI):n==="turn"?o*360:o}function T(e){if(e===void 0)return 1;let r=ne(e,Q);return r===null?null:(0,ee.clampUnit)(r)}function C(e){return[e[0]??0,e[1]??0,e[2]??0]}function E(e,r,n){let t=e.split("/");if(t.length>2)return null;let o=(t[0]??"").trim(),a=t.length===2?(t[1]??"").trim():void 0;if(a!==void 0&&a.length===0||o.length===0)return null;let s=o.split(/[,\s]+/);return n&&a===void 0&&s.length===r+1&&(a=s.pop()),s.length!==r?null:{components:s,alphaToken:a}}function _(e,r){if(e.length!==r.length)return null;let n=[];for(let t=0;t<r.length;t+=1){let o=e[t],a=r[t];if(o===void 0||a===void 0)return null;let s=a==="hue"?ye(o):ne(o,a);if(s===null)return null;n.push(s)}return n}function m(e,r,n){let t=E(e,r.length,!0);if(!t)return null;let o=_(t.components,r);if(!o)return null;let a=T(t.alphaToken);return a===null?null:{rgb:n(C(o)),alpha:a}}function oe(e){let r=E(e,4,!1);if(!r)return null;let n=_(r.components,[g,g,g,g]);if(!n)return null;let t=T(r.alphaToken);return t===null?null:{rgb:(0,B.cmykToRgb)(n),alpha:t}}function ae(e){let r=E(e,4,!1);if(!r)return null;let[n,...t]=r.components,o=n===void 0?void 0:Z[n];if(o===void 0)return null;let a=_(t,[g,g,g]);if(!a)return null;let s=T(r.alphaToken);if(s===null)return null;let f=C(a);return{rgb:o==="sRGB"?f:(0,B.convertRGBColorspace)((0,te.unsafeAsEncodedRGB)(f),o,"sRGB"),alpha:s}}function Ce(e){let{value:r}=(0,h.convertByPipeline)(e,"Lab D50","sRGB encoded",w);return C(r)}function Re(e){let{value:r}=(0,h.convertByPipeline)(e,"LCh","sRGB encoded",w);return C(r)}function se(e,r){switch(e){case"lab":{let n=m(r,[N,G,G],Ce);return n?{...n,source:"lab"}:null}case"lch":{let n=m(r,[N,J,"hue"],Re);return n?{...n,source:"lch"}:null}case"oklab":{let n=m(r,[v,$,$],t=>(0,h.oklabToRgb)((0,F.unsafeAsOklab)(t)));return n?{...n,source:"oklab"}:null}case"oklch":{let n=m(r,[v,$,"hue"],t=>(0,h.oklchToRgb)((0,F.unsafeAsOklch)(t)));return n?{...n,source:"oklch"}:null}default:return null}}var H=require("@omi-io/color-convert");function le(e,r){switch(e){case"rgb":case"rgba":{let n=m(r,[S,S,S],t=>t);return n?{...n,source:"rgb"}:null}case"hsl":case"hsla":{let n=m(r,["hue",x,x],t=>(0,H.hslToRgb)(t));return n?{...n,source:"hsl"}:null}case"hsv":case"hsva":{let n=m(r,["hue",x,x],t=>(0,H.hsvToRgb)(t));return n?{...n,source:"hsv"}:null}case"cmyk":case"device-cmyk":{let n=oe(r);return n?{...n,source:"cmyk"}:null}case"color":{let n=ae(r);return n?{...n,source:"color"}:null}default:return null}}var b=require("@omi-io/color-core"),ke=/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/,xe=/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/,Le=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/,Oe=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/;function i(e){return parseInt(e,16)}function I(e){let r=Oe.exec(e);if(r)return{rgb:(0,b.rgb8ToUnit)([i(r[1]??"0"),i(r[2]??"0"),i(r[3]??"0")]),alpha:(0,b.clampUnit)(i(r[4]??"ff")/255)};let n=Le.exec(e);if(n)return{rgb:(0,b.rgb8ToUnit)([i(n[1]??"0"),i(n[2]??"0"),i(n[3]??"0")]),alpha:1};let t=xe.exec(e);if(t){let[a,s,f,d]=[t[1]??"0",t[2]??"0",t[3]??"0",t[4]??"f"];return{rgb:(0,b.rgb8ToUnit)([i(a+a),i(s+s),i(f+f)]),alpha:(0,b.clampUnit)(i(d+d)/255)}}let o=ke.exec(e);if(o){let[a,s,f]=[o[1]??"0",o[2]??"0",o[3]??"0"];return{rgb:(0,b.rgb8ToUnit)([i(a+a),i(s+s),i(f+f)]),alpha:1}}return null}var Ae=/^([a-z-]+)\(\s*(.*?)\s*\)$/;function M(e){if(typeof e!="string")return null;let r=e.trim().toLowerCase();if(r.length===0)return null;if(r==="transparent")return{rgb:[0,0,0],alpha:0,source:"named"};let n=A[r];if(n!==void 0){let a=I(n);return a?{...a,source:"named"}:null}let t=Ae.exec(r);if(t){let a=t[1]??"",s=t[2]??"";return le(a,s)??se(a,s)}let o=I(r);return o?{...o,source:"hex"}:null}var R=require("@omi-io/color-convert"),c=require("@omi-io/color-core");var p=require("@omi-io/color-core"),y=3,U=4;function l(e,r){if(!Number.isFinite(e))return 0;let n=10**r;return Math.round(e*n)/n}function L(e){return Math.round((0,p.clampByteChannel)(e)).toString(16).padStart(2,"0")}function fe(e){return(0,p.unitToRgb8)([(0,p.clampUnit)(e[0]),(0,p.clampUnit)(e[1]),(0,p.clampUnit)(e[2])])}function u(e){if(e===void 0)return"";let r=(0,p.clampUnit)(e);return r>=1?"":` / ${l(r,3)}`}function O(e,r,n,t){return t?`${l(e*r,n)}%`:`${l(e,n)}`}function D(e,r){let[n,t,o]=fe(e),a=`#${L(n)}${L(t)}${L(o)}`;return r===void 0||(0,c.clampUnit)(r)>=1?a:`${a}${L((0,c.clampUnit)(r)*255)}`}function K(e,r,n){if(n?.percent){let f=n.decimals??1,d=l((0,c.clampUnit)(e[0])*100,f),ce=l((0,c.clampUnit)(e[1])*100,f),ie=l((0,c.clampUnit)(e[2])*100,f);return`rgb(${d}% ${ce}% ${ie}%${u(r)})`}let t=n?.decimals??0,[o,a,s]=(0,c.unitToRgb8)([(0,c.clampUnit)(e[0]),(0,c.clampUnit)(e[1]),(0,c.clampUnit)(e[2])],{decimals:t});return`rgb(${l(o,t)} ${l(a,t)} ${l(s,t)}${u(r)})`}function V(e,r,n){let t=n?.decimals??y,[o,a,s]=(0,R.rgbToHsl)(e);return`hsl(${l((0,c.wrapHueDegrees)(o),t)} ${l((0,c.clampUnit)(a)*100,t)}% ${l((0,c.clampUnit)(s)*100,t)}%${u(r)})`}function q(e,r,n){let t=n?.decimals??y,[o,a,s]=(0,R.rgbToHsv)(e);return`hsv(${l((0,c.wrapHueDegrees)(o),t)} ${l((0,c.clampUnit)(a)*100,t)}% ${l((0,c.clampUnit)(s)*100,t)}%${u(r)})`}function X(e,r){let n=r?.decimals??y,[t,o,a,s]=(0,R.rgbToCmyk)(e).map(f=>l((0,c.clampUnit)(f)*100,n));return`cmyk(${t}% ${o}% ${a}% ${s}%)`}var k=require("@omi-io/color-core");function z(e,r,n){let t=n?.decimals??U,[o,a,s]=e,f=O(o,100,t,n?.percentLightness),d=a<=k.EPSILON_CHROMA?"none":`${l((0,k.wrapHueDegrees)(s),t)}`;return`oklch(${f} ${l(a,t)} ${d}${u(r)})`}function Y(e,r,n){let t=n?.decimals??U,[o,a,s]=e;return`oklab(${O(o,100,t,n?.percentLightness)} ${l(a,t)} ${l(s,t)}${u(r)})`}function j(e,r,n){let t=n?.decimals??y,[o,a,s]=e;return`lab(${O(o,1,t,n?.percentLightness)} ${l(a,t)} ${l(s,t)}${u(r)})`}function W(e,r,n){let t=n?.decimals??y,[o,a,s]=e,f=O(o,1,t,n?.percentLightness),d=a<=k.EPSILON_CHROMA?"none":`${l((0,k.wrapHueDegrees)(s),t)}`;return`lch(${f} ${l(a,t)} ${d}${u(r)})`}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var x=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var X=(r,e)=>{for(var n in e)x(r,n,{get:e[n],enumerable:!0})},z=(r,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of $(e))!D.call(r,t)&&t!==n&&x(r,t,{get:()=>e[t],enumerable:!(o=q(e,t))||o.enumerable});return r};var Y=r=>z(x({},"__esModule",{value:!0}),r);var te={};X(te,{parseColor:()=>K});module.exports=Y(te);var N={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",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};var p=require("@omi-io/color-convert"),k=require("@omi-io/color-models");var R=require("@omi-io/color-convert"),I=require("@omi-io/color-models");var g={number:.00392156862745098,percent:.01},m={number:.01,percent:.01},i={number:1,percent:.01},T={number:1,percent:1},S={number:1,percent:1.25},B={number:1,percent:1.5},P={number:1,percent:.01},b={number:1,percent:.004},O={number:1,percent:.01},H={srgb:"sRGB","display-p3":"Display P3"},_={adaptation:{transform:"Bradford"}};var w=require("@omi-io/color-core");var v=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$/i,j=/^(deg|grad|rad|turn)$/;function G(r,e){if(r==="none")return 0;let n=r.endsWith("%"),o=n?r.slice(0,-1):r;return v.test(o)?parseFloat(o)*(n?e.percent:e.number):null}function W(r){if(r==="none")return 0;let e=/(deg|grad|rad|turn)$/.exec(r),n=e?.[1]??"deg",o=e?r.slice(0,-n.length):r;if(!v.test(o)||!j.test(n))return null;let t=parseFloat(o);return n==="grad"?t*.9:n==="rad"?t*(180/Math.PI):n==="turn"?t*360:t}function h(r){if(r===void 0)return 1;let e=G(r,O);return e===null?null:(0,w.clampUnit)(e)}function d(r){return[r[0]??0,r[1]??0,r[2]??0]}function y(r,e,n){let o=r.split("/");if(o.length>2)return null;let t=(o[0]??"").trim(),a=o.length===2?(o[1]??"").trim():void 0;if(a!==void 0&&a.length===0||t.length===0)return null;let l=t.split(/[,\s]+/);return n&&a===void 0&&l.length===e+1&&(a=l.pop()),l.length!==e?null:{components:l,alphaToken:a}}function C(r,e){if(r.length!==e.length)return null;let n=[];for(let o=0;o<e.length;o+=1){let t=r[o],a=e[o];if(t===void 0||a===void 0)return null;let l=a==="hue"?W(t):G(t,a);if(l===null)return null;n.push(l)}return n}function s(r,e,n){let o=y(r,e.length,!0);if(!o)return null;let t=C(o.components,e);if(!t)return null;let a=h(o.alphaToken);return a===null?null:{rgb:n(d(t)),alpha:a}}function F(r){let e=y(r,4,!1);if(!e)return null;let n=C(e.components,[i,i,i,i]);if(!n)return null;let o=h(e.alphaToken);return o===null?null:{rgb:(0,R.cmykToRgb)(n),alpha:o}}function U(r){let e=y(r,4,!1);if(!e)return null;let[n,...o]=e.components,t=n===void 0?void 0:H[n];if(t===void 0)return null;let a=C(o,[i,i,i]);if(!a)return null;let l=h(e.alphaToken);if(l===null)return null;let c=d(a);return{rgb:t==="sRGB"?c:(0,R.convertRGBColorspace)((0,I.unsafeAsEncodedRGB)(c),t,"sRGB"),alpha:l}}function J(r){let{value:e}=(0,p.convertByPipeline)(r,"Lab D50","sRGB encoded",_);return d(e)}function Q(r){let{value:e}=(0,p.convertByPipeline)(r,"LCh","sRGB encoded",_);return d(e)}function V(r,e){switch(r){case"lab":{let n=s(e,[T,S,S],J);return n?{...n,source:"lab"}:null}case"lch":{let n=s(e,[T,B,"hue"],Q);return n?{...n,source:"lch"}:null}case"oklab":{let n=s(e,[P,b,b],o=>(0,p.oklabToRgb)((0,k.unsafeAsOklab)(o)));return n?{...n,source:"oklab"}:null}case"oklch":{let n=s(e,[P,b,"hue"],o=>(0,p.oklchToRgb)((0,k.unsafeAsOklch)(o)));return n?{...n,source:"oklch"}:null}default:return null}}var A=require("@omi-io/color-convert");function M(r,e){switch(r){case"rgb":case"rgba":{let n=s(e,[g,g,g],o=>o);return n?{...n,source:"rgb"}:null}case"hsl":case"hsla":{let n=s(e,["hue",m,m],o=>(0,A.hslToRgb)(o));return n?{...n,source:"hsl"}:null}case"hsv":case"hsva":{let n=s(e,["hue",m,m],o=>(0,A.hsvToRgb)(o));return n?{...n,source:"hsv"}:null}case"cmyk":case"device-cmyk":{let n=F(e);return n?{...n,source:"cmyk"}:null}case"color":{let n=U(e);return n?{...n,source:"color"}:null}default:return null}}var u=require("@omi-io/color-core"),Z=/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/,ee=/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/,ne=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/,re=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/;function f(r){return parseInt(r,16)}function E(r){let e=re.exec(r);if(e)return{rgb:(0,u.rgb8ToUnit)([f(e[1]??"0"),f(e[2]??"0"),f(e[3]??"0")]),alpha:(0,u.clampUnit)(f(e[4]??"ff")/255)};let n=ne.exec(r);if(n)return{rgb:(0,u.rgb8ToUnit)([f(n[1]??"0"),f(n[2]??"0"),f(n[3]??"0")]),alpha:1};let o=ee.exec(r);if(o){let[a,l,c,L]=[o[1]??"0",o[2]??"0",o[3]??"0",o[4]??"f"];return{rgb:(0,u.rgb8ToUnit)([f(a+a),f(l+l),f(c+c)]),alpha:(0,u.clampUnit)(f(L+L)/255)}}let t=Z.exec(r);if(t){let[a,l,c]=[t[1]??"0",t[2]??"0",t[3]??"0"];return{rgb:(0,u.rgb8ToUnit)([f(a+a),f(l+l),f(c+c)]),alpha:1}}return null}var oe=/^([a-z-]+)\(\s*(.*?)\s*\)$/;function K(r){if(typeof r!="string")return null;let e=r.trim().toLowerCase();if(e.length===0)return null;if(e==="transparent")return{rgb:[0,0,0],alpha:0,source:"named"};let n=N[e];if(n!==void 0){let a=E(n);return a?{...a,source:"named"}:null}let o=oe.exec(e);if(o){let a=o[1]??"",l=o[2]??"";return M(a,l)??V(a,l)}let t=E(e);return t?{...t,source:"hex"}:null}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var d=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var M=(t,r)=>{for(var o in r)d(t,o,{get:r[o],enumerable:!0})},_=(t,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of S(r))!G.call(t,s)&&s!==o&&d(t,s,{get:()=>r[s],enumerable:!(n=H(r,s))||n.enumerable});return t};var U=t=>_(d({},"__esModule",{value:!0}),t);var I={};M(I,{formatCmyk:()=>k,formatHex:()=>x,formatHsl:()=>y,formatHsv:()=>R,formatLab:()=>D,formatLch:()=>T,formatOklab:()=>B,formatOklch:()=>C,formatRgb:()=>F});module.exports=U(I);var l=require("@omi-io/color-convert"),m=require("@omi-io/color-core");var f=require("@omi-io/color-core"),p=3,L=4;function e(t,r){if(!Number.isFinite(t))return 0;let o=10**r;return Math.round(t*o)/o}function b(t){return Math.round((0,f.clampByteChannel)(t)).toString(16).padStart(2,"0")}function O(t){return(0,f.unitToRgb8)([(0,f.clampUnit)(t[0]),(0,f.clampUnit)(t[1]),(0,f.clampUnit)(t[2])])}function u(t){if(t===void 0)return"";let r=(0,f.clampUnit)(t);return r>=1?"":` / ${e(r,3)}`}function h(t,r,o,n){return n?`${e(t*r,o)}%`:`${e(t,o)}`}function x(t,r){let[o,n,s]=O(t),i=`#${b(o)}${b(n)}${b(s)}`;return r===void 0||(0,m.clampUnit)(r)>=1?i:`${i}${b((0,m.clampUnit)(r)*255)}`}function F(t,r,o){if(o?.percent){let a=o.decimals??1,g=e((0,m.clampUnit)(t[0])*100,a),A=e((0,m.clampUnit)(t[1])*100,a),E=e((0,m.clampUnit)(t[2])*100,a);return`rgb(${g}% ${A}% ${E}%${u(r)})`}let n=o?.decimals??0,[s,i,c]=(0,m.unitToRgb8)([(0,m.clampUnit)(t[0]),(0,m.clampUnit)(t[1]),(0,m.clampUnit)(t[2])],{decimals:n});return`rgb(${e(s,n)} ${e(i,n)} ${e(c,n)}${u(r)})`}function y(t,r,o){let n=o?.decimals??p,[s,i,c]=(0,l.rgbToHsl)(t);return`hsl(${e((0,m.wrapHueDegrees)(s),n)} ${e((0,m.clampUnit)(i)*100,n)}% ${e((0,m.clampUnit)(c)*100,n)}%${u(r)})`}function R(t,r,o){let n=o?.decimals??p,[s,i,c]=(0,l.rgbToHsv)(t);return`hsv(${e((0,m.wrapHueDegrees)(s),n)} ${e((0,m.clampUnit)(i)*100,n)}% ${e((0,m.clampUnit)(c)*100,n)}%${u(r)})`}function k(t,r){let o=r?.decimals??p,[n,s,i,c]=(0,l.rgbToCmyk)(t).map(a=>e((0,m.clampUnit)(a)*100,o));return`cmyk(${n}% ${s}% ${i}% ${c}%)`}var $=require("@omi-io/color-core");function C(t,r,o){let n=o?.decimals??L,[s,i,c]=t,a=h(s,100,n,o?.percentLightness),g=i<=$.EPSILON_CHROMA?"none":`${e((0,$.wrapHueDegrees)(c),n)}`;return`oklch(${a} ${e(i,n)} ${g}${u(r)})`}function B(t,r,o){let n=o?.decimals??L,[s,i,c]=t;return`oklab(${h(s,100,n,o?.percentLightness)} ${e(i,n)} ${e(c,n)}${u(r)})`}function D(t,r,o){let n=o?.decimals??p,[s,i,c]=t;return`lab(${h(s,1,n,o?.percentLightness)} ${e(i,n)} ${e(c,n)}${u(r)})`}function T(t,r,o){let n=o?.decimals??p,[s,i,c]=t,a=h(s,1,n,o?.percentLightness),g=i<=$.EPSILON_CHROMA?"none":`${e((0,$.wrapHueDegrees)(c),n)}`;return`lch(${a} ${e(i,n)} ${g}${u(r)})`}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var S={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",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};import{convertByPipeline as H,oklabToRgb as q,oklchToRgb as $}from"@omi-io/color-convert";import{unsafeAsOklab as D,unsafeAsOklch as X}from"@omi-io/color-models";import{cmykToRgb as V,convertRGBColorspace as M}from"@omi-io/color-convert";import{unsafeAsEncodedRGB as K}from"@omi-io/color-models";var d={number:.00392156862745098,percent:.01},p={number:.01,percent:.01},i={number:1,percent:.01},C={number:1,percent:1},R={number:1,percent:1.25},P={number:1,percent:1.5},k={number:1,percent:.01},m={number:1,percent:.004},_={number:1,percent:.01},E={srgb:"sRGB","display-p3":"Display P3"},A={adaptation:{transform:"Bradford"}};import{clampUnit as I}from"@omi-io/color-core";var L=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$/i,F=/^(deg|grad|rad|turn)$/;function N(r,n){if(r==="none")return 0;let e=r.endsWith("%"),o=e?r.slice(0,-1):r;return L.test(o)?parseFloat(o)*(e?n.percent:n.number):null}function U(r){if(r==="none")return 0;let n=/(deg|grad|rad|turn)$/.exec(r),e=n?.[1]??"deg",o=n?r.slice(0,-e.length):r;if(!L.test(o)||!F.test(e))return null;let a=parseFloat(o);return e==="grad"?a*.9:e==="rad"?a*(180/Math.PI):e==="turn"?a*360:a}function g(r){if(r===void 0)return 1;let n=N(r,_);return n===null?null:I(n)}function u(r){return[r[0]??0,r[1]??0,r[2]??0]}function b(r,n,e){let o=r.split("/");if(o.length>2)return null;let a=(o[0]??"").trim(),t=o.length===2?(o[1]??"").trim():void 0;if(t!==void 0&&t.length===0||a.length===0)return null;let l=a.split(/[,\s]+/);return e&&t===void 0&&l.length===n+1&&(t=l.pop()),l.length!==n?null:{components:l,alphaToken:t}}function h(r,n){if(r.length!==n.length)return null;let e=[];for(let o=0;o<n.length;o+=1){let a=r[o],t=n[o];if(a===void 0||t===void 0)return null;let l=t==="hue"?U(a):N(a,t);if(l===null)return null;e.push(l)}return e}function s(r,n,e){let o=b(r,n.length,!0);if(!o)return null;let a=h(o.components,n);if(!a)return null;let t=g(o.alphaToken);return t===null?null:{rgb:e(u(a)),alpha:t}}function B(r){let n=b(r,4,!1);if(!n)return null;let e=h(n.components,[i,i,i,i]);if(!e)return null;let o=g(n.alphaToken);return o===null?null:{rgb:V(e),alpha:o}}function O(r){let n=b(r,4,!1);if(!n)return null;let[e,...o]=n.components,a=e===void 0?void 0:E[e];if(a===void 0)return null;let t=h(o,[i,i,i]);if(!t)return null;let l=g(n.alphaToken);if(l===null)return null;let c=u(t);return{rgb:a==="sRGB"?c:M(K(c),a,"sRGB"),alpha:l}}function z(r){let{value:n}=H(r,"Lab D50","sRGB encoded",A);return u(n)}function Y(r){let{value:n}=H(r,"LCh","sRGB encoded",A);return u(n)}function w(r,n){switch(r){case"lab":{let e=s(n,[C,R,R],z);return e?{...e,source:"lab"}:null}case"lch":{let e=s(n,[C,P,"hue"],Y);return e?{...e,source:"lch"}:null}case"oklab":{let e=s(n,[k,m,m],o=>q(D(o)));return e?{...e,source:"oklab"}:null}case"oklch":{let e=s(n,[k,m,"hue"],o=>$(X(o)));return e?{...e,source:"oklch"}:null}default:return null}}import{hslToRgb as j,hsvToRgb as W}from"@omi-io/color-convert";function v(r,n){switch(r){case"rgb":case"rgba":{let e=s(n,[d,d,d],o=>o);return e?{...e,source:"rgb"}:null}case"hsl":case"hsla":{let e=s(n,["hue",p,p],o=>j(o));return e?{...e,source:"hsl"}:null}case"hsv":case"hsva":{let e=s(n,["hue",p,p],o=>W(o));return e?{...e,source:"hsv"}:null}case"cmyk":case"device-cmyk":{let e=B(n);return e?{...e,source:"cmyk"}:null}case"color":{let e=O(n);return e?{...e,source:"color"}:null}default:return null}}import{clampUnit as G,rgb8ToUnit as y}from"@omi-io/color-core";var J=/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/,Q=/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/,Z=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/,ee=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/;function f(r){return parseInt(r,16)}function x(r){let n=ee.exec(r);if(n)return{rgb:y([f(n[1]??"0"),f(n[2]??"0"),f(n[3]??"0")]),alpha:G(f(n[4]??"ff")/255)};let e=Z.exec(r);if(e)return{rgb:y([f(e[1]??"0"),f(e[2]??"0"),f(e[3]??"0")]),alpha:1};let o=Q.exec(r);if(o){let[t,l,c,T]=[o[1]??"0",o[2]??"0",o[3]??"0",o[4]??"f"];return{rgb:y([f(t+t),f(l+l),f(c+c)]),alpha:G(f(T+T)/255)}}let a=J.exec(r);if(a){let[t,l,c]=[a[1]??"0",a[2]??"0",a[3]??"0"];return{rgb:y([f(t+t),f(l+l),f(c+c)]),alpha:1}}return null}var ne=/^([a-z-]+)\(\s*(.*?)\s*\)$/;function re(r){if(typeof r!="string")return null;let n=r.trim().toLowerCase();if(n.length===0)return null;if(n==="transparent")return{rgb:[0,0,0],alpha:0,source:"named"};let e=S[n];if(e!==void 0){let t=x(e);return t?{...t,source:"named"}:null}let o=ne.exec(n);if(o){let t=o[1]??"",l=o[2]??"";return v(t,l)??w(t,l)}let a=x(n);return a?{...a,source:"hex"}:null}export{S as a,re as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{rgbToCmyk as k,rgbToHsl as C,rgbToHsv as B}from"@omi-io/color-convert";import{clampUnit as c,unitToRgb8 as D,wrapHueDegrees as d}from"@omi-io/color-core";import{clampByteChannel as y,clampUnit as g,unitToRgb8 as R}from"@omi-io/color-core";var f=3,b=4;function e(t,o){if(!Number.isFinite(t))return 0;let n=10**o;return Math.round(t*n)/n}function l(t){return Math.round(y(t)).toString(16).padStart(2,"0")}function h(t){return R([g(t[0]),g(t[1]),g(t[2])])}function u(t){if(t===void 0)return"";let o=g(t);return o>=1?"":` / ${e(o,3)}`}function $(t,o,n,r){return r?`${e(t*o,n)}%`:`${e(t,n)}`}function T(t,o){let[n,r,i]=h(t),s=`#${l(n)}${l(r)}${l(i)}`;return o===void 0||c(o)>=1?s:`${s}${l(c(o)*255)}`}function A(t,o,n){if(n?.percent){let a=n.decimals??1,p=e(c(t[0])*100,a),x=e(c(t[1])*100,a),F=e(c(t[2])*100,a);return`rgb(${p}% ${x}% ${F}%${u(o)})`}let r=n?.decimals??0,[i,s,m]=D([c(t[0]),c(t[1]),c(t[2])],{decimals:r});return`rgb(${e(i,r)} ${e(s,r)} ${e(m,r)}${u(o)})`}function E(t,o,n){let r=n?.decimals??f,[i,s,m]=C(t);return`hsl(${e(d(i),r)} ${e(c(s)*100,r)}% ${e(c(m)*100,r)}%${u(o)})`}function H(t,o,n){let r=n?.decimals??f,[i,s,m]=B(t);return`hsv(${e(d(i),r)} ${e(c(s)*100,r)}% ${e(c(m)*100,r)}%${u(o)})`}function S(t,o){let n=o?.decimals??f,[r,i,s,m]=k(t).map(a=>e(c(a)*100,n));return`cmyk(${r}% ${i}% ${s}% ${m}%)`}import{EPSILON_CHROMA as L,wrapHueDegrees as O}from"@omi-io/color-core";function G(t,o,n){let r=n?.decimals??b,[i,s,m]=t,a=$(i,100,r,n?.percentLightness),p=s<=L?"none":`${e(O(m),r)}`;return`oklch(${a} ${e(s,r)} ${p}${u(o)})`}function M(t,o,n){let r=n?.decimals??b,[i,s,m]=t;return`oklab(${$(i,100,r,n?.percentLightness)} ${e(s,r)} ${e(m,r)}${u(o)})`}function _(t,o,n){let r=n?.decimals??f,[i,s,m]=t;return`lab(${$(i,1,r,n?.percentLightness)} ${e(s,r)} ${e(m,r)}${u(o)})`}function U(t,o,n){let r=n?.decimals??f,[i,s,m]=t,a=$(i,1,r,n?.percentLightness),p=s<=L?"none":`${e(O(m),r)}`;return`lch(${a} ${e(s,r)} ${p}${u(o)})`}export{T as a,A as b,E as c,H as d,S as e,G as f,M as g,_ as h,U as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o,b as t}from"./chunk-7G5PE7V2.js";import{a as r,b as a,c as m,d as e,e as f,f as p,g as s,h as y,i as C}from"./chunk-FGDLWKLI.js";export{o as CSS_NAMED_COLORS,f as formatCmyk,r as formatHex,m as formatHsl,e as formatHsv,y as formatLab,C as formatLch,s as formatOklab,p as formatOklch,a as formatRgb,t as parseColor};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as a}from"../chunk-7G5PE7V2.js";export{a as parseColor};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i}from"../chunk-FGDLWKLI.js";export{e as formatCmyk,a as formatHex,c as formatHsl,d as formatHsv,h as formatLab,i as formatLch,g as formatOklab,f as formatOklch,b as formatRgb};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { CSS_NAMED_COLORS } from "./named-colors";
|
|
2
|
+
export { parseColor, type CssColorSyntax, type ParsedColor } from "./parse";
|
|
3
|
+
export { formatCmyk, formatHex, formatHsl, formatHsv, formatLab, formatLch, formatOklab, formatOklch, formatRgb, type FormatLightnessOptions, type FormatOptions, type FormatRgbOptions, } from "./serialize";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CSS_NAMED_COLORS: Readonly<Record<string, string>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RGB, Vec3 } from "@omi-io/color-core/types";
|
|
2
|
+
import type { ComponentKind, ParsedChannels } from "./types";
|
|
3
|
+
export declare function parseTripletFunction(body: string, kinds: ReadonlyArray<ComponentKind>, toRgb: (components: Vec3) => RGB): ParsedChannels | null;
|
|
4
|
+
export declare function parseCmykFunction(body: string): ParsedChannels | null;
|
|
5
|
+
export declare function parseColorFunction(body: string): ParsedChannels | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RGBColorspaceConversionOptions, RGBColorspaceId } from "@omi-io/color-core/types";
|
|
2
|
+
import type { ComponentScale } from "./types";
|
|
3
|
+
export declare const RGB_CHANNEL: ComponentScale;
|
|
4
|
+
export declare const PERCENTAGE_UNIT: ComponentScale;
|
|
5
|
+
export declare const UNIT_OR_PERCENT: ComponentScale;
|
|
6
|
+
export declare const LAB_LIGHTNESS: ComponentScale;
|
|
7
|
+
export declare const LAB_AB: ComponentScale;
|
|
8
|
+
export declare const LCH_CHROMA: ComponentScale;
|
|
9
|
+
export declare const OK_LIGHTNESS: ComponentScale;
|
|
10
|
+
export declare const OK_AB_CHROMA: ComponentScale;
|
|
11
|
+
export declare const ALPHA: ComponentScale;
|
|
12
|
+
export declare const COLOR_FUNCTION_SPACES: Readonly<Record<string, RGBColorspaceId>>;
|
|
13
|
+
export declare const LAB_PIPELINE_OPTIONS: RGBColorspaceConversionOptions;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Vec3 } from "@omi-io/color-core/types";
|
|
2
|
+
import type { ComponentKind, ComponentScale, FunctionArgs } from "./types";
|
|
3
|
+
export declare function parseScaledComponent(token: string, scale: ComponentScale): number | null;
|
|
4
|
+
export declare function parseHueComponent(token: string): number | null;
|
|
5
|
+
export declare function parseAlphaComponent(token: string | undefined): number | null;
|
|
6
|
+
export declare function asVec3(values: ReadonlyArray<number>): Vec3;
|
|
7
|
+
export declare function splitFunctionArgs(body: string, componentCount: number, allowLegacyAlpha: boolean): FunctionArgs | null;
|
|
8
|
+
export declare function parseComponents(tokens: ReadonlyArray<string>, kinds: ReadonlyArray<ComponentKind>): Array<number> | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RGB } from "@omi-io/color-core/types";
|
|
2
|
+
export type CssColorSyntax = "hex" | "named" | "rgb" | "hsl" | "hsv" | "cmyk" | "lab" | "lch" | "oklab" | "oklch" | "color";
|
|
3
|
+
export interface ParsedColor {
|
|
4
|
+
rgb: RGB;
|
|
5
|
+
alpha: number;
|
|
6
|
+
source: CssColorSyntax;
|
|
7
|
+
}
|
|
8
|
+
export interface ParsedChannels {
|
|
9
|
+
rgb: RGB;
|
|
10
|
+
alpha: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ComponentScale {
|
|
13
|
+
number: number;
|
|
14
|
+
percent: number;
|
|
15
|
+
}
|
|
16
|
+
export type ComponentKind = ComponentScale | "hue";
|
|
17
|
+
export interface FunctionArgs {
|
|
18
|
+
components: ReadonlyArray<string>;
|
|
19
|
+
alphaToken?: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RGB } from "@omi-io/color-core/types";
|
|
2
|
+
import type { FormatOptions, FormatRgbOptions } from "./types";
|
|
3
|
+
export declare function formatHex(rgb: RGB, alpha?: number): string;
|
|
4
|
+
export declare function formatRgb(rgb: RGB, alpha?: number, options?: FormatRgbOptions): string;
|
|
5
|
+
export declare function formatHsl(rgb: RGB, alpha?: number, options?: FormatOptions): string;
|
|
6
|
+
export declare function formatHsv(rgb: RGB, alpha?: number, options?: FormatOptions): string;
|
|
7
|
+
export declare function formatCmyk(rgb: RGB, options?: FormatOptions): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Lab, LCh, Oklab, Oklch } from "@omi-io/color-models";
|
|
2
|
+
import type { FormatLightnessOptions } from "./types";
|
|
3
|
+
export declare function formatOklch(oklch: Oklch, alpha?: number, options?: FormatLightnessOptions): string;
|
|
4
|
+
export declare function formatOklab(oklab: Oklab, alpha?: number, options?: FormatLightnessOptions): string;
|
|
5
|
+
export declare function formatLab(lab: Lab, alpha?: number, options?: FormatLightnessOptions): string;
|
|
6
|
+
export declare function formatLch(lch: LCh, alpha?: number, options?: FormatLightnessOptions): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RGB, RGB8 } from "@omi-io/color-core/types";
|
|
2
|
+
export declare const DEFAULT_DECIMALS = 3;
|
|
3
|
+
export declare const DEFAULT_OK_DECIMALS = 4;
|
|
4
|
+
export declare function round(value: number, decimals: number): number;
|
|
5
|
+
export declare function pad2(byte: number): string;
|
|
6
|
+
export declare function toBytes(rgb: RGB): RGB8;
|
|
7
|
+
export declare function alphaSuffix(alpha: number | undefined): string;
|
|
8
|
+
export declare function lightnessToken(lightness: number, percentFactor: number, decimals: number, percent: boolean | undefined): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omi-io/color-css",
|
|
3
|
+
"scopeCommitName": "@:css",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "CSS color string parsing and serialization: hex, rgb(), hsl(), hsv(), cmyk(), lab(), lch(), oklab(), oklch(), color(), named colors — normalized to canonical [0,1] sRGB plus alpha.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"color",
|
|
8
|
+
"css",
|
|
9
|
+
"css-color-4",
|
|
10
|
+
"parse",
|
|
11
|
+
"serialize",
|
|
12
|
+
"hex",
|
|
13
|
+
"rgb",
|
|
14
|
+
"hsl",
|
|
15
|
+
"oklch",
|
|
16
|
+
"oklab",
|
|
17
|
+
"lab",
|
|
18
|
+
"lch",
|
|
19
|
+
"named-colors",
|
|
20
|
+
"alpha",
|
|
21
|
+
"display-p3"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/a-omi-io/color.git",
|
|
27
|
+
"directory": "packages/color-css"
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"type": "module",
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"main": "./dist/cjs/index.cjs",
|
|
36
|
+
"module": "./dist/esm/index.js",
|
|
37
|
+
"scripts": {
|
|
38
|
+
"clean": "omi-io-pkg clean",
|
|
39
|
+
"build": "yarn clean && omi-io-pkg build && tsc && omi-io-pkg alias",
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"lint": "eslint ./src",
|
|
42
|
+
"tsc-check": "tsc --noEmit --emitDeclarationOnly false"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@omi-io/color-convert": "^0.2.0",
|
|
46
|
+
"@omi-io/color-core": "^0.1.0",
|
|
47
|
+
"@omi-io/color-models": "^0.2.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@omi-io/pkg-scripts": "v2.5.0",
|
|
51
|
+
"@types/jest": "^29.5.0",
|
|
52
|
+
"@types/node": "^20.11.30",
|
|
53
|
+
"eslint": "^8.57.0",
|
|
54
|
+
"jest": "^29.5.0",
|
|
55
|
+
"ts-jest": "^29.0.5",
|
|
56
|
+
"typescript": "~5.4.3"
|
|
57
|
+
},
|
|
58
|
+
"exports": {
|
|
59
|
+
".": {
|
|
60
|
+
"types": "./dist/types/index.d.ts",
|
|
61
|
+
"require": "./dist/cjs/index.cjs",
|
|
62
|
+
"default": "./dist/esm/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./package.json": "./package.json",
|
|
65
|
+
"./parse": {
|
|
66
|
+
"types": "./dist/types/parse/index.d.ts",
|
|
67
|
+
"require": "./dist/cjs/parse/index.cjs",
|
|
68
|
+
"default": "./dist/esm/parse/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./serialize": {
|
|
71
|
+
"types": "./dist/types/serialize/index.d.ts",
|
|
72
|
+
"require": "./dist/cjs/serialize/index.cjs",
|
|
73
|
+
"default": "./dist/esm/serialize/index.js"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"files": [
|
|
77
|
+
"dist",
|
|
78
|
+
"parse/package.json",
|
|
79
|
+
"serialize/package.json"
|
|
80
|
+
]
|
|
81
|
+
}
|