@unocss/preset-mini 0.44.5 → 0.45.3

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.
@@ -1,337 +1,684 @@
1
- const colors = {
2
- inherit: "inherit",
3
- current: "currentColor",
4
- transparent: "transparent",
5
- black: "#000",
6
- white: "#fff",
7
- rose: {
8
- 50: "#fff1f2",
9
- 100: "#ffe4e6",
10
- 200: "#fecdd3",
11
- 300: "#fda4af",
12
- 400: "#fb7185",
13
- 500: "#f43f5e",
14
- 600: "#e11d48",
15
- 700: "#be123c",
16
- 800: "#9f1239",
17
- 900: "#881337"
18
- },
19
- pink: {
20
- 50: "#fdf2f8",
21
- 100: "#fce7f3",
22
- 200: "#fbcfe8",
23
- 300: "#f9a8d4",
24
- 400: "#f472b6",
25
- 500: "#ec4899",
26
- 600: "#db2777",
27
- 700: "#be185d",
28
- 800: "#9d174d",
29
- 900: "#831843"
30
- },
31
- fuchsia: {
32
- 50: "#fdf4ff",
33
- 100: "#fae8ff",
34
- 200: "#f5d0fe",
35
- 300: "#f0abfc",
36
- 400: "#e879f9",
37
- 500: "#d946ef",
38
- 600: "#c026d3",
39
- 700: "#a21caf",
40
- 800: "#86198f",
41
- 900: "#701a75"
42
- },
43
- purple: {
44
- 50: "#faf5ff",
45
- 100: "#f3e8ff",
46
- 200: "#e9d5ff",
47
- 300: "#d8b4fe",
48
- 400: "#c084fc",
49
- 500: "#a855f7",
50
- 600: "#9333ea",
51
- 700: "#7e22ce",
52
- 800: "#6b21a8",
53
- 900: "#581c87"
54
- },
55
- violet: {
56
- 50: "#f5f3ff",
57
- 100: "#ede9fe",
58
- 200: "#ddd6fe",
59
- 300: "#c4b5fd",
60
- 400: "#a78bfa",
61
- 500: "#8b5cf6",
62
- 600: "#7c3aed",
63
- 700: "#6d28d9",
64
- 800: "#5b21b6",
65
- 900: "#4c1d95"
66
- },
67
- indigo: {
68
- 50: "#eef2ff",
69
- 100: "#e0e7ff",
70
- 200: "#c7d2fe",
71
- 300: "#a5b4fc",
72
- 400: "#818cf8",
73
- 500: "#6366f1",
74
- 600: "#4f46e5",
75
- 700: "#4338ca",
76
- 800: "#3730a3",
77
- 900: "#312e81"
78
- },
79
- blue: {
80
- 50: "#eff6ff",
81
- 100: "#dbeafe",
82
- 200: "#bfdbfe",
83
- 300: "#93c5fd",
84
- 400: "#60a5fa",
85
- 500: "#3b82f6",
86
- 600: "#2563eb",
87
- 700: "#1d4ed8",
88
- 800: "#1e40af",
89
- 900: "#1e3a8a"
90
- },
91
- sky: {
92
- 50: "#f0f9ff",
93
- 100: "#e0f2fe",
94
- 200: "#bae6fd",
95
- 300: "#7dd3fc",
96
- 400: "#38bdf8",
97
- 500: "#0ea5e9",
98
- 600: "#0284c7",
99
- 700: "#0369a1",
100
- 800: "#075985",
101
- 900: "#0c4a6e"
102
- },
103
- cyan: {
104
- 50: "#ecfeff",
105
- 100: "#cffafe",
106
- 200: "#a5f3fc",
107
- 300: "#67e8f9",
108
- 400: "#22d3ee",
109
- 500: "#06b6d4",
110
- 600: "#0891b2",
111
- 700: "#0e7490",
112
- 800: "#155e75",
113
- 900: "#164e63"
114
- },
115
- teal: {
116
- 50: "#f0fdfa",
117
- 100: "#ccfbf1",
118
- 200: "#99f6e4",
119
- 300: "#5eead4",
120
- 400: "#2dd4bf",
121
- 500: "#14b8a6",
122
- 600: "#0d9488",
123
- 700: "#0f766e",
124
- 800: "#115e59",
125
- 900: "#134e4a"
126
- },
127
- emerald: {
128
- 50: "#ecfdf5",
129
- 100: "#d1fae5",
130
- 200: "#a7f3d0",
131
- 300: "#6ee7b7",
132
- 400: "#34d399",
133
- 500: "#10b981",
134
- 600: "#059669",
135
- 700: "#047857",
136
- 800: "#065f46",
137
- 900: "#064e3b"
138
- },
139
- green: {
140
- 50: "#f0fdf4",
141
- 100: "#dcfce7",
142
- 200: "#bbf7d0",
143
- 300: "#86efac",
144
- 400: "#4ade80",
145
- 500: "#22c55e",
146
- 600: "#16a34a",
147
- 700: "#15803d",
148
- 800: "#166534",
149
- 900: "#14532d"
150
- },
151
- lime: {
152
- 50: "#f7fee7",
153
- 100: "#ecfccb",
154
- 200: "#d9f99d",
155
- 300: "#bef264",
156
- 400: "#a3e635",
157
- 500: "#84cc16",
158
- 600: "#65a30d",
159
- 700: "#4d7c0f",
160
- 800: "#3f6212",
161
- 900: "#365314"
162
- },
163
- yellow: {
164
- 50: "#fefce8",
165
- 100: "#fef9c3",
166
- 200: "#fef08a",
167
- 300: "#fde047",
168
- 400: "#facc15",
169
- 500: "#eab308",
170
- 600: "#ca8a04",
171
- 700: "#a16207",
172
- 800: "#854d0e",
173
- 900: "#713f12"
174
- },
175
- amber: {
176
- 50: "#fffbeb",
177
- 100: "#fef3c7",
178
- 200: "#fde68a",
179
- 300: "#fcd34d",
180
- 400: "#fbbf24",
181
- 500: "#f59e0b",
182
- 600: "#d97706",
183
- 700: "#b45309",
184
- 800: "#92400e",
185
- 900: "#78350f"
186
- },
187
- orange: {
188
- 50: "#fff7ed",
189
- 100: "#ffedd5",
190
- 200: "#fed7aa",
191
- 300: "#fdba74",
192
- 400: "#fb923c",
193
- 500: "#f97316",
194
- 600: "#ea580c",
195
- 700: "#c2410c",
196
- 800: "#9a3412",
197
- 900: "#7c2d12"
198
- },
199
- red: {
200
- 50: "#fef2f2",
201
- 100: "#fee2e2",
202
- 200: "#fecaca",
203
- 300: "#fca5a5",
204
- 400: "#f87171",
205
- 500: "#ef4444",
206
- 600: "#dc2626",
207
- 700: "#b91c1c",
208
- 800: "#991b1b",
209
- 900: "#7f1d1d"
210
- },
211
- gray: {
212
- 50: "#f9fafb",
213
- 100: "#f3f4f6",
214
- 200: "#e5e7eb",
215
- 300: "#d1d5db",
216
- 400: "#9ca3af",
217
- 500: "#6b7280",
218
- 600: "#4b5563",
219
- 700: "#374151",
220
- 800: "#1f2937",
221
- 900: "#111827"
222
- },
223
- slate: {
224
- 50: "#f8fafc",
225
- 100: "#f1f5f9",
226
- 200: "#e2e8f0",
227
- 300: "#cbd5e1",
228
- 400: "#94a3b8",
229
- 500: "#64748b",
230
- 600: "#475569",
231
- 700: "#334155",
232
- 800: "#1e293b",
233
- 900: "#0f172a"
234
- },
235
- zinc: {
236
- 50: "#fafafa",
237
- 100: "#f4f4f5",
238
- 200: "#e4e4e7",
239
- 300: "#d4d4d8",
240
- 400: "#a1a1aa",
241
- 500: "#71717a",
242
- 600: "#52525b",
243
- 700: "#3f3f46",
244
- 800: "#27272a",
245
- 900: "#18181b"
246
- },
247
- neutral: {
248
- 50: "#fafafa",
249
- 100: "#f5f5f5",
250
- 200: "#e5e5e5",
251
- 300: "#d4d4d4",
252
- 400: "#a3a3a3",
253
- 500: "#737373",
254
- 600: "#525252",
255
- 700: "#404040",
256
- 800: "#262626",
257
- 900: "#171717"
258
- },
259
- stone: {
260
- 50: "#fafaf9",
261
- 100: "#f5f5f4",
262
- 200: "#e7e5e4",
263
- 300: "#d6d3d1",
264
- 400: "#a8a29e",
265
- 500: "#78716c",
266
- 600: "#57534e",
267
- 700: "#44403c",
268
- 800: "#292524",
269
- 900: "#1c1917"
270
- },
271
- light: {
272
- 50: "#fdfdfd",
273
- 100: "#fcfcfc",
274
- 200: "#fafafa",
275
- 300: "#f8f9fa",
276
- 400: "#f6f6f6",
277
- 500: "#f2f2f2",
278
- 600: "#f1f3f5",
279
- 700: "#e9ecef",
280
- 800: "#dee2e6",
281
- 900: "#dde1e3"
282
- },
283
- dark: {
284
- 50: "#4a4a4a",
285
- 100: "#3c3c3c",
286
- 200: "#323232",
287
- 300: "#2d2d2d",
288
- 400: "#222222",
289
- 500: "#1f1f1f",
290
- 600: "#1c1c1e",
291
- 700: "#1b1b1b",
292
- 800: "#181818",
293
- 900: "#0f0f0f"
294
- },
295
- get lightblue() {
296
- return this.sky;
297
- },
298
- get lightBlue() {
299
- return this.sky;
300
- },
301
- get warmgray() {
302
- return this.stone;
303
- },
304
- get warmGray() {
305
- return this.stone;
306
- },
307
- get truegray() {
308
- return this.neutral;
309
- },
310
- get trueGray() {
311
- return this.neutral;
312
- },
313
- get coolgray() {
314
- return this.gray;
315
- },
316
- get coolGray() {
317
- return this.gray;
318
- },
319
- get bluegray() {
320
- return this.slate;
321
- },
322
- get blueGray() {
323
- return this.slate;
324
- }
1
+ import { escapeSelector, createValueHandler, toArray, escapeRegExp } from '@unocss/core';
2
+
3
+ const directionMap = {
4
+ "l": ["-left"],
5
+ "r": ["-right"],
6
+ "t": ["-top"],
7
+ "b": ["-bottom"],
8
+ "s": ["-inline-start"],
9
+ "e": ["-inline-end"],
10
+ "x": ["-left", "-right"],
11
+ "y": ["-top", "-bottom"],
12
+ "": [""],
13
+ "bs": ["-block-start"],
14
+ "be": ["-block-end"],
15
+ "is": ["-inline-start"],
16
+ "ie": ["-inline-end"],
17
+ "block": ["-block-start", "-block-end"],
18
+ "inline": ["-inline-start", "-inline-end"]
19
+ };
20
+ const insetMap = {
21
+ ...directionMap,
22
+ s: ["-inset-inline-start"],
23
+ e: ["-inset-inline-end"],
24
+ bs: ["-inset-block-start"],
25
+ be: ["-inset-block-end"],
26
+ is: ["-inset-inline-start"],
27
+ ie: ["-inset-inline-end"],
28
+ block: ["-inset-block-start", "-inset-block-end"],
29
+ inline: ["-inset-inline-start", "-inset-inline-end"]
30
+ };
31
+ const cornerMap = {
32
+ "l": ["-top-left", "-bottom-left"],
33
+ "r": ["-top-right", "-bottom-right"],
34
+ "t": ["-top-left", "-top-right"],
35
+ "b": ["-bottom-left", "-bottom-right"],
36
+ "tl": ["-top-left"],
37
+ "lt": ["-top-left"],
38
+ "tr": ["-top-right"],
39
+ "rt": ["-top-right"],
40
+ "bl": ["-bottom-left"],
41
+ "lb": ["-bottom-left"],
42
+ "br": ["-bottom-right"],
43
+ "rb": ["-bottom-right"],
44
+ "": [""],
45
+ "bs": ["-start-start", "-start-end"],
46
+ "be": ["-end-start", "-end-end"],
47
+ "is": ["-end-start", "-start-start"],
48
+ "ie": ["-start-end", "-end-end"],
49
+ "bs-is": ["-start-start"],
50
+ "is-bs": ["-start-start"],
51
+ "bs-ie": ["-start-end"],
52
+ "ie-bs": ["-start-end"],
53
+ "be-is": ["-end-start"],
54
+ "is-be": ["-end-start"],
55
+ "be-ie": ["-end-end"],
56
+ "ie-be": ["-end-end"]
325
57
  };
326
- Object.values(colors).forEach((color) => {
327
- if (typeof color !== "string") {
328
- color.DEFAULT = color.DEFAULT || color[400];
329
- Object.keys(color).forEach((key) => {
330
- const short = +key / 100;
331
- if (short === Math.round(short))
332
- color[short] = color[key];
58
+ const xyzMap = {
59
+ "x": ["-x"],
60
+ "y": ["-y"],
61
+ "z": ["-z"],
62
+ "": ["-x", "-y"]
63
+ };
64
+ const basePositionMap = [
65
+ "top",
66
+ "top center",
67
+ "top left",
68
+ "top right",
69
+ "bottom",
70
+ "bottom center",
71
+ "bottom left",
72
+ "bottom right",
73
+ "left",
74
+ "left center",
75
+ "left top",
76
+ "left bottom",
77
+ "right",
78
+ "right center",
79
+ "right top",
80
+ "right bottom",
81
+ "center",
82
+ "center top",
83
+ "center bottom",
84
+ "center left",
85
+ "center right",
86
+ "center center"
87
+ ];
88
+ const positionMap = Object.assign(
89
+ {},
90
+ ...basePositionMap.map((p) => ({ [p.replace(/ /, "-")]: p })),
91
+ ...basePositionMap.map((p) => ({ [p.replace(/\b(\w)\w+/g, "$1").replace(/ /, "")]: p }))
92
+ );
93
+ const globalKeywords = [
94
+ "inherit",
95
+ "initial",
96
+ "revert",
97
+ "revert-layer",
98
+ "unset"
99
+ ];
100
+
101
+ const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax|cqw|cqh|cqi|cqb|cqmin|cqmax|rpx)?$/i;
102
+ const numberRE = /^(-?[0-9.]+)$/i;
103
+ const unitOnlyRE = /^(px)$/i;
104
+
105
+ const cssProps = [
106
+ "color",
107
+ "border-color",
108
+ "background-color",
109
+ "flex-grow",
110
+ "flex",
111
+ "flex-shrink",
112
+ "caret-color",
113
+ "font",
114
+ "gap",
115
+ "opacity",
116
+ "visibility",
117
+ "z-index",
118
+ "font-weight",
119
+ "zoom",
120
+ "text-shadow",
121
+ "transform",
122
+ "box-shadow",
123
+ "backround-position",
124
+ "left",
125
+ "right",
126
+ "top",
127
+ "bottom",
128
+ "object-position",
129
+ "max-height",
130
+ "min-height",
131
+ "max-width",
132
+ "min-width",
133
+ "height",
134
+ "width",
135
+ "border-width",
136
+ "margin",
137
+ "padding",
138
+ "outline-width",
139
+ "outline-offset",
140
+ "font-size",
141
+ "line-height",
142
+ "text-indent",
143
+ "vertical-align",
144
+ "border-spacing",
145
+ "letter-spacing",
146
+ "word-spacing",
147
+ "stroke",
148
+ "filter",
149
+ "backdrop-filter",
150
+ "fill",
151
+ "mask",
152
+ "mask-size",
153
+ "mask-border",
154
+ "clip-path",
155
+ "clip",
156
+ "border-radius"
157
+ ];
158
+ function round(n) {
159
+ return n.toFixed(10).replace(/\.0+$/, "").replace(/(\.\d+?)0+$/, "$1");
160
+ }
161
+ function numberWithUnit(str) {
162
+ const match = str.match(numberWithUnitRE);
163
+ if (!match)
164
+ return;
165
+ const [, n, unit] = match;
166
+ const num = parseFloat(n);
167
+ if (unit && !Number.isNaN(num))
168
+ return `${round(num)}${unit}`;
169
+ }
170
+ function auto(str) {
171
+ if (str === "auto" || str === "a")
172
+ return "auto";
173
+ }
174
+ function rem(str) {
175
+ if (str.match(unitOnlyRE))
176
+ return `1${str}`;
177
+ const match = str.match(numberWithUnitRE);
178
+ if (!match)
179
+ return;
180
+ const [, n, unit] = match;
181
+ const num = parseFloat(n);
182
+ if (!Number.isNaN(num))
183
+ return unit ? `${round(num)}${unit}` : `${round(num / 4)}rem`;
184
+ }
185
+ function px(str) {
186
+ if (str.match(unitOnlyRE))
187
+ return `1${str}`;
188
+ const match = str.match(numberWithUnitRE);
189
+ if (!match)
190
+ return;
191
+ const [, n, unit] = match;
192
+ const num = parseFloat(n);
193
+ if (!Number.isNaN(num))
194
+ return unit ? `${round(num)}${unit}` : `${round(num)}px`;
195
+ }
196
+ function number(str) {
197
+ if (!numberRE.test(str))
198
+ return;
199
+ const num = parseFloat(str);
200
+ if (!Number.isNaN(num))
201
+ return round(num);
202
+ }
203
+ function percent(str) {
204
+ if (str.endsWith("%"))
205
+ str = str.slice(0, -1);
206
+ const num = parseFloat(str);
207
+ if (!Number.isNaN(num))
208
+ return `${round(num / 100)}`;
209
+ }
210
+ function fraction(str) {
211
+ if (str === "full")
212
+ return "100%";
213
+ const [left, right] = str.split("/");
214
+ const num = parseFloat(left) / parseFloat(right);
215
+ if (!Number.isNaN(num))
216
+ return `${round(num * 100)}%`;
217
+ }
218
+ const bracketTypeRe = /^\[(color|length|position):/i;
219
+ function bracketWithType(str, type) {
220
+ if (str && str.startsWith("[") && str.endsWith("]")) {
221
+ let base;
222
+ const match = str.match(bracketTypeRe);
223
+ if (!match)
224
+ base = str.slice(1, -1);
225
+ else if (type && match[1] === type)
226
+ base = str.slice(match[0].length, -1);
227
+ if (!base)
228
+ return;
229
+ let curly = 0;
230
+ for (const i of base) {
231
+ if (i === "[") {
232
+ curly += 1;
233
+ } else if (i === "]") {
234
+ curly -= 1;
235
+ if (curly < 0)
236
+ return;
237
+ }
238
+ }
239
+ if (curly)
240
+ return;
241
+ return base.replace(/(url\(.*?\))/g, (v) => v.replace(/_/g, "\\_")).replace(/([^\\])_/g, "$1 ").replace(/(?:calc|clamp|max|min)\((.*)/g, (v) => {
242
+ return v.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ");
333
243
  });
334
244
  }
335
- });
245
+ }
246
+ function bracket(str) {
247
+ return bracketWithType(str);
248
+ }
249
+ function bracketOfColor(str) {
250
+ return bracketWithType(str, "color");
251
+ }
252
+ function bracketOfLength(str) {
253
+ return bracketWithType(str, "length");
254
+ }
255
+ function bracketOfPosition(str) {
256
+ return bracketWithType(str, "position");
257
+ }
258
+ function cssvar(str) {
259
+ if (str.match(/^\$\S/))
260
+ return `var(--${escapeSelector(str.slice(1))})`;
261
+ }
262
+ function time(str) {
263
+ const match = str.match(/^(-?[0-9.]+)(s|ms)?$/i);
264
+ if (!match)
265
+ return;
266
+ const [, n, unit] = match;
267
+ const num = parseFloat(n);
268
+ if (!Number.isNaN(num))
269
+ return unit ? `${round(num)}${unit}` : `${round(num)}ms`;
270
+ }
271
+ function degree(str) {
272
+ const match = str.match(/^(-?[0-9.]+)(deg|rad|grad|turn)?$/i);
273
+ if (!match)
274
+ return;
275
+ const [, n, unit] = match;
276
+ const num = parseFloat(n);
277
+ if (!Number.isNaN(num))
278
+ return unit ? `${round(num)}${unit}` : `${round(num)}deg`;
279
+ }
280
+ function global(str) {
281
+ if (globalKeywords.includes(str))
282
+ return str;
283
+ }
284
+ function properties(str) {
285
+ if (str.split(",").every((prop) => cssProps.includes(prop)))
286
+ return str;
287
+ }
288
+ function position(str) {
289
+ if (["top", "left", "right", "bottom", "center"].includes(str))
290
+ return str;
291
+ }
292
+
293
+ const valueHandlers = {
294
+ __proto__: null,
295
+ numberWithUnit: numberWithUnit,
296
+ auto: auto,
297
+ rem: rem,
298
+ px: px,
299
+ number: number,
300
+ percent: percent,
301
+ fraction: fraction,
302
+ bracket: bracket,
303
+ bracketOfColor: bracketOfColor,
304
+ bracketOfLength: bracketOfLength,
305
+ bracketOfPosition: bracketOfPosition,
306
+ cssvar: cssvar,
307
+ time: time,
308
+ degree: degree,
309
+ global: global,
310
+ properties: properties,
311
+ position: position
312
+ };
313
+
314
+ const handler = createValueHandler(valueHandlers);
315
+ const h = handler;
316
+
317
+ const CONTROL_MINI_NO_NEGATIVE = "$$mini-no-negative";
318
+ function directionSize(propertyPrefix) {
319
+ return ([_, direction, size], { theme }) => {
320
+ const v = theme.spacing?.[size || "DEFAULT"] ?? handler.bracket.cssvar.global.auto.fraction.rem(size);
321
+ if (v != null)
322
+ return directionMap[direction].map((i) => [`${propertyPrefix}${i}`, v]);
323
+ };
324
+ }
325
+ function getThemeColor(theme, colors) {
326
+ let obj = theme.colors;
327
+ let index = -1;
328
+ for (const c of colors) {
329
+ index += 1;
330
+ if (obj && typeof obj !== "string") {
331
+ const camel = colors.slice(index).join("-").replace(/(-[a-z])/g, (n) => n.slice(1).toUpperCase());
332
+ if (obj[camel])
333
+ return obj[camel];
334
+ if (obj[c]) {
335
+ obj = obj[c];
336
+ continue;
337
+ }
338
+ }
339
+ return void 0;
340
+ }
341
+ return obj;
342
+ }
343
+ function parseColor$1(body, theme) {
344
+ const split = body.split(/(?:\/|:)/);
345
+ let main, opacity;
346
+ if (split[0] === "[color") {
347
+ main = split.slice(0, 2).join(":");
348
+ opacity = split[2];
349
+ } else {
350
+ [main, opacity] = split;
351
+ }
352
+ const colors = main.replace(/([a-z])([0-9])/g, "$1-$2").split(/-/g);
353
+ const [name] = colors;
354
+ if (!name)
355
+ return;
356
+ let color;
357
+ const bracket = handler.bracketOfColor(main);
358
+ const bracketOrMain = bracket || main;
359
+ if (bracketOrMain.match(/^#[\da-fA-F]+/g))
360
+ color = bracketOrMain;
361
+ else if (bracketOrMain.match(/^hex-[\da-fA-F]+/g))
362
+ color = `#${bracketOrMain.slice(4)}`;
363
+ else if (main.startsWith("$"))
364
+ color = handler.cssvar(main);
365
+ color = color || bracket;
366
+ let no = "DEFAULT";
367
+ if (!color) {
368
+ let colorData;
369
+ const [scale] = colors.slice(-1);
370
+ if (scale.match(/^\d+$/)) {
371
+ no = scale;
372
+ colorData = getThemeColor(theme, colors.slice(0, -1));
373
+ if (!colorData || typeof colorData === "string")
374
+ color = void 0;
375
+ else
376
+ color = colorData[no];
377
+ } else {
378
+ colorData = getThemeColor(theme, colors);
379
+ if (!colorData && colors.length <= 2) {
380
+ [, no = no] = colors;
381
+ colorData = getThemeColor(theme, [name]);
382
+ }
383
+ if (typeof colorData === "string")
384
+ color = colorData;
385
+ else if (no && colorData)
386
+ color = colorData[no];
387
+ }
388
+ }
389
+ return {
390
+ opacity,
391
+ name,
392
+ no,
393
+ color,
394
+ cssColor: parseCssColor(color),
395
+ alpha: handler.bracket.cssvar.percent(opacity ?? "")
396
+ };
397
+ }
398
+ function colorResolver(property, varName, shouldPass) {
399
+ return ([, body], { theme }) => {
400
+ const data = parseColor$1(body, theme);
401
+ if (!data)
402
+ return;
403
+ const { alpha, color, cssColor } = data;
404
+ const css = {};
405
+ if (cssColor) {
406
+ if (alpha != null) {
407
+ css[property] = colorToString(cssColor, alpha);
408
+ } else {
409
+ css[`--un-${varName}-opacity`] = colorOpacityToString(cssColor);
410
+ css[property] = colorToString(cssColor, `var(--un-${varName}-opacity)`);
411
+ }
412
+ } else if (color) {
413
+ css[property] = colorToString(color, alpha);
414
+ }
415
+ if (shouldPass?.(css) !== false)
416
+ return css;
417
+ };
418
+ }
419
+ function colorableShadows(shadows, colorVar) {
420
+ const colored = [];
421
+ shadows = toArray(shadows);
422
+ for (let i = 0; i < shadows.length; i++) {
423
+ const components = getComponents(shadows[i], " ", 6);
424
+ if (!components || components.length < 3)
425
+ return shadows;
426
+ const color = parseCssColor(components.pop());
427
+ if (color == null)
428
+ return shadows;
429
+ colored.push(`${components.join(" ")} var(${colorVar}, ${colorToString(color)})`);
430
+ }
431
+ return colored;
432
+ }
433
+ function hasParseableColor(color, theme) {
434
+ return color != null && !!parseColor$1(color, theme)?.color;
435
+ }
436
+ function resolveBreakpoints({ theme, generator }) {
437
+ let breakpoints;
438
+ if (generator.userConfig && generator.userConfig.theme)
439
+ breakpoints = generator.userConfig.theme.breakpoints;
440
+ if (!breakpoints)
441
+ breakpoints = theme.breakpoints;
442
+ return breakpoints;
443
+ }
444
+ function resolveVerticalBreakpoints({ theme, generator }) {
445
+ let verticalBreakpoints;
446
+ if (generator.userConfig && generator.userConfig.theme)
447
+ verticalBreakpoints = generator.userConfig.theme.verticalBreakpoints;
448
+ if (!verticalBreakpoints)
449
+ verticalBreakpoints = theme.verticalBreakpoints;
450
+ return verticalBreakpoints;
451
+ }
452
+ function makeGlobalStaticRules(prefix, property) {
453
+ return globalKeywords.map((keyword) => [`${prefix}-${keyword}`, { [property ?? prefix]: keyword }]);
454
+ }
455
+ function getComponent(str, open, close, separator) {
456
+ if (str === "")
457
+ return;
458
+ const l = str.length;
459
+ let parenthesis = 0;
460
+ for (let i = 0; i < l; i++) {
461
+ switch (str[i]) {
462
+ case open:
463
+ parenthesis++;
464
+ break;
465
+ case close:
466
+ if (--parenthesis < 0)
467
+ return;
468
+ break;
469
+ case separator:
470
+ if (parenthesis === 0) {
471
+ if (i === 0 || i === l - 1)
472
+ return;
473
+ return [
474
+ str.slice(0, i),
475
+ str.slice(i + 1)
476
+ ];
477
+ }
478
+ }
479
+ }
480
+ return [
481
+ str,
482
+ ""
483
+ ];
484
+ }
485
+ function getComponents(str, separator, limit) {
486
+ if (separator.length !== 1)
487
+ return;
488
+ limit = limit ?? 10;
489
+ const components = [];
490
+ let i = 0;
491
+ while (str !== "") {
492
+ if (++i > limit)
493
+ return;
494
+ const componentPair = getComponent(str, "(", ")", separator);
495
+ if (!componentPair)
496
+ return;
497
+ const [component, rest] = componentPair;
498
+ components.push(component);
499
+ str = rest;
500
+ }
501
+ if (components.length > 0)
502
+ return components;
503
+ }
504
+
505
+ const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
506
+ const alphaPlaceholders = ["%alpha", "<alpha-value>"];
507
+ const alphaPlaceholdersRE = new RegExp(alphaPlaceholders.map((v) => escapeRegExp(v)).join("|"));
508
+ function hex2rgba(hex = "") {
509
+ const color = parseHexColor(hex);
510
+ if (color != null) {
511
+ const { components, alpha } = color;
512
+ if (alpha == null)
513
+ return components;
514
+ return [...components, alpha];
515
+ }
516
+ }
517
+ function parseCssColor(str = "") {
518
+ const color = parseColor(str);
519
+ if (color == null || color === false)
520
+ return;
521
+ const { type: casedType, components, alpha } = color;
522
+ const type = casedType.toLowerCase();
523
+ if (components.length === 0)
524
+ return;
525
+ if (["rgba", "hsla"].includes(type) && alpha == null)
526
+ return;
527
+ if (cssColorFunctions.includes(type) && ![1, 3].includes(components.length))
528
+ return;
529
+ return {
530
+ type,
531
+ components: components.map((c) => typeof c === "string" ? c.trim() : c),
532
+ alpha: typeof alpha === "string" ? alpha.trim() : alpha
533
+ };
534
+ }
535
+ function colorOpacityToString(color) {
536
+ const alpha = color.alpha ?? 1;
537
+ return typeof alpha === "string" && alphaPlaceholders.includes(alpha) ? 1 : alpha;
538
+ }
539
+ function colorToString(color, alphaOverride) {
540
+ if (typeof color === "string")
541
+ return color.replace(alphaPlaceholdersRE, `${alphaOverride ?? 1}`);
542
+ const { components } = color;
543
+ let { alpha, type } = color;
544
+ alpha = alphaOverride ?? alpha;
545
+ type = type.toLowerCase();
546
+ if (["hsla", "hsl", "rgba", "rgb"].includes(type))
547
+ return `${type.replace("a", "")}a(${components.join(",")}${alpha == null ? "" : `,${alpha}`})`;
548
+ alpha = alpha == null ? "" : ` / ${alpha}`;
549
+ if (cssColorFunctions.includes(type))
550
+ return `${type}(${components.join(" ")}${alpha})`;
551
+ return `color(${type} ${components.join(" ")}${alpha})`;
552
+ }
553
+ function parseColor(str) {
554
+ if (!str)
555
+ return;
556
+ let color = parseHexColor(str);
557
+ if (color != null)
558
+ return color;
559
+ color = cssColorKeyword(str);
560
+ if (color != null)
561
+ return color;
562
+ color = parseCssCommaColorFunction(str);
563
+ if (color != null)
564
+ return color;
565
+ color = parseCssSpaceColorFunction(str);
566
+ if (color != null)
567
+ return color;
568
+ color = parseCssColorFunction(str);
569
+ if (color != null)
570
+ return color;
571
+ }
572
+ function parseHexColor(str) {
573
+ const [, body] = str.match(/^#([\da-f]+)$/i) || [];
574
+ if (!body)
575
+ return;
576
+ switch (body.length) {
577
+ case 3:
578
+ case 4:
579
+ const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
580
+ return {
581
+ type: "rgb",
582
+ components: digits.slice(0, 3),
583
+ alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
584
+ };
585
+ case 6:
586
+ case 8:
587
+ const value = Number.parseInt(body, 16);
588
+ return {
589
+ type: "rgb",
590
+ components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
591
+ alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
592
+ };
593
+ }
594
+ }
595
+ function cssColorKeyword(str) {
596
+ const color = {
597
+ rebeccapurple: [102, 51, 153, 1]
598
+ }[str];
599
+ if (color != null) {
600
+ return {
601
+ type: "rgb",
602
+ components: color.slice(0, 3),
603
+ alpha: color[3]
604
+ };
605
+ }
606
+ }
607
+ function parseCssCommaColorFunction(color) {
608
+ const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
609
+ if (!match)
610
+ return;
611
+ const [, type, componentString] = match;
612
+ const components = getComponents(componentString, ",", 5);
613
+ if (components) {
614
+ if ([3, 4].includes(components.length)) {
615
+ return {
616
+ type,
617
+ components: components.slice(0, 3),
618
+ alpha: components[3]
619
+ };
620
+ } else if (components.length !== 1) {
621
+ return false;
622
+ }
623
+ }
624
+ }
625
+ const cssColorFunctionsRe = new RegExp(`^(${cssColorFunctions.join("|")})\\((.+)\\)$`, "i");
626
+ function parseCssSpaceColorFunction(color) {
627
+ const match = color.match(cssColorFunctionsRe);
628
+ if (!match)
629
+ return;
630
+ const [, fn, componentString] = match;
631
+ const parsed = parseCssSpaceColorValues(`${fn} ${componentString}`);
632
+ if (parsed) {
633
+ const { alpha, components: [type, ...components] } = parsed;
634
+ return {
635
+ type,
636
+ components,
637
+ alpha
638
+ };
639
+ }
640
+ }
641
+ function parseCssColorFunction(color) {
642
+ const match = color.match(/^color\((.+)\)$/);
643
+ if (!match)
644
+ return;
645
+ const parsed = parseCssSpaceColorValues(match[1]);
646
+ if (parsed) {
647
+ const { alpha, components: [type, ...components] } = parsed;
648
+ return {
649
+ type,
650
+ components,
651
+ alpha
652
+ };
653
+ }
654
+ }
655
+ function parseCssSpaceColorValues(componentString) {
656
+ const components = getComponents(componentString, " ");
657
+ if (!components)
658
+ return;
659
+ let totalComponents = components.length;
660
+ if (components[totalComponents - 2] === "/") {
661
+ return {
662
+ components: components.slice(0, totalComponents - 2),
663
+ alpha: components[totalComponents - 1]
664
+ };
665
+ }
666
+ if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
667
+ const removed = components.splice(totalComponents - 2);
668
+ components.push(removed.join(" "));
669
+ --totalComponents;
670
+ }
671
+ const withAlpha = getComponents(components[totalComponents - 1], "/", 2);
672
+ if (!withAlpha)
673
+ return;
674
+ if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "")
675
+ return { components };
676
+ const alpha = withAlpha.pop();
677
+ components[totalComponents - 1] = withAlpha.join("/");
678
+ return {
679
+ components,
680
+ alpha
681
+ };
682
+ }
336
683
 
337
- export { colors as c };
684
+ export { CONTROL_MINI_NO_NEGATIVE as C, hasParseableColor as a, cornerMap as b, colorResolver as c, directionMap as d, colorToString as e, colorOpacityToString as f, globalKeywords as g, handler as h, colorableShadows as i, insetMap as j, positionMap as k, resolveBreakpoints as l, makeGlobalStaticRules as m, numberWithUnitRE as n, directionSize as o, parseColor$1 as p, getComponent as q, resolveVerticalBreakpoints as r, hex2rgba as s, parseCssColor as t, h as u, valueHandlers as v, getComponents as w, xyzMap as x };