@xaui/core 0.1.7 → 0.1.8
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/LICENSE +21 -0
- package/README.md +50 -1
- package/dist/index.cjs +349 -2
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +58 -1
- package/dist/theme/index.cjs +9 -9
- package/dist/theme/index.d.cts +2 -1
- package/dist/theme/index.d.ts +2 -1
- package/dist/theme/index.js +9 -9
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bamory grams
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -269,12 +269,61 @@ const blue500 = colors.blue[500]
|
|
|
269
269
|
const red600 = colors.red[600]
|
|
270
270
|
```
|
|
271
271
|
|
|
272
|
+
## Spacing Tokens
|
|
273
|
+
|
|
274
|
+
Access the spacing scale for consistent layout:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
import { spacing } from '@xaui/core/tokens'
|
|
278
|
+
|
|
279
|
+
const smallGap = spacing.sm // 8
|
|
280
|
+
const mediumGap = spacing.md // 16
|
|
281
|
+
const largeGap = spacing.lg // 24
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Border Radius Tokens
|
|
285
|
+
|
|
286
|
+
Access border radius tokens:
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { borderRadius } from '@xaui/core/tokens'
|
|
290
|
+
|
|
291
|
+
const smallRadius = borderRadius.sm // 4
|
|
292
|
+
const mediumRadius = borderRadius.md // 8
|
|
293
|
+
const largeRadius = borderRadius.lg // 12
|
|
294
|
+
const fullRadius = borderRadius.full // 9999
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Typography Tokens
|
|
298
|
+
|
|
299
|
+
Access typography tokens:
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { fontSizes, fontWeights, fontFamilies } from '@xaui/core/tokens'
|
|
303
|
+
|
|
304
|
+
const headingSize = fontSizes['2xl'] // 24
|
|
305
|
+
const boldWeight = fontWeights.bold // 700
|
|
306
|
+
const bodyFont = fontFamilies.body // 'System'
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Shadow Tokens
|
|
310
|
+
|
|
311
|
+
Access shadow tokens for elevation:
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
import { shadows } from '@xaui/core/tokens'
|
|
315
|
+
|
|
316
|
+
const cardShadow = shadows.md
|
|
317
|
+
// { shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 2 }
|
|
318
|
+
```
|
|
319
|
+
|
|
272
320
|
## TypeScript Support
|
|
273
321
|
|
|
274
322
|
All exports are fully typed for excellent IntelliSense support:
|
|
275
323
|
|
|
276
324
|
```typescript
|
|
277
|
-
import type { XUITheme } from '@xaui/core/theme'
|
|
325
|
+
import type { XUITheme, DeepPartial } from '@xaui/core/theme'
|
|
326
|
+
import type { ColorRole, SpacingScale } from '@xaui/core/tokens'
|
|
278
327
|
```
|
|
279
328
|
|
|
280
329
|
## Theme Structure
|
package/dist/index.cjs
CHANGED
|
@@ -21,16 +21,362 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
getSafeThemeColor: () => getSafeThemeColor,
|
|
24
|
-
withOpacity: () => withOpacity
|
|
24
|
+
withOpacity: () => withOpacity,
|
|
25
|
+
withPaletteNumber: () => withPaletteNumber
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(src_exports);
|
|
27
28
|
|
|
29
|
+
// src/tokens/index.ts
|
|
30
|
+
var colors = {
|
|
31
|
+
slate: {
|
|
32
|
+
50: "#f8fafc",
|
|
33
|
+
100: "#f1f5f9",
|
|
34
|
+
200: "#e2e8f0",
|
|
35
|
+
300: "#cbd5e1",
|
|
36
|
+
400: "#94a3b8",
|
|
37
|
+
500: "#64748b",
|
|
38
|
+
600: "#475569",
|
|
39
|
+
700: "#334155",
|
|
40
|
+
800: "#1e293b",
|
|
41
|
+
900: "#0f172a",
|
|
42
|
+
950: "#020617"
|
|
43
|
+
},
|
|
44
|
+
gray: {
|
|
45
|
+
50: "#f9fafb",
|
|
46
|
+
100: "#f3f4f6",
|
|
47
|
+
200: "#e5e7eb",
|
|
48
|
+
300: "#d1d5db",
|
|
49
|
+
400: "#9ca3af",
|
|
50
|
+
500: "#6b7280",
|
|
51
|
+
600: "#4b5563",
|
|
52
|
+
700: "#374151",
|
|
53
|
+
800: "#1f2937",
|
|
54
|
+
900: "#111827",
|
|
55
|
+
950: "#030712"
|
|
56
|
+
},
|
|
57
|
+
zinc: {
|
|
58
|
+
50: "#fafafa",
|
|
59
|
+
100: "#f4f4f5",
|
|
60
|
+
200: "#e4e4e7",
|
|
61
|
+
300: "#d4d4d8",
|
|
62
|
+
400: "#a1a1aa",
|
|
63
|
+
500: "#71717a",
|
|
64
|
+
600: "#52525b",
|
|
65
|
+
700: "#3f3f46",
|
|
66
|
+
800: "#27272a",
|
|
67
|
+
900: "#18181b",
|
|
68
|
+
950: "#09090b"
|
|
69
|
+
},
|
|
70
|
+
neutral: {
|
|
71
|
+
50: "#fafafa",
|
|
72
|
+
100: "#f5f5f5",
|
|
73
|
+
200: "#e5e5e5",
|
|
74
|
+
300: "#d4d4d4",
|
|
75
|
+
400: "#a3a3a3",
|
|
76
|
+
500: "#737373",
|
|
77
|
+
600: "#525252",
|
|
78
|
+
700: "#404040",
|
|
79
|
+
800: "#262626",
|
|
80
|
+
900: "#171717",
|
|
81
|
+
950: "#0a0a0a"
|
|
82
|
+
},
|
|
83
|
+
stone: {
|
|
84
|
+
50: "#fafaf9",
|
|
85
|
+
100: "#f5f5f4",
|
|
86
|
+
200: "#e7e5e4",
|
|
87
|
+
300: "#d6d3d1",
|
|
88
|
+
400: "#a8a29e",
|
|
89
|
+
500: "#78716c",
|
|
90
|
+
600: "#57534e",
|
|
91
|
+
700: "#44403c",
|
|
92
|
+
800: "#292524",
|
|
93
|
+
900: "#1c1917",
|
|
94
|
+
950: "#0c0a09"
|
|
95
|
+
},
|
|
96
|
+
red: {
|
|
97
|
+
50: "#fef2f2",
|
|
98
|
+
100: "#fee2e2",
|
|
99
|
+
200: "#fecaca",
|
|
100
|
+
300: "#fca5a5",
|
|
101
|
+
400: "#f87171",
|
|
102
|
+
500: "#ef4444",
|
|
103
|
+
600: "#dc2626",
|
|
104
|
+
700: "#b91c1c",
|
|
105
|
+
800: "#991b1b",
|
|
106
|
+
900: "#7f1d1d",
|
|
107
|
+
950: "#450a0a"
|
|
108
|
+
},
|
|
109
|
+
orange: {
|
|
110
|
+
50: "#fff7ed",
|
|
111
|
+
100: "#ffedd5",
|
|
112
|
+
200: "#fed7aa",
|
|
113
|
+
300: "#fdba74",
|
|
114
|
+
400: "#fb923c",
|
|
115
|
+
500: "#f97316",
|
|
116
|
+
600: "#ea580c",
|
|
117
|
+
700: "#c2410c",
|
|
118
|
+
800: "#9a3412",
|
|
119
|
+
900: "#7c2d12",
|
|
120
|
+
950: "#431407"
|
|
121
|
+
},
|
|
122
|
+
amber: {
|
|
123
|
+
50: "#fffbeb",
|
|
124
|
+
100: "#fef3c7",
|
|
125
|
+
200: "#fde68a",
|
|
126
|
+
300: "#fcd34d",
|
|
127
|
+
400: "#fbbf24",
|
|
128
|
+
500: "#f59e0b",
|
|
129
|
+
600: "#d97706",
|
|
130
|
+
700: "#b45309",
|
|
131
|
+
800: "#92400e",
|
|
132
|
+
900: "#78350f",
|
|
133
|
+
950: "#451a03"
|
|
134
|
+
},
|
|
135
|
+
yellow: {
|
|
136
|
+
50: "#fefce8",
|
|
137
|
+
100: "#fef9c3",
|
|
138
|
+
200: "#fef08a",
|
|
139
|
+
300: "#fde047",
|
|
140
|
+
400: "#facc15",
|
|
141
|
+
500: "#eab308",
|
|
142
|
+
600: "#ca8a04",
|
|
143
|
+
700: "#a16207",
|
|
144
|
+
800: "#854d0e",
|
|
145
|
+
900: "#713f12",
|
|
146
|
+
950: "#422006"
|
|
147
|
+
},
|
|
148
|
+
lime: {
|
|
149
|
+
50: "#f7fee7",
|
|
150
|
+
100: "#ecfccb",
|
|
151
|
+
200: "#d9f99d",
|
|
152
|
+
300: "#bef264",
|
|
153
|
+
400: "#a3e635",
|
|
154
|
+
500: "#84cc16",
|
|
155
|
+
600: "#65a30d",
|
|
156
|
+
700: "#4d7c0f",
|
|
157
|
+
800: "#3f6212",
|
|
158
|
+
900: "#365314",
|
|
159
|
+
950: "#1a2e05"
|
|
160
|
+
},
|
|
161
|
+
green: {
|
|
162
|
+
50: "#f0fdf4",
|
|
163
|
+
100: "#dcfce7",
|
|
164
|
+
200: "#bbf7d0",
|
|
165
|
+
300: "#86efac",
|
|
166
|
+
400: "#4ade80",
|
|
167
|
+
500: "#22c55e",
|
|
168
|
+
600: "#16a34a",
|
|
169
|
+
700: "#15803d",
|
|
170
|
+
800: "#166534",
|
|
171
|
+
900: "#14532d",
|
|
172
|
+
950: "#052e16"
|
|
173
|
+
},
|
|
174
|
+
emerald: {
|
|
175
|
+
50: "#ecfdf5",
|
|
176
|
+
100: "#d1fae5",
|
|
177
|
+
200: "#a7f3d0",
|
|
178
|
+
300: "#6ee7b7",
|
|
179
|
+
400: "#34d399",
|
|
180
|
+
500: "#10b981",
|
|
181
|
+
600: "#059669",
|
|
182
|
+
700: "#047857",
|
|
183
|
+
800: "#065f46",
|
|
184
|
+
900: "#064e3b",
|
|
185
|
+
950: "#022c22"
|
|
186
|
+
},
|
|
187
|
+
teal: {
|
|
188
|
+
50: "#f0fdfa",
|
|
189
|
+
100: "#ccfbf1",
|
|
190
|
+
200: "#99f6e4",
|
|
191
|
+
300: "#5eead4",
|
|
192
|
+
400: "#2dd4bf",
|
|
193
|
+
500: "#14b8a6",
|
|
194
|
+
600: "#0d9488",
|
|
195
|
+
700: "#0f766e",
|
|
196
|
+
800: "#115e59",
|
|
197
|
+
900: "#134e4a",
|
|
198
|
+
950: "#042f2e"
|
|
199
|
+
},
|
|
200
|
+
cyan: {
|
|
201
|
+
50: "#ecfeff",
|
|
202
|
+
100: "#cffafe",
|
|
203
|
+
200: "#a5f3fc",
|
|
204
|
+
300: "#67e8f9",
|
|
205
|
+
400: "#22d3ee",
|
|
206
|
+
500: "#06b6d4",
|
|
207
|
+
600: "#0891b2",
|
|
208
|
+
700: "#0e7490",
|
|
209
|
+
800: "#155e75",
|
|
210
|
+
900: "#164e63",
|
|
211
|
+
950: "#083344"
|
|
212
|
+
},
|
|
213
|
+
sky: {
|
|
214
|
+
50: "#f0f9ff",
|
|
215
|
+
100: "#e0f2fe",
|
|
216
|
+
200: "#bae6fd",
|
|
217
|
+
300: "#7dd3fc",
|
|
218
|
+
400: "#38bdf8",
|
|
219
|
+
500: "#0ea5e9",
|
|
220
|
+
600: "#0284c7",
|
|
221
|
+
700: "#0369a1",
|
|
222
|
+
800: "#075985",
|
|
223
|
+
900: "#0c4a6e",
|
|
224
|
+
950: "#082f49"
|
|
225
|
+
},
|
|
226
|
+
blue: {
|
|
227
|
+
50: "#eff6ff",
|
|
228
|
+
100: "#dbeafe",
|
|
229
|
+
200: "#bfdbfe",
|
|
230
|
+
300: "#93c5fd",
|
|
231
|
+
400: "#60a5fa",
|
|
232
|
+
500: "#3b82f6",
|
|
233
|
+
600: "#2563eb",
|
|
234
|
+
700: "#1d4ed8",
|
|
235
|
+
800: "#1e40af",
|
|
236
|
+
900: "#1e3a8a",
|
|
237
|
+
950: "#172554"
|
|
238
|
+
},
|
|
239
|
+
indigo: {
|
|
240
|
+
50: "#eef2ff",
|
|
241
|
+
100: "#e0e7ff",
|
|
242
|
+
200: "#c7d2fe",
|
|
243
|
+
300: "#a5b4fc",
|
|
244
|
+
400: "#818cf8",
|
|
245
|
+
500: "#6366f1",
|
|
246
|
+
600: "#4f46e5",
|
|
247
|
+
700: "#4338ca",
|
|
248
|
+
800: "#3730a3",
|
|
249
|
+
900: "#312e81",
|
|
250
|
+
950: "#1e1b4b"
|
|
251
|
+
},
|
|
252
|
+
violet: {
|
|
253
|
+
50: "#f5f3ff",
|
|
254
|
+
100: "#ede9fe",
|
|
255
|
+
200: "#ddd6fe",
|
|
256
|
+
300: "#c4b5fd",
|
|
257
|
+
400: "#a78bfa",
|
|
258
|
+
500: "#8b5cf6",
|
|
259
|
+
600: "#7c3aed",
|
|
260
|
+
700: "#6d28d9",
|
|
261
|
+
800: "#5b21b6",
|
|
262
|
+
900: "#4c1d95",
|
|
263
|
+
950: "#2e1065"
|
|
264
|
+
},
|
|
265
|
+
purple: {
|
|
266
|
+
50: "#faf5ff",
|
|
267
|
+
100: "#f3e8ff",
|
|
268
|
+
200: "#e9d5ff",
|
|
269
|
+
300: "#d8b4fe",
|
|
270
|
+
400: "#c084fc",
|
|
271
|
+
500: "#a855f7",
|
|
272
|
+
600: "#9333ea",
|
|
273
|
+
700: "#7e22ce",
|
|
274
|
+
800: "#6b21a8",
|
|
275
|
+
900: "#581c87",
|
|
276
|
+
950: "#3b0764"
|
|
277
|
+
},
|
|
278
|
+
fuchsia: {
|
|
279
|
+
50: "#fdf4ff",
|
|
280
|
+
100: "#fae8ff",
|
|
281
|
+
200: "#f5d0fe",
|
|
282
|
+
300: "#f0abfc",
|
|
283
|
+
400: "#e879f9",
|
|
284
|
+
500: "#d946ef",
|
|
285
|
+
600: "#c026d3",
|
|
286
|
+
700: "#a21caf",
|
|
287
|
+
800: "#86198f",
|
|
288
|
+
900: "#701a75",
|
|
289
|
+
950: "#4a044e"
|
|
290
|
+
},
|
|
291
|
+
pink: {
|
|
292
|
+
50: "#fdf2f8",
|
|
293
|
+
100: "#fce7f3",
|
|
294
|
+
200: "#fbcfe8",
|
|
295
|
+
300: "#f9a8d4",
|
|
296
|
+
400: "#f472b6",
|
|
297
|
+
500: "#ec4899",
|
|
298
|
+
600: "#db2777",
|
|
299
|
+
700: "#be185d",
|
|
300
|
+
800: "#9d174d",
|
|
301
|
+
900: "#831843",
|
|
302
|
+
950: "#500724"
|
|
303
|
+
},
|
|
304
|
+
rose: {
|
|
305
|
+
50: "#fff1f2",
|
|
306
|
+
100: "#ffe4e6",
|
|
307
|
+
200: "#fecdd3",
|
|
308
|
+
300: "#fda4af",
|
|
309
|
+
400: "#fb7185",
|
|
310
|
+
500: "#f43f5e",
|
|
311
|
+
600: "#e11d48",
|
|
312
|
+
700: "#be123c",
|
|
313
|
+
800: "#9f1239",
|
|
314
|
+
900: "#881337",
|
|
315
|
+
950: "#4c0519"
|
|
316
|
+
},
|
|
317
|
+
black: "#000000",
|
|
318
|
+
white: "#ffffff",
|
|
319
|
+
transparent: "transparent"
|
|
320
|
+
};
|
|
321
|
+
|
|
28
322
|
// src/utils/colors-utils.ts
|
|
29
323
|
function withOpacity(color, opacity) {
|
|
30
324
|
const clampedOpacity = Math.max(0, Math.min(1, opacity));
|
|
31
325
|
const alpha = Math.round(clampedOpacity * 255).toString(16).padStart(2, "0");
|
|
32
326
|
return `${color}${alpha}`;
|
|
33
327
|
}
|
|
328
|
+
var normalizeHexColor = (color) => {
|
|
329
|
+
const normalized = color.trim().toLowerCase();
|
|
330
|
+
if (!normalized.startsWith("#")) return normalized;
|
|
331
|
+
if (normalized.length === 9) return normalized.slice(0, 7);
|
|
332
|
+
if (normalized.length === 5) {
|
|
333
|
+
const [r, g, b] = normalized.slice(1, 4).split("");
|
|
334
|
+
return `#${r}${r}${g}${g}${b}${b}`;
|
|
335
|
+
}
|
|
336
|
+
return normalized;
|
|
337
|
+
};
|
|
338
|
+
var colorPalettes = Object.values(colors).filter(
|
|
339
|
+
(value) => typeof value === "object" && value !== null
|
|
340
|
+
);
|
|
341
|
+
var hexToRgb = (color) => {
|
|
342
|
+
const normalized = normalizeHexColor(color);
|
|
343
|
+
if (!normalized.startsWith("#") || normalized.length !== 7) return null;
|
|
344
|
+
const r = parseInt(normalized.slice(1, 3), 16);
|
|
345
|
+
const g = parseInt(normalized.slice(3, 5), 16);
|
|
346
|
+
const b = parseInt(normalized.slice(5, 7), 16);
|
|
347
|
+
return Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b) ? null : [r, g, b];
|
|
348
|
+
};
|
|
349
|
+
var colorDistance = (a, b) => {
|
|
350
|
+
const dr = a[0] - b[0];
|
|
351
|
+
const dg = a[1] - b[1];
|
|
352
|
+
const db = a[2] - b[2];
|
|
353
|
+
return dr * dr + dg * dg + db * db;
|
|
354
|
+
};
|
|
355
|
+
function withPaletteNumber(color, paletteNumber) {
|
|
356
|
+
const normalizedInput = normalizeHexColor(color);
|
|
357
|
+
const inputRgb = hexToRgb(normalizedInput);
|
|
358
|
+
if (!inputRgb) return color;
|
|
359
|
+
const exactPalette = colorPalettes.find(
|
|
360
|
+
(scale) => Object.values(scale).some(
|
|
361
|
+
(scaleColor) => normalizeHexColor(scaleColor) === normalizedInput
|
|
362
|
+
)
|
|
363
|
+
);
|
|
364
|
+
if (exactPalette) return exactPalette[paletteNumber];
|
|
365
|
+
let nearestPalette = null;
|
|
366
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
367
|
+
for (const palette of colorPalettes) {
|
|
368
|
+
for (const swatch of Object.values(palette)) {
|
|
369
|
+
const swatchRgb = hexToRgb(swatch);
|
|
370
|
+
if (!swatchRgb) continue;
|
|
371
|
+
const distance = colorDistance(inputRgb, swatchRgb);
|
|
372
|
+
if (distance < nearestDistance) {
|
|
373
|
+
nearestDistance = distance;
|
|
374
|
+
nearestPalette = palette;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return nearestPalette ? nearestPalette[paletteNumber] : color;
|
|
379
|
+
}
|
|
34
380
|
var validThemeColors = [
|
|
35
381
|
"primary",
|
|
36
382
|
"secondary",
|
|
@@ -46,5 +392,6 @@ function getSafeThemeColor(themeColor) {
|
|
|
46
392
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47
393
|
0 && (module.exports = {
|
|
48
394
|
getSafeThemeColor,
|
|
49
|
-
withOpacity
|
|
395
|
+
withOpacity,
|
|
396
|
+
withPaletteNumber
|
|
50
397
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -5,8 +5,16 @@
|
|
|
5
5
|
* @returns Color with opacity
|
|
6
6
|
*/
|
|
7
7
|
declare function withOpacity(color: string, opacity: number): string;
|
|
8
|
+
type PaletteNumber = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
|
|
9
|
+
/**
|
|
10
|
+
* Create opacity variants for a color
|
|
11
|
+
* @param color - Base color hex
|
|
12
|
+
* @param paletteNumber - Palette number (50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950)
|
|
13
|
+
* @returns Color from matched (or nearest) palette family at the requested palette number
|
|
14
|
+
*/
|
|
15
|
+
declare function withPaletteNumber(color: string, paletteNumber: PaletteNumber): string;
|
|
8
16
|
declare const validThemeColors: readonly ["primary", "secondary", "tertiary", "danger", "warning", "success", "default"];
|
|
9
17
|
declare function getSafeThemeColor(themeColor: string): ValidThemeColor;
|
|
10
18
|
type ValidThemeColor = (typeof validThemeColors)[number];
|
|
11
19
|
|
|
12
|
-
export { getSafeThemeColor, withOpacity };
|
|
20
|
+
export { getSafeThemeColor, withOpacity, withPaletteNumber };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,16 @@
|
|
|
5
5
|
* @returns Color with opacity
|
|
6
6
|
*/
|
|
7
7
|
declare function withOpacity(color: string, opacity: number): string;
|
|
8
|
+
type PaletteNumber = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
|
|
9
|
+
/**
|
|
10
|
+
* Create opacity variants for a color
|
|
11
|
+
* @param color - Base color hex
|
|
12
|
+
* @param paletteNumber - Palette number (50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950)
|
|
13
|
+
* @returns Color from matched (or nearest) palette family at the requested palette number
|
|
14
|
+
*/
|
|
15
|
+
declare function withPaletteNumber(color: string, paletteNumber: PaletteNumber): string;
|
|
8
16
|
declare const validThemeColors: readonly ["primary", "secondary", "tertiary", "danger", "warning", "success", "default"];
|
|
9
17
|
declare function getSafeThemeColor(themeColor: string): ValidThemeColor;
|
|
10
18
|
type ValidThemeColor = (typeof validThemeColors)[number];
|
|
11
19
|
|
|
12
|
-
export { getSafeThemeColor, withOpacity };
|
|
20
|
+
export { getSafeThemeColor, withOpacity, withPaletteNumber };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
colors
|
|
3
|
+
} from "./chunk-IRULUOQR.js";
|
|
4
|
+
|
|
1
5
|
// src/utils/colors-utils.ts
|
|
2
6
|
function withOpacity(color, opacity) {
|
|
3
7
|
const clampedOpacity = Math.max(0, Math.min(1, opacity));
|
|
4
8
|
const alpha = Math.round(clampedOpacity * 255).toString(16).padStart(2, "0");
|
|
5
9
|
return `${color}${alpha}`;
|
|
6
10
|
}
|
|
11
|
+
var normalizeHexColor = (color) => {
|
|
12
|
+
const normalized = color.trim().toLowerCase();
|
|
13
|
+
if (!normalized.startsWith("#")) return normalized;
|
|
14
|
+
if (normalized.length === 9) return normalized.slice(0, 7);
|
|
15
|
+
if (normalized.length === 5) {
|
|
16
|
+
const [r, g, b] = normalized.slice(1, 4).split("");
|
|
17
|
+
return `#${r}${r}${g}${g}${b}${b}`;
|
|
18
|
+
}
|
|
19
|
+
return normalized;
|
|
20
|
+
};
|
|
21
|
+
var colorPalettes = Object.values(colors).filter(
|
|
22
|
+
(value) => typeof value === "object" && value !== null
|
|
23
|
+
);
|
|
24
|
+
var hexToRgb = (color) => {
|
|
25
|
+
const normalized = normalizeHexColor(color);
|
|
26
|
+
if (!normalized.startsWith("#") || normalized.length !== 7) return null;
|
|
27
|
+
const r = parseInt(normalized.slice(1, 3), 16);
|
|
28
|
+
const g = parseInt(normalized.slice(3, 5), 16);
|
|
29
|
+
const b = parseInt(normalized.slice(5, 7), 16);
|
|
30
|
+
return Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b) ? null : [r, g, b];
|
|
31
|
+
};
|
|
32
|
+
var colorDistance = (a, b) => {
|
|
33
|
+
const dr = a[0] - b[0];
|
|
34
|
+
const dg = a[1] - b[1];
|
|
35
|
+
const db = a[2] - b[2];
|
|
36
|
+
return dr * dr + dg * dg + db * db;
|
|
37
|
+
};
|
|
38
|
+
function withPaletteNumber(color, paletteNumber) {
|
|
39
|
+
const normalizedInput = normalizeHexColor(color);
|
|
40
|
+
const inputRgb = hexToRgb(normalizedInput);
|
|
41
|
+
if (!inputRgb) return color;
|
|
42
|
+
const exactPalette = colorPalettes.find(
|
|
43
|
+
(scale) => Object.values(scale).some(
|
|
44
|
+
(scaleColor) => normalizeHexColor(scaleColor) === normalizedInput
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
if (exactPalette) return exactPalette[paletteNumber];
|
|
48
|
+
let nearestPalette = null;
|
|
49
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
50
|
+
for (const palette of colorPalettes) {
|
|
51
|
+
for (const swatch of Object.values(palette)) {
|
|
52
|
+
const swatchRgb = hexToRgb(swatch);
|
|
53
|
+
if (!swatchRgb) continue;
|
|
54
|
+
const distance = colorDistance(inputRgb, swatchRgb);
|
|
55
|
+
if (distance < nearestDistance) {
|
|
56
|
+
nearestDistance = distance;
|
|
57
|
+
nearestPalette = palette;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return nearestPalette ? nearestPalette[paletteNumber] : color;
|
|
62
|
+
}
|
|
7
63
|
var validThemeColors = [
|
|
8
64
|
"primary",
|
|
9
65
|
"secondary",
|
|
@@ -18,5 +74,6 @@ function getSafeThemeColor(themeColor) {
|
|
|
18
74
|
}
|
|
19
75
|
export {
|
|
20
76
|
getSafeThemeColor,
|
|
21
|
-
withOpacity
|
|
77
|
+
withOpacity,
|
|
78
|
+
withPaletteNumber
|
|
22
79
|
};
|
package/dist/theme/index.cjs
CHANGED
|
@@ -328,12 +328,12 @@ var themeColors = {
|
|
|
328
328
|
secondary: {
|
|
329
329
|
main: colors.zinc[500],
|
|
330
330
|
foreground: colors.white,
|
|
331
|
-
background: colors.
|
|
331
|
+
background: colors.zinc[200]
|
|
332
332
|
},
|
|
333
333
|
tertiary: {
|
|
334
334
|
main: colors.stone[500],
|
|
335
335
|
foreground: colors.white,
|
|
336
|
-
background: colors.
|
|
336
|
+
background: colors.stone[100]
|
|
337
337
|
},
|
|
338
338
|
danger: {
|
|
339
339
|
main: colors.red[700],
|
|
@@ -351,8 +351,8 @@ var themeColors = {
|
|
|
351
351
|
background: colors.green[100]
|
|
352
352
|
},
|
|
353
353
|
default: {
|
|
354
|
-
main: colors.
|
|
355
|
-
foreground: colors.
|
|
354
|
+
main: colors.zinc[900],
|
|
355
|
+
foreground: colors.white,
|
|
356
356
|
background: colors.zinc[200]
|
|
357
357
|
},
|
|
358
358
|
background: colors.white,
|
|
@@ -390,8 +390,8 @@ var darkThemeColors = {
|
|
|
390
390
|
background: colors.green[900]
|
|
391
391
|
},
|
|
392
392
|
default: {
|
|
393
|
-
main: colors.
|
|
394
|
-
foreground: colors.
|
|
393
|
+
main: colors.stone[200],
|
|
394
|
+
foreground: colors.zinc[900],
|
|
395
395
|
background: colors.zinc[700]
|
|
396
396
|
},
|
|
397
397
|
background: colors.zinc[900],
|
|
@@ -423,9 +423,9 @@ var baseTheme = {
|
|
|
423
423
|
none: 0,
|
|
424
424
|
xs: 0.5,
|
|
425
425
|
sm: 1,
|
|
426
|
-
md:
|
|
427
|
-
lg:
|
|
428
|
-
xl:
|
|
426
|
+
md: 1.75,
|
|
427
|
+
lg: 2.5,
|
|
428
|
+
xl: 3
|
|
429
429
|
},
|
|
430
430
|
fontSizes: {
|
|
431
431
|
xs: 12,
|
package/dist/theme/index.d.cts
CHANGED
|
@@ -121,7 +121,8 @@ interface XUITheme {
|
|
|
121
121
|
fontFamilies: ThemeFontFamilies;
|
|
122
122
|
shadows: ThemeShadows;
|
|
123
123
|
}
|
|
124
|
+
type PartialXUITheme = Partial<XUITheme>;
|
|
124
125
|
declare const defaultTheme: XUITheme;
|
|
125
126
|
declare const defaultDarkTheme: XUITheme;
|
|
126
127
|
|
|
127
|
-
export { type XUITheme, defaultDarkTheme, defaultTheme };
|
|
128
|
+
export { type PartialXUITheme, type XUITheme, defaultDarkTheme, defaultTheme };
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -121,7 +121,8 @@ interface XUITheme {
|
|
|
121
121
|
fontFamilies: ThemeFontFamilies;
|
|
122
122
|
shadows: ThemeShadows;
|
|
123
123
|
}
|
|
124
|
+
type PartialXUITheme = Partial<XUITheme>;
|
|
124
125
|
declare const defaultTheme: XUITheme;
|
|
125
126
|
declare const defaultDarkTheme: XUITheme;
|
|
126
127
|
|
|
127
|
-
export { type XUITheme, defaultDarkTheme, defaultTheme };
|
|
128
|
+
export { type PartialXUITheme, type XUITheme, defaultDarkTheme, defaultTheme };
|
package/dist/theme/index.js
CHANGED
|
@@ -12,12 +12,12 @@ var themeColors = {
|
|
|
12
12
|
secondary: {
|
|
13
13
|
main: colors.zinc[500],
|
|
14
14
|
foreground: colors.white,
|
|
15
|
-
background: colors.
|
|
15
|
+
background: colors.zinc[200]
|
|
16
16
|
},
|
|
17
17
|
tertiary: {
|
|
18
18
|
main: colors.stone[500],
|
|
19
19
|
foreground: colors.white,
|
|
20
|
-
background: colors.
|
|
20
|
+
background: colors.stone[100]
|
|
21
21
|
},
|
|
22
22
|
danger: {
|
|
23
23
|
main: colors.red[700],
|
|
@@ -35,8 +35,8 @@ var themeColors = {
|
|
|
35
35
|
background: colors.green[100]
|
|
36
36
|
},
|
|
37
37
|
default: {
|
|
38
|
-
main: colors.
|
|
39
|
-
foreground: colors.
|
|
38
|
+
main: colors.zinc[900],
|
|
39
|
+
foreground: colors.white,
|
|
40
40
|
background: colors.zinc[200]
|
|
41
41
|
},
|
|
42
42
|
background: colors.white,
|
|
@@ -74,8 +74,8 @@ var darkThemeColors = {
|
|
|
74
74
|
background: colors.green[900]
|
|
75
75
|
},
|
|
76
76
|
default: {
|
|
77
|
-
main: colors.
|
|
78
|
-
foreground: colors.
|
|
77
|
+
main: colors.stone[200],
|
|
78
|
+
foreground: colors.zinc[900],
|
|
79
79
|
background: colors.zinc[700]
|
|
80
80
|
},
|
|
81
81
|
background: colors.zinc[900],
|
|
@@ -107,9 +107,9 @@ var baseTheme = {
|
|
|
107
107
|
none: 0,
|
|
108
108
|
xs: 0.5,
|
|
109
109
|
sm: 1,
|
|
110
|
-
md:
|
|
111
|
-
lg:
|
|
112
|
-
xl:
|
|
110
|
+
md: 1.75,
|
|
111
|
+
lg: 2.5,
|
|
112
|
+
xl: 3
|
|
113
113
|
},
|
|
114
114
|
fontSizes: {
|
|
115
115
|
xs: 12,
|