@ai-matrx/kit 0.5.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/LICENSE +21 -0
  3. package/README.md +72 -0
  4. package/dist/autosave.cjs +92 -0
  5. package/dist/autosave.cjs.map +1 -0
  6. package/dist/autosave.d.cts +17 -0
  7. package/dist/autosave.d.ts +17 -0
  8. package/dist/autosave.js +72 -0
  9. package/dist/autosave.js.map +1 -0
  10. package/dist/clipboard.cjs +152 -0
  11. package/dist/clipboard.cjs.map +1 -0
  12. package/dist/clipboard.d.cts +17 -0
  13. package/dist/clipboard.d.ts +17 -0
  14. package/dist/clipboard.js +132 -0
  15. package/dist/clipboard.js.map +1 -0
  16. package/dist/color-util.cjs +790 -0
  17. package/dist/color-util.cjs.map +1 -0
  18. package/dist/color-util.d.cts +235 -0
  19. package/dist/color-util.d.ts +235 -0
  20. package/dist/color-util.js +767 -0
  21. package/dist/color-util.js.map +1 -0
  22. package/dist/concurrency.cjs +59 -0
  23. package/dist/concurrency.cjs.map +1 -0
  24. package/dist/concurrency.d.cts +19 -0
  25. package/dist/concurrency.d.ts +19 -0
  26. package/dist/concurrency.js +38 -0
  27. package/dist/concurrency.js.map +1 -0
  28. package/dist/confirm.cjs +344 -0
  29. package/dist/confirm.cjs.map +1 -0
  30. package/dist/confirm.d.cts +132 -0
  31. package/dist/confirm.d.ts +132 -0
  32. package/dist/confirm.js +312 -0
  33. package/dist/confirm.js.map +1 -0
  34. package/dist/delimiter-guard.cjs +172 -0
  35. package/dist/delimiter-guard.cjs.map +1 -0
  36. package/dist/delimiter-guard.d.cts +119 -0
  37. package/dist/delimiter-guard.d.ts +119 -0
  38. package/dist/delimiter-guard.js +151 -0
  39. package/dist/delimiter-guard.js.map +1 -0
  40. package/dist/drafts.cjs +223 -0
  41. package/dist/drafts.cjs.map +1 -0
  42. package/dist/drafts.d.cts +62 -0
  43. package/dist/drafts.d.ts +62 -0
  44. package/dist/drafts.js +201 -0
  45. package/dist/drafts.js.map +1 -0
  46. package/dist/idb-store.cjs +178 -0
  47. package/dist/idb-store.cjs.map +1 -0
  48. package/dist/idb-store.d.cts +111 -0
  49. package/dist/idb-store.d.ts +111 -0
  50. package/dist/idb-store.js +155 -0
  51. package/dist/idb-store.js.map +1 -0
  52. package/dist/idle-scheduler.cjs +268 -0
  53. package/dist/idle-scheduler.cjs.map +1 -0
  54. package/dist/idle-scheduler.d.cts +185 -0
  55. package/dist/idle-scheduler.d.ts +185 -0
  56. package/dist/idle-scheduler.js +246 -0
  57. package/dist/idle-scheduler.js.map +1 -0
  58. package/dist/index.cjs +3113 -0
  59. package/dist/index.cjs.map +1 -0
  60. package/dist/index.d.cts +897 -0
  61. package/dist/index.d.ts +897 -0
  62. package/dist/index.js +3088 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/invalidation.cjs +64 -0
  65. package/dist/invalidation.cjs.map +1 -0
  66. package/dist/invalidation.d.cts +52 -0
  67. package/dist/invalidation.d.ts +52 -0
  68. package/dist/invalidation.js +43 -0
  69. package/dist/invalidation.js.map +1 -0
  70. package/dist/json-format.cjs +319 -0
  71. package/dist/json-format.cjs.map +1 -0
  72. package/dist/json-format.d.cts +148 -0
  73. package/dist/json-format.d.ts +148 -0
  74. package/dist/json-format.js +286 -0
  75. package/dist/json-format.js.map +1 -0
  76. package/dist/latest-request.cjs +36 -0
  77. package/dist/latest-request.cjs.map +1 -0
  78. package/dist/latest-request.d.cts +29 -0
  79. package/dist/latest-request.d.ts +29 -0
  80. package/dist/latest-request.js +16 -0
  81. package/dist/latest-request.js.map +1 -0
  82. package/dist/qr.cjs +109 -0
  83. package/dist/qr.cjs.map +1 -0
  84. package/dist/qr.d.cts +47 -0
  85. package/dist/qr.d.ts +47 -0
  86. package/dist/qr.js +78 -0
  87. package/dist/qr.js.map +1 -0
  88. package/dist/react-tree.cjs +69 -0
  89. package/dist/react-tree.cjs.map +1 -0
  90. package/dist/react-tree.d.cts +38 -0
  91. package/dist/react-tree.d.ts +38 -0
  92. package/dist/react-tree.js +38 -0
  93. package/dist/react-tree.js.map +1 -0
  94. package/dist/search-scoring.cjs +116 -0
  95. package/dist/search-scoring.cjs.map +1 -0
  96. package/dist/search-scoring.d.cts +77 -0
  97. package/dist/search-scoring.d.ts +77 -0
  98. package/dist/search-scoring.js +95 -0
  99. package/dist/search-scoring.js.map +1 -0
  100. package/dist/text-case.cjs +313 -0
  101. package/dist/text-case.cjs.map +1 -0
  102. package/dist/text-case.d.cts +53 -0
  103. package/dist/text-case.d.ts +53 -0
  104. package/dist/text-case.js +292 -0
  105. package/dist/text-case.js.map +1 -0
  106. package/dist/toast.cjs +74 -0
  107. package/dist/toast.cjs.map +1 -0
  108. package/dist/toast.d.cts +92 -0
  109. package/dist/toast.d.ts +92 -0
  110. package/dist/toast.js +54 -0
  111. package/dist/toast.js.map +1 -0
  112. package/dist/url-state.cjs +212 -0
  113. package/dist/url-state.cjs.map +1 -0
  114. package/dist/url-state.d.cts +90 -0
  115. package/dist/url-state.d.ts +90 -0
  116. package/dist/url-state.js +199 -0
  117. package/dist/url-state.js.map +1 -0
  118. package/package.json +286 -0
@@ -0,0 +1,767 @@
1
+ // src/color-util/lab-delta.ts
2
+ function round(value, digits = 0) {
3
+ const factor = Math.pow(10, digits);
4
+ return Math.round(factor * value) / factor + 0;
5
+ }
6
+ function clamp(value, min = 0, max = 1) {
7
+ return value > max ? max : value > min ? value : min;
8
+ }
9
+ function linearize(channel) {
10
+ const c = channel / 255;
11
+ return c < 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
12
+ }
13
+ var WHITE_X = 96.422;
14
+ var WHITE_Y = 100;
15
+ var WHITE_Z = 82.521;
16
+ var EPSILON = 216 / 24389;
17
+ var KAPPA = 24389 / 27;
18
+ function rgbToXyz(rgb) {
19
+ const r = linearize(rgb.r);
20
+ const g = linearize(rgb.g);
21
+ const b = linearize(rgb.b);
22
+ const d65 = {
23
+ x: 100 * (0.4124564 * r + 0.3575761 * g + 0.1804375 * b),
24
+ y: 100 * (0.2126729 * r + 0.7151522 * g + 0.072175 * b),
25
+ z: 100 * (0.0193339 * r + 0.119192 * g + 0.9503041 * b)
26
+ };
27
+ const d50 = {
28
+ x: 1.0478112 * d65.x + 0.0228866 * d65.y + -0.050127 * d65.z,
29
+ y: 0.0295424 * d65.x + 0.9904844 * d65.y + -0.0170491 * d65.z,
30
+ z: -92345e-7 * d65.x + 0.0150436 * d65.y + 0.7521316 * d65.z
31
+ };
32
+ return {
33
+ x: clamp(d50.x, 0, WHITE_X),
34
+ y: clamp(d50.y, 0, WHITE_Y),
35
+ z: clamp(d50.z, 0, WHITE_Z)
36
+ };
37
+ }
38
+ function rgbToLab(rgb) {
39
+ const xyz = rgbToXyz(rgb);
40
+ let x = xyz.x / WHITE_X;
41
+ let y = xyz.y / WHITE_Y;
42
+ let z = xyz.z / WHITE_Z;
43
+ x = x > EPSILON ? Math.cbrt(x) : (KAPPA * x + 16) / 116;
44
+ y = y > EPSILON ? Math.cbrt(y) : (KAPPA * y + 16) / 116;
45
+ z = z > EPSILON ? Math.cbrt(z) : (KAPPA * z + 16) / 116;
46
+ return {
47
+ l: round(116 * y - 16, 2),
48
+ a: round(500 * (x - y), 2),
49
+ b: round(200 * (y - z), 2)
50
+ };
51
+ }
52
+ function ciede2000(lab1, lab2) {
53
+ const { l: l1, a: a1, b: b1 } = lab1;
54
+ const { l: l2, a: a2, b: b2 } = lab2;
55
+ const toDeg = 180 / Math.PI;
56
+ const toRad = Math.PI / 180;
57
+ const c1 = Math.pow(Math.pow(a1, 2) + Math.pow(b1, 2), 0.5);
58
+ const c2 = Math.pow(Math.pow(a2, 2) + Math.pow(b2, 2), 0.5);
59
+ const lBar = (l1 + l2) / 2;
60
+ const cBar7 = Math.pow((c1 + c2) / 2, 7);
61
+ const g = 0.5 * (1 - Math.pow(cBar7 / (cBar7 + Math.pow(25, 7)), 0.5));
62
+ const a1p = a1 * (1 + g);
63
+ const a2p = a2 * (1 + g);
64
+ const c1p = Math.pow(Math.pow(a1p, 2) + Math.pow(b1, 2), 0.5);
65
+ const c2p = Math.pow(Math.pow(a2p, 2) + Math.pow(b2, 2), 0.5);
66
+ const cBarP = (c1p + c2p) / 2;
67
+ let h1p = a1p === 0 && b1 === 0 ? 0 : Math.atan2(b1, a1p) * toDeg;
68
+ let h2p = a2p === 0 && b2 === 0 ? 0 : Math.atan2(b2, a2p) * toDeg;
69
+ if (h1p < 0) h1p += 360;
70
+ if (h2p < 0) h2p += 360;
71
+ let dhp = h2p - h1p;
72
+ const hAbs = Math.abs(h2p - h1p);
73
+ if (hAbs > 180 && h2p <= h1p) {
74
+ dhp += 360;
75
+ } else if (hAbs > 180 && h2p > h1p) {
76
+ dhp -= 360;
77
+ }
78
+ let hBarP = h1p + h2p;
79
+ if (hAbs <= 180) {
80
+ hBarP /= 2;
81
+ } else {
82
+ hBarP = (h1p + h2p < 360 ? hBarP + 360 : hBarP - 360) / 2;
83
+ }
84
+ const t = 1 - 0.17 * Math.cos(toRad * (hBarP - 30)) + 0.24 * Math.cos(2 * toRad * hBarP) + 0.32 * Math.cos(toRad * (3 * hBarP + 6)) - 0.2 * Math.cos(toRad * (4 * hBarP - 63));
85
+ const dL = l2 - l1;
86
+ const dCp = c2p - c1p;
87
+ const dHp = 2 * Math.sin(toRad * dhp / 2) * Math.pow(c1p * c2p, 0.5);
88
+ const sl = 1 + 0.015 * Math.pow(lBar - 50, 2) / Math.pow(20 + Math.pow(lBar - 50, 2), 0.5);
89
+ const sc = 1 + 0.045 * cBarP;
90
+ const sh = 1 + 0.015 * cBarP * t;
91
+ const dTheta = 30 * Math.exp(-1 * Math.pow((hBarP - 275) / 25, 2));
92
+ const cBarP7 = Math.pow(cBarP, 7);
93
+ const rt = -2 * Math.pow(cBarP7 / (cBarP7 + Math.pow(25, 7)), 0.5) * Math.sin(2 * toRad * dTheta);
94
+ return Math.pow(
95
+ Math.pow(dL / 1 / sl, 2) + Math.pow(dCp / 1 / sc, 2) + Math.pow(dHp / 1 / sh, 2) + rt * dCp * dHp / (1 * sc * 1 * sh),
96
+ 0.5
97
+ );
98
+ }
99
+ function rgbDelta(rgb1, rgb2) {
100
+ return clamp(round(ciede2000(rgbToLab(rgb1), rgbToLab(rgb2)) / 100, 3));
101
+ }
102
+ var HEX_RE = /^#?([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
103
+ var RGB_FN_RE = /^rgba?\(\s*([+-]?[\d.]+)\s*[,\s]\s*([+-]?[\d.]+)\s*[,\s]\s*([+-]?[\d.]+)(?:\s*[,/]\s*[+-]?[\d.]+%?)?\s*\)$/i;
104
+ function parseHexOrRgb(input) {
105
+ const text = input.trim();
106
+ const hexMatch = text.match(HEX_RE);
107
+ if (hexMatch) {
108
+ const hex = hexMatch[1];
109
+ if (hex.length === 3 || hex.length === 4) {
110
+ return {
111
+ r: parseInt(hex[0] + hex[0], 16),
112
+ g: parseInt(hex[1] + hex[1], 16),
113
+ b: parseInt(hex[2] + hex[2], 16)
114
+ };
115
+ }
116
+ return {
117
+ r: parseInt(hex.slice(0, 2), 16),
118
+ g: parseInt(hex.slice(2, 4), 16),
119
+ b: parseInt(hex.slice(4, 6), 16)
120
+ };
121
+ }
122
+ const rgbMatch = text.match(RGB_FN_RE);
123
+ if (rgbMatch) {
124
+ const r = Number(rgbMatch[1]);
125
+ const g = Number(rgbMatch[2]);
126
+ const b = Number(rgbMatch[3]);
127
+ if ([r, g, b].some((v) => Number.isNaN(v))) return null;
128
+ return { r: clamp(r, 0, 255), g: clamp(g, 0, 255), b: clamp(b, 0, 255) };
129
+ }
130
+ return null;
131
+ }
132
+
133
+ // src/color-util/tailwind-colors.ts
134
+ var tailwindColors = [
135
+ {
136
+ name: "Slate",
137
+ shades: {
138
+ "50": "#f8fafc",
139
+ "100": "#f1f5f9",
140
+ "200": "#e2e8f0",
141
+ "300": "#cbd5e1",
142
+ "400": "#94a3b8",
143
+ "500": "#64748b",
144
+ "600": "#475569",
145
+ "700": "#334155",
146
+ "800": "#1e293b",
147
+ "900": "#0f172a",
148
+ "950": "#020617"
149
+ }
150
+ },
151
+ {
152
+ name: "Gray",
153
+ shades: {
154
+ "50": "#f9fafb",
155
+ "100": "#f3f4f6",
156
+ "200": "#e5e7eb",
157
+ "300": "#d1d5db",
158
+ "400": "#9ca3af",
159
+ "500": "#6b7280",
160
+ "600": "#4b5563",
161
+ "700": "#374151",
162
+ "800": "#1f2937",
163
+ "900": "#111827",
164
+ "950": "#030712"
165
+ }
166
+ },
167
+ {
168
+ name: "Zinc",
169
+ shades: {
170
+ "50": "#fafafa",
171
+ "100": "#f4f4f5",
172
+ "200": "#e4e4e7",
173
+ "300": "#d4d4d8",
174
+ "400": "#a1a1aa",
175
+ "500": "#71717a",
176
+ "600": "#52525b",
177
+ "700": "#3f3f46",
178
+ "800": "#27272a",
179
+ "900": "#18181b",
180
+ "950": "#09090b"
181
+ }
182
+ },
183
+ {
184
+ name: "Neutral",
185
+ shades: {
186
+ "50": "#fafafa",
187
+ "100": "#f5f5f5",
188
+ "200": "#e5e5e5",
189
+ "300": "#d4d4d4",
190
+ "400": "#a3a3a3",
191
+ "500": "#737373",
192
+ "600": "#525252",
193
+ "700": "#404040",
194
+ "800": "#262626",
195
+ "900": "#171717",
196
+ "950": "#0a0a0a"
197
+ }
198
+ },
199
+ {
200
+ name: "Stone",
201
+ shades: {
202
+ "50": "#fafaf9",
203
+ "100": "#f5f5f4",
204
+ "200": "#e7e5e4",
205
+ "300": "#d6d3d1",
206
+ "400": "#a8a29e",
207
+ "500": "#78716c",
208
+ "600": "#57534e",
209
+ "700": "#44403c",
210
+ "800": "#292524",
211
+ "900": "#1c1917",
212
+ "950": "#0c0a09"
213
+ }
214
+ },
215
+ {
216
+ name: "Red",
217
+ shades: {
218
+ "50": "#fef2f2",
219
+ "100": "#fee2e2",
220
+ "200": "#fecaca",
221
+ "300": "#fca5a5",
222
+ "400": "#f87171",
223
+ "500": "#ef4444",
224
+ "600": "#dc2626",
225
+ "700": "#b91c1c",
226
+ "800": "#991b1b",
227
+ "900": "#7f1d1d",
228
+ "950": "#450a0a"
229
+ }
230
+ },
231
+ {
232
+ name: "Orange",
233
+ shades: {
234
+ "50": "#fff7ed",
235
+ "100": "#ffedd5",
236
+ "200": "#fed7aa",
237
+ "300": "#fdba74",
238
+ "400": "#fb923c",
239
+ "500": "#f97316",
240
+ "600": "#ea580c",
241
+ "700": "#c2410c",
242
+ "800": "#9a3412",
243
+ "900": "#7c2d12",
244
+ "950": "#431407"
245
+ }
246
+ },
247
+ {
248
+ name: "Amber",
249
+ shades: {
250
+ "50": "#fffbeb",
251
+ "100": "#fef3c7",
252
+ "200": "#fde68a",
253
+ "300": "#fcd34d",
254
+ "400": "#fbbf24",
255
+ "500": "#f59e0b",
256
+ "600": "#d97706",
257
+ "700": "#b45309",
258
+ "800": "#92400e",
259
+ "900": "#78350f",
260
+ "950": "#451a03"
261
+ }
262
+ },
263
+ {
264
+ name: "Yellow",
265
+ shades: {
266
+ "50": "#fefce8",
267
+ "100": "#fef9c3",
268
+ "200": "#fef08a",
269
+ "300": "#fde047",
270
+ "400": "#facc15",
271
+ "500": "#eab308",
272
+ "600": "#ca8a04",
273
+ "700": "#a16207",
274
+ "800": "#854d0e",
275
+ "900": "#713f12",
276
+ "950": "#422006"
277
+ }
278
+ },
279
+ {
280
+ name: "Lime",
281
+ shades: {
282
+ "50": "#f7fee7",
283
+ "100": "#ecfccb",
284
+ "200": "#d9f99d",
285
+ "300": "#bef264",
286
+ "400": "#a3e635",
287
+ "500": "#84cc16",
288
+ "600": "#65a30d",
289
+ "700": "#4d7c0f",
290
+ "800": "#3f6212",
291
+ "900": "#365314",
292
+ "950": "#1a2e05"
293
+ }
294
+ },
295
+ {
296
+ name: "Green",
297
+ shades: {
298
+ "50": "#f0fdf4",
299
+ "100": "#dcfce7",
300
+ "200": "#bbf7d0",
301
+ "300": "#86efac",
302
+ "400": "#4ade80",
303
+ "500": "#22c55e",
304
+ "600": "#16a34a",
305
+ "700": "#15803d",
306
+ "800": "#166534",
307
+ "900": "#14532d",
308
+ "950": "#052e16"
309
+ }
310
+ },
311
+ {
312
+ name: "Emerald",
313
+ shades: {
314
+ "50": "#ecfdf5",
315
+ "100": "#d1fae5",
316
+ "200": "#a7f3d0",
317
+ "300": "#6ee7b7",
318
+ "400": "#34d399",
319
+ "500": "#10b981",
320
+ "600": "#059669",
321
+ "700": "#047857",
322
+ "800": "#065f46",
323
+ "900": "#064e3b",
324
+ "950": "#022c22"
325
+ }
326
+ },
327
+ {
328
+ name: "Teal",
329
+ shades: {
330
+ "50": "#f0fdfa",
331
+ "100": "#ccfbf1",
332
+ "200": "#99f6e4",
333
+ "300": "#5eead4",
334
+ "400": "#2dd4bf",
335
+ "500": "#14b8a6",
336
+ "600": "#0d9488",
337
+ "700": "#0f766e",
338
+ "800": "#115e59",
339
+ "900": "#134e4a",
340
+ "950": "#042f2e"
341
+ }
342
+ },
343
+ {
344
+ name: "Cyan",
345
+ shades: {
346
+ "50": "#ecfeff",
347
+ "100": "#cffafe",
348
+ "200": "#a5f3fc",
349
+ "300": "#67e8f9",
350
+ "400": "#22d3ee",
351
+ "500": "#06b6d4",
352
+ "600": "#0891b2",
353
+ "700": "#0e7490",
354
+ "800": "#155e75",
355
+ "900": "#164e63",
356
+ "950": "#083344"
357
+ }
358
+ },
359
+ {
360
+ name: "Sky",
361
+ shades: {
362
+ "50": "#f0f9ff",
363
+ "100": "#e0f2fe",
364
+ "200": "#bae6fd",
365
+ "300": "#7dd3fc",
366
+ "400": "#38bdf8",
367
+ "500": "#0ea5e9",
368
+ "600": "#0284c7",
369
+ "700": "#0369a1",
370
+ "800": "#075985",
371
+ "900": "#0c4a6e",
372
+ "950": "#082f49"
373
+ }
374
+ },
375
+ {
376
+ name: "Blue",
377
+ shades: {
378
+ "50": "#eff6ff",
379
+ "100": "#dbeafe",
380
+ "200": "#bfdbfe",
381
+ "300": "#93c5fd",
382
+ "400": "#60a5fa",
383
+ "500": "#3b82f6",
384
+ "600": "#2563eb",
385
+ "700": "#1d4ed8",
386
+ "800": "#1e40af",
387
+ "900": "#1e3a8a",
388
+ "950": "#172554"
389
+ }
390
+ },
391
+ {
392
+ name: "Indigo",
393
+ shades: {
394
+ "50": "#eef2ff",
395
+ "100": "#e0e7ff",
396
+ "200": "#c7d2fe",
397
+ "300": "#a5b4fc",
398
+ "400": "#818cf8",
399
+ "500": "#6366f1",
400
+ "600": "#4f46e5",
401
+ "700": "#4338ca",
402
+ "800": "#3730a3",
403
+ "900": "#312e81",
404
+ "950": "#1e1b4b"
405
+ }
406
+ },
407
+ {
408
+ name: "Violet",
409
+ shades: {
410
+ "50": "#f5f3ff",
411
+ "100": "#ede9fe",
412
+ "200": "#ddd6fe",
413
+ "300": "#c4b5fd",
414
+ "400": "#a78bfa",
415
+ "500": "#8b5cf6",
416
+ "600": "#7c3aed",
417
+ "700": "#6d28d9",
418
+ "800": "#5b21b6",
419
+ "900": "#4c1d95",
420
+ "950": "#2e1065"
421
+ }
422
+ },
423
+ {
424
+ name: "Purple",
425
+ shades: {
426
+ "50": "#faf5ff",
427
+ "100": "#f3e8ff",
428
+ "200": "#e9d5ff",
429
+ "300": "#d8b4fe",
430
+ "400": "#c084fc",
431
+ "500": "#a855f7",
432
+ "600": "#9333ea",
433
+ "700": "#7e22ce",
434
+ "800": "#6b21a8",
435
+ "900": "#581c87",
436
+ "950": "#3b0764"
437
+ }
438
+ },
439
+ {
440
+ name: "Fuchsia",
441
+ shades: {
442
+ "50": "#fdf4ff",
443
+ "100": "#fae8ff",
444
+ "200": "#f5d0fe",
445
+ "300": "#f0abfc",
446
+ "400": "#e879f9",
447
+ "500": "#d946ef",
448
+ "600": "#c026d3",
449
+ "700": "#a21caf",
450
+ "800": "#86198f",
451
+ "900": "#701a75",
452
+ "950": "#4a044e"
453
+ }
454
+ },
455
+ {
456
+ name: "Pink",
457
+ shades: {
458
+ "50": "#fdf2f8",
459
+ "100": "#fce7f3",
460
+ "200": "#fbcfe8",
461
+ "300": "#f9a8d4",
462
+ "400": "#f472b6",
463
+ "500": "#ec4899",
464
+ "600": "#db2777",
465
+ "700": "#be185d",
466
+ "800": "#9d174d",
467
+ "900": "#831843",
468
+ "950": "#500724"
469
+ }
470
+ },
471
+ {
472
+ name: "Rose",
473
+ shades: {
474
+ "50": "#fff1f2",
475
+ "100": "#ffe4e6",
476
+ "200": "#fecdd3",
477
+ "300": "#fda4af",
478
+ "400": "#fb7185",
479
+ "500": "#f43f5e",
480
+ "600": "#e11d48",
481
+ "700": "#be123c",
482
+ "800": "#9f1239",
483
+ "900": "#881337",
484
+ "950": "#4c0519"
485
+ }
486
+ }
487
+ ];
488
+
489
+ // src/color-util/tailwind.ts
490
+ function getColorFromTailwind(tailwindColorString) {
491
+ const [colorName, shade] = tailwindColorString.split("-");
492
+ const colorGroup = tailwindColors.find((group) => group.name.toLowerCase() === (colorName ?? "").toLowerCase());
493
+ if (colorGroup) {
494
+ const shadeEntry = Object.entries(colorGroup.shades).find(([key]) => key === shade);
495
+ if (shadeEntry) {
496
+ return shadeEntry[1];
497
+ }
498
+ }
499
+ return "";
500
+ }
501
+ function findNearestTailwindColor(inputColor) {
502
+ let measure;
503
+ if (typeof inputColor === "string") {
504
+ const rgb = parseHexOrRgb(inputColor);
505
+ if (!rgb) return "";
506
+ measure = (hexValue) => {
507
+ const target = parseHexOrRgb(hexValue);
508
+ return target ? rgbDelta(rgb, target) : Infinity;
509
+ };
510
+ } else {
511
+ measure = (hexValue) => inputColor.delta(hexValue);
512
+ }
513
+ let nearestColor = "";
514
+ let smallestDistance = Infinity;
515
+ tailwindColors.forEach((colorGroup) => {
516
+ Object.entries(colorGroup.shades).forEach(([shade, hexValue]) => {
517
+ const distance = measure(hexValue);
518
+ if (distance < smallestDistance) {
519
+ smallestDistance = distance;
520
+ nearestColor = `${colorGroup.name.toLowerCase()}-${shade}`;
521
+ }
522
+ });
523
+ });
524
+ return nearestColor;
525
+ }
526
+ function formatTailwindColor(tailwindColor) {
527
+ const tailwindColorNames = [
528
+ "Slate",
529
+ "Gray",
530
+ "Zinc",
531
+ "Neutral",
532
+ "Stone",
533
+ "Red",
534
+ "Orange",
535
+ "Amber",
536
+ "Yellow",
537
+ "Lime",
538
+ "Green",
539
+ "Emerald",
540
+ "Teal",
541
+ "Cyan",
542
+ "Blue",
543
+ "Indigo",
544
+ "Violet",
545
+ "Sky",
546
+ "Purple",
547
+ "Fuchsia",
548
+ "Pink",
549
+ "Rose"
550
+ ];
551
+ const splitIndex = tailwindColor.search(/\d/);
552
+ if (splitIndex === -1) {
553
+ const colorName = tailwindColorNames.find((color) => tailwindColor.toLowerCase().includes(color.toLowerCase()));
554
+ if (colorName) {
555
+ return getColorFromTailwind(`${colorName.toLowerCase()}-500`);
556
+ }
557
+ }
558
+ if (splitIndex > 0) {
559
+ const colorNamePart = tailwindColor.slice(0, splitIndex);
560
+ let shadePart = tailwindColor.slice(splitIndex);
561
+ const matchedColors = tailwindColorNames.filter((color) => colorNamePart.toLowerCase().includes(color.toLowerCase()));
562
+ matchedColors.sort((a, b) => colorNamePart.toLowerCase().indexOf(a.toLowerCase()) - colorNamePart.toLowerCase().indexOf(b.toLowerCase()));
563
+ if (matchedColors.length > 0) {
564
+ const colorName = matchedColors[0].toLowerCase();
565
+ let shade = Math.round(parseInt(shadePart) / 100) * 100;
566
+ const formattedColor = getColorFromTailwind(`${colorName}-${shade.toString()}`);
567
+ if (formattedColor) {
568
+ return formattedColor;
569
+ }
570
+ }
571
+ }
572
+ return "";
573
+ }
574
+
575
+ // src/color-util/formats.ts
576
+ function formatHex(hex) {
577
+ return hex.startsWith("#") ? hex : `#${hex}`;
578
+ }
579
+ function formatRgbString(rgb) {
580
+ const rgbValues = rgb.replace(/[^\d,]/g, "").split(",");
581
+ if (rgbValues.length === 3) {
582
+ return `rgb(${rgbValues[0].trim()}, ${rgbValues[1].trim()}, ${rgbValues[2].trim()})`;
583
+ }
584
+ return "";
585
+ }
586
+ function formatRgbObject(rgbObject) {
587
+ const regex = /["']?r["']?\s*[:=]\s*(\d+)\s*[,]\s*["']?g["']?\s*[:=]\s*(\d+)\s*[,]\s*["']?b["']?\s*[:=]\s*(\d+)(?:\s*[,]\s*["']?a["']?\s*[:=]\s*(\d+))?/i;
588
+ const match = rgbObject.match(regex);
589
+ if (match) {
590
+ const r = match[1], g = match[2], b = match[3], a = match[4] || 1;
591
+ return `{"r":${r},"g":${g},"b":${b},"a":${a}}`;
592
+ }
593
+ return "";
594
+ }
595
+ function formatHslObject(hslObject) {
596
+ const regex = /["']?h["']?\s*[:=]\s*(\d+)\s*,\s*["']?s["']?\s*[:=]\s*(\d+)\s*,\s*["']?l["']?\s*[:=]\s*(\d+)(?:\s*,\s*["']?a["']?\s*[:=]\s*(\d+))?/i;
597
+ const match = hslObject.match(regex);
598
+ if (match) {
599
+ const h = match[1], s = match[2], l = match[3], a = match[4] || 1;
600
+ return `{"h":${h},"s":${s},"l":${l},"a":${a}}`;
601
+ }
602
+ return "";
603
+ }
604
+ function formatHslString(hslString) {
605
+ const hslValues = hslString.replace(/[^\d,%]/g, "").split(/\s*,\s*/);
606
+ if (hslValues.length === 3) {
607
+ return `hsl(${hslValues[0]}, ${hslValues[1]}%, ${hslValues[2]}%)`;
608
+ }
609
+ return "";
610
+ }
611
+ function formatHsvString(hsvString) {
612
+ const hsvValues = hsvString.replace(/[^\d%\s]/g, "").split(/\s+/).map((value) => parseInt(value.replace("%", ""), 10));
613
+ if (hsvValues.length === 3 && hsvValues.every((val) => !isNaN(val))) {
614
+ return `hsv(${hsvValues[0]}, ${hsvValues[1]}%, ${hsvValues[2]}%)`;
615
+ }
616
+ return "";
617
+ }
618
+ function formatRegularCmykString(cmykString) {
619
+ const cmykValues = cmykString.replace(/[^\d,]/g, "").split(/\s*,\s*/);
620
+ if (cmykValues.length === 4 && cmykValues.every((val) => !isNaN(Number(val)))) {
621
+ return `cmyk(${cmykValues[0]}, ${cmykValues[1]}, ${cmykValues[2]}, ${cmykValues[3]})`;
622
+ }
623
+ return "";
624
+ }
625
+ function formatCmykObject(cmykObject) {
626
+ const regex = /["']?c["']?\s*[:=]\s*(\d+)\s*,\s*["']?m["']?\s*[:=]\s*(\d+)\s*,\s*["']?y["']?\s*[:=]\s*(\d+)\s*,\s*["']?k["']?\s*[:=]\s*(\d+)(?:\s*,\s*["']?a["']?\s*[:=]\s*(\d+))?/i;
627
+ const match = cmykObject.match(regex);
628
+ if (match) {
629
+ const c = match[1], m = match[2], y = match[3], k = match[4], a = match[5] || 1;
630
+ return `{"c":${c},"m":${m},"y":${y},"k":${k},"a":${a}}`;
631
+ }
632
+ return "";
633
+ }
634
+ function formatCmykString(cmykString) {
635
+ const cmykValues = cmykString.replace(/[^\d%\s]/g, "").split(/\s+/).map((value) => parseInt(value.replace("%", ""), 10));
636
+ if (cmykValues.length === 4 && cmykValues.every((val) => !isNaN(val))) {
637
+ return `device-cmyk(${cmykValues[0]}% ${cmykValues[1]}% ${cmykValues[2]}% ${cmykValues[3]}%)`;
638
+ }
639
+ return "";
640
+ }
641
+ function isDeviceCmyk(cmykString) {
642
+ const regex = /device-cmyk\(\s*\d+%\s+\d+%\s+\d+%\s+\d+%\s*\)/;
643
+ return regex.test(cmykString);
644
+ }
645
+ function formatHwbString(hwbString) {
646
+ const hwbValues = hwbString.replace(/[^\d,%\s]/g, "").split(/\s+/);
647
+ if (hwbValues.length === 3) {
648
+ return `hwb(${hwbValues[0]}, ${hwbValues[1]}%, ${hwbValues[2]}%)`;
649
+ }
650
+ return "";
651
+ }
652
+ function formatLabString(labString) {
653
+ const match = labString.match(/(?:lab\()?\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s*\)?/i);
654
+ if (match) {
655
+ const [, l, a, b] = match;
656
+ return `lab(${l} ${a} ${b})`;
657
+ }
658
+ return "";
659
+ }
660
+ function formatLchString(lchString) {
661
+ const match = lchString.match(/(?:lch\()?\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s*\)?/i);
662
+ if (match) {
663
+ const [, l, c, h] = match;
664
+ return `lch(${l} ${c} ${h})`;
665
+ }
666
+ return "";
667
+ }
668
+ function formatHexWith0x(hex) {
669
+ if (hex.startsWith("0x")) {
670
+ return `#${hex.slice(2)}`;
671
+ }
672
+ return "";
673
+ }
674
+
675
+ // src/color-util/normalize.ts
676
+ function createColorNormalizer({ isValid }) {
677
+ return function normalizeColorInput(colorInput) {
678
+ if (isValid(colorInput)) {
679
+ return { value: colorInput, type: "standard" };
680
+ }
681
+ if (isDeviceCmyk(colorInput)) {
682
+ return { value: colorInput, type: "device-cmyk" };
683
+ }
684
+ const hex = formatHex(colorInput);
685
+ if (isValid(hex)) {
686
+ return { value: hex, type: "hex" };
687
+ }
688
+ const rgbString = formatRgbString(colorInput);
689
+ if (isValid(rgbString)) {
690
+ return { value: rgbString, type: "rgb" };
691
+ }
692
+ const rgbObject = formatRgbObject(colorInput);
693
+ if (rgbObject !== "") {
694
+ return { value: rgbObject, type: "rgb-object" };
695
+ }
696
+ const hslObject = formatHslObject(colorInput);
697
+ if (hslObject !== "") {
698
+ return { value: hslObject, type: "hsl-object" };
699
+ }
700
+ const hslString = formatHslString(colorInput);
701
+ if (isValid(hslString)) {
702
+ return { value: hslString, type: "hsl" };
703
+ }
704
+ const hsvString = formatHsvString(colorInput);
705
+ if (isValid(hsvString)) {
706
+ return { value: hsvString, type: "hsv" };
707
+ }
708
+ const tailwindColor = formatTailwindColor(colorInput);
709
+ if (tailwindColor !== "") {
710
+ return { value: tailwindColor, type: "tailwind" };
711
+ }
712
+ const regularCmykString = formatRegularCmykString(colorInput);
713
+ if (regularCmykString !== "") {
714
+ return { value: regularCmykString, type: "cmyk" };
715
+ }
716
+ const cmykObject = formatCmykObject(colorInput);
717
+ if (cmykObject !== "") {
718
+ return { value: cmykObject, type: "cmyk-object" };
719
+ }
720
+ const cmykString = formatCmykString(colorInput);
721
+ if (isValid(cmykString)) {
722
+ return { value: cmykString, type: "cmyk-percentage" };
723
+ }
724
+ const hwbString = formatHwbString(colorInput);
725
+ if (isValid(hwbString)) {
726
+ return { value: hwbString, type: "hwb" };
727
+ }
728
+ const labString = formatLabString(colorInput);
729
+ if (labString !== "") {
730
+ return { value: labString, type: "lab" };
731
+ }
732
+ const lchString = formatLchString(colorInput);
733
+ if (lchString !== "") {
734
+ return { value: lchString, type: "lch" };
735
+ }
736
+ const hexWith0x = formatHexWith0x(colorInput);
737
+ if (isValid(hexWith0x)) {
738
+ return { value: hexWith0x, type: "hex-0x" };
739
+ }
740
+ return null;
741
+ };
742
+ }
743
+ export {
744
+ createColorNormalizer,
745
+ findNearestTailwindColor,
746
+ formatCmykObject,
747
+ formatCmykString,
748
+ formatHex,
749
+ formatHexWith0x,
750
+ formatHslObject,
751
+ formatHslString,
752
+ formatHsvString,
753
+ formatHwbString,
754
+ formatLabString,
755
+ formatLchString,
756
+ formatRegularCmykString,
757
+ formatRgbObject,
758
+ formatRgbString,
759
+ formatTailwindColor,
760
+ getColorFromTailwind,
761
+ isDeviceCmyk,
762
+ parseHexOrRgb,
763
+ rgbDelta,
764
+ rgbToLab,
765
+ tailwindColors
766
+ };
767
+ //# sourceMappingURL=color-util.js.map