@vinicunca/unocss-preset 0.0.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/antfu>
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.
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ function masonryGridPolyfill(selectors = ".masonry-grid") {
4
+ const elements = [...document.querySelectorAll(selectors)];
5
+ if (!elements.length) {
6
+ return;
7
+ }
8
+ if (getComputedStyle(elements[0]).gridTemplateRows === "masonry") {
9
+ return;
10
+ }
11
+ for (const el of elements) {
12
+ const grid = {
13
+ el,
14
+ items: [...el.childNodes].filter((i) => i.nodeType === 1),
15
+ gap: parseFloat(getComputedStyle(el).rowGap),
16
+ columns: 0,
17
+ count: 0
18
+ };
19
+ renderGrid(grid);
20
+ const resizeObserver = new ResizeObserver(() => renderGrid(grid));
21
+ resizeObserver.observe(grid.el);
22
+ }
23
+ }
24
+ function renderGrid(grid) {
25
+ const columns = getComputedStyle(grid.el).gridTemplateColumns.split(" ").length;
26
+ for (const column of grid.items) {
27
+ const { height } = column.getBoundingClientRect();
28
+ const h = height.toString();
29
+ if (h !== column.dataset?.h) {
30
+ column.dataset.h = h;
31
+ grid.count++;
32
+ }
33
+ }
34
+ if (grid.columns === columns && grid.count) {
35
+ return;
36
+ }
37
+ grid.columns = columns;
38
+ for (const { style } of grid.items) {
39
+ style.removeProperty("margin-top");
40
+ }
41
+ if (grid.columns > 1) {
42
+ for (const [index, column] of grid.items.slice(columns).entries()) {
43
+ const { bottom: prevBottom } = grid.items[index].getBoundingClientRect();
44
+ const { top } = column.getBoundingClientRect();
45
+ column.style.marginTop = `${prevBottom + grid.gap - top}px`;
46
+ }
47
+ }
48
+ grid.count = 0;
49
+ }
50
+
51
+ exports.masonryGridPolyfill = masonryGridPolyfill;
@@ -0,0 +1,10 @@
1
+ interface GridInstance {
2
+ el: HTMLElement;
3
+ items: HTMLElement[];
4
+ gap: number;
5
+ columns: number;
6
+ count: number;
7
+ }
8
+ declare function masonryGridPolyfill(selectors?: string): void;
9
+
10
+ export { GridInstance, masonryGridPolyfill };
@@ -0,0 +1,49 @@
1
+ function masonryGridPolyfill(selectors = ".masonry-grid") {
2
+ const elements = [...document.querySelectorAll(selectors)];
3
+ if (!elements.length) {
4
+ return;
5
+ }
6
+ if (getComputedStyle(elements[0]).gridTemplateRows === "masonry") {
7
+ return;
8
+ }
9
+ for (const el of elements) {
10
+ const grid = {
11
+ el,
12
+ items: [...el.childNodes].filter((i) => i.nodeType === 1),
13
+ gap: parseFloat(getComputedStyle(el).rowGap),
14
+ columns: 0,
15
+ count: 0
16
+ };
17
+ renderGrid(grid);
18
+ const resizeObserver = new ResizeObserver(() => renderGrid(grid));
19
+ resizeObserver.observe(grid.el);
20
+ }
21
+ }
22
+ function renderGrid(grid) {
23
+ const columns = getComputedStyle(grid.el).gridTemplateColumns.split(" ").length;
24
+ for (const column of grid.items) {
25
+ const { height } = column.getBoundingClientRect();
26
+ const h = height.toString();
27
+ if (h !== column.dataset?.h) {
28
+ column.dataset.h = h;
29
+ grid.count++;
30
+ }
31
+ }
32
+ if (grid.columns === columns && grid.count) {
33
+ return;
34
+ }
35
+ grid.columns = columns;
36
+ for (const { style } of grid.items) {
37
+ style.removeProperty("margin-top");
38
+ }
39
+ if (grid.columns > 1) {
40
+ for (const [index, column] of grid.items.slice(columns).entries()) {
41
+ const { bottom: prevBottom } = grid.items[index].getBoundingClientRect();
42
+ const { top } = column.getBoundingClientRect();
43
+ column.style.marginTop = `${prevBottom + grid.gap - top}px`;
44
+ }
45
+ }
46
+ grid.count = 0;
47
+ }
48
+
49
+ export { masonryGridPolyfill };
package/dist/index.cjs ADDED
@@ -0,0 +1,556 @@
1
+ 'use strict';
2
+
3
+ const jsUtilities = require('@vinicunca/js-utilities');
4
+ const core = require('@unocss/core');
5
+ const presetMini = require('@unocss/preset-mini');
6
+ const unocss = require('unocss');
7
+
8
+ const DEFAULT_PREFIX = "vin-";
9
+ class PresetCore {
10
+ constructor(options) {
11
+ this.prefix = options.prefix ?? "";
12
+ this.colorKeys = options.colorKeys ?? [];
13
+ }
14
+ genVariable(key = "") {
15
+ return `--${this.prefix}${key}`;
16
+ }
17
+ remapVariables({ tokens, key = "" }) {
18
+ return Object.keys(tokens).reduce((prev, acc) => {
19
+ const _key = `${this.genVariable(key)}${jsUtilities.toKebabCase(acc)}`;
20
+ prev[_key] = tokens[acc];
21
+ return prev;
22
+ }, {});
23
+ }
24
+ getColorKeys() {
25
+ return Array.from(new Set(this.colorKeys));
26
+ }
27
+ }
28
+
29
+ class Color extends PresetCore {
30
+ constructor(options) {
31
+ super(options);
32
+ }
33
+ getRules() {
34
+ return [
35
+ this.getTextRule(),
36
+ this.getBgRule()
37
+ ];
38
+ }
39
+ getTextRule() {
40
+ return [
41
+ /^text-(?<body>(?:on-)?(?<color>.+))/,
42
+ ({ groups }) => {
43
+ const { body, color } = groups;
44
+ if (!this.getColorKeys().includes(color)) {
45
+ return;
46
+ }
47
+ const colorBody = /^on-[a-z]/.test(body) ? `on-${color}` : color;
48
+ const colorVar = this.genVariable(`theme-${colorBody}`);
49
+ return {
50
+ "--un-color-opacity": 1,
51
+ "color": `rgba(var(${colorVar}), var(--un-color-opacity))`
52
+ };
53
+ },
54
+ { layer: "vinicunca" }
55
+ ];
56
+ }
57
+ getBgRule() {
58
+ return [
59
+ /^bg-(.+)$/,
60
+ ([, body]) => {
61
+ if (!this.colorKeys.includes(body)) {
62
+ return;
63
+ }
64
+ const bgColorVar = this.genVariable(`theme-${body}`);
65
+ const colorVar = this.genVariable(`theme-on-${body}`);
66
+ return {
67
+ "--un-color-opacity": 1,
68
+ "--un-bg-opacity": 1,
69
+ "background-color": `rgba(var(${bgColorVar}),var(--un-bg-opacity))`,
70
+ "color": `rgba(var(${colorVar}), var(--un-color-opacity))`
71
+ };
72
+ },
73
+ { layer: "vinicunca" }
74
+ ];
75
+ }
76
+ }
77
+
78
+ const COLOR_RING_OFFSET = "rgba(0, 0, 0, 0.2)";
79
+ const COLOR_RING_SHADOW = "rgba(0, 0, 0, 0.14)";
80
+ const COLOR_SHADOW = "rgba(0, 0, 0, 0.12)";
81
+ const ELEVATION_DICTIONARY = {
82
+ 0: [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
83
+ 1: [[0, 2, 1, -1], [0, 1, 1, 0], [0, 1, 3, 0]],
84
+ 2: [[0, 3, 1, -2], [0, 2, 2, 0], [0, 1, 5, 0]],
85
+ 3: [[0, 3, 3, -2], [0, 3, 4, 0], [0, 1, 8, 0]],
86
+ 4: [[0, 2, 4, -1], [0, 4, 5, 0], [0, 1, 10, 0]],
87
+ 5: [[0, 3, 5, -1], [0, 5, 8, 0], [0, 1, 14, 0]],
88
+ 6: [[0, 3, 5, -1], [0, 6, 10, 0], [0, 1, 18, 0]],
89
+ 7: [[0, 4, 5, -2], [0, 7, 10, 1], [0, 2, 16, 1]],
90
+ 8: [[0, 5, 5, -3], [0, 8, 10, 1], [0, 3, 14, 2]],
91
+ 9: [[0, 5, 6, -3], [0, 9, 12, 1], [0, 3, 16, 2]],
92
+ 10: [[0, 6, 6, -3], [0, 10, 14, 1], [0, 4, 18, 3]],
93
+ 11: [[0, 6, 7, -4], [0, 11, 15, 1], [0, 4, 20, 3]],
94
+ 12: [[0, 7, 8, -4], [0, 12, 17, 2], [0, 5, 22, 4]],
95
+ 13: [[0, 7, 8, -4], [0, 13, 19, 2], [0, 5, 24, 4]],
96
+ 14: [[0, 7, 9, -4], [0, 14, 21, 2], [0, 5, 26, 4]],
97
+ 15: [[0, 8, 9, -5], [0, 15, 22, 2], [0, 6, 28, 5]],
98
+ 16: [[0, 8, 10, -5], [0, 16, 24, 2], [0, 6, 30, 5]],
99
+ 17: [[0, 8, 11, -5], [0, 17, 26, 2], [0, 6, 32, 5]],
100
+ 18: [[0, 9, 11, -5], [0, 18, 28, 2], [0, 7, 34, 6]],
101
+ 19: [[0, 9, 12, -6], [0, 19, 29, 2], [0, 7, 36, 6]],
102
+ 20: [[0, 1, 13, -6], [0, 20, 31, 3], [0, 8, 38, 7]],
103
+ 21: [[0, 1, 13, -6], [0, 21, 33, 3], [0, 8, 40, 7]],
104
+ 22: [[0, 1, 14, -6], [0, 22, 35, 3], [0, 8, 42, 7]],
105
+ 23: [[0, 1, 14, -7], [0, 23, 36, 3], [0, 9, 44, 8]],
106
+ 24: [[0, 1, 15, -7], [0, 24, 38, 3], [0, 9, 46, 8]]
107
+ };
108
+ class Elevation {
109
+ getRules() {
110
+ return [
111
+ this.getBaseRule()
112
+ ];
113
+ }
114
+ addPixels(value) {
115
+ return value.map((v) => jsUtilities.convertToUnit(v)).join(" ");
116
+ }
117
+ getBaseRule() {
118
+ return [
119
+ /^elevation-([\d.]+)$/,
120
+ ([, body]) => {
121
+ const elevation = ELEVATION_DICTIONARY[body];
122
+ if (!elevation) {
123
+ return;
124
+ }
125
+ const [ringOffset, ringShadow, shadow] = elevation;
126
+ const unRingOffsetShadow = this.addPixels(ringOffset);
127
+ const unRingShadow = this.addPixels(ringShadow);
128
+ const unShadow = this.addPixels(shadow);
129
+ return {
130
+ "--un-ring-offset-shadow": `${unRingOffsetShadow} ${COLOR_RING_OFFSET}`,
131
+ "--un-ring-shadow": `${unRingShadow} ${COLOR_RING_SHADOW}`,
132
+ "--un-shadow": `${unShadow} ${COLOR_SHADOW}`,
133
+ "box-shadow": "var(--un-ring-offset-shadow), var(--un-ring-shadow), var(--un-shadow)"
134
+ };
135
+ },
136
+ { layer: "vinicunca" }
137
+ ];
138
+ }
139
+ }
140
+
141
+ const DEFAULT_THEME = {
142
+ light: {
143
+ dark: false,
144
+ colors: {
145
+ "background": "#FFFFFF",
146
+ "invert": "#000000",
147
+ "surface": "#FFFFFF",
148
+ "surface-variant": "#424242",
149
+ "on-surface-variant": "#EEEEEE",
150
+ "primary": "#1976D2",
151
+ "secondary": "#9c27b0",
152
+ "error": "#d32f2f",
153
+ "info": "#0288d1",
154
+ "success": "#2e7d32",
155
+ "warning": "#ed6c02"
156
+ },
157
+ variables: {
158
+ "border-color": "#000000",
159
+ "border-opacity": 0.12,
160
+ "high-emphasis-opacity": 0.87,
161
+ "medium-emphasis-opacity": 0.6,
162
+ "disabled-opacity": 0.38,
163
+ "idle-opacity": 0.04,
164
+ "hover-opacity": 0.04,
165
+ "focus-opacity": 0.12,
166
+ "selected-opacity": 0.08,
167
+ "activated-opacity": 0.12,
168
+ "pressed-opacity": 0.12,
169
+ "dragged-opacity": 0.08
170
+ }
171
+ },
172
+ dark: {
173
+ dark: true,
174
+ colors: {
175
+ "background": "#121212",
176
+ "invert": "#FFFFFF",
177
+ "surface": "#212121",
178
+ "surface-variant": "#BDBDBD",
179
+ "on-surface-variant": "#424242",
180
+ "primary": "#1565C0",
181
+ "secondary": "#7b1fa2",
182
+ "error": "#c62828",
183
+ "info": "#01579b",
184
+ "success": "#1b5e20",
185
+ "warning": "#e65100"
186
+ },
187
+ variables: {
188
+ "border-color": "#FFFFFF",
189
+ "border-opacity": 0.12,
190
+ "high-emphasis-opacity": 0.87,
191
+ "medium-emphasis-opacity": 0.6,
192
+ "disabled-opacity": 0.38,
193
+ "idle-opacity": 0.1,
194
+ "hover-opacity": 0.04,
195
+ "focus-opacity": 0.12,
196
+ "selected-opacity": 0.08,
197
+ "activated-opacity": 0.12,
198
+ "pressed-opacity": 0.16,
199
+ "dragged-opacity": 0.08
200
+ }
201
+ }
202
+ };
203
+
204
+ function createCssSelector({ selector, content }) {
205
+ return `${selector} { ${content.join(" ")} }`;
206
+ }
207
+
208
+ function generateRGBs(colors) {
209
+ const theme = {};
210
+ for (const color of Object.keys(colors)) {
211
+ let colorKey = color;
212
+ if (/^on-[a-z]/.test(color)) {
213
+ colorKey = jsUtilities.toCamelCase(color);
214
+ }
215
+ const data = presetMini.parseColor(color, {
216
+ colors: {
217
+ [colorKey]: colors[color]
218
+ }
219
+ });
220
+ if (data?.cssColor?.components) {
221
+ const colorValue = data.cssColor.components.join(",");
222
+ theme[color] = colorValue;
223
+ }
224
+ }
225
+ return theme;
226
+ }
227
+ function colorToInt(color) {
228
+ let rgb;
229
+ if (typeof color === "number") {
230
+ rgb = color;
231
+ } else if (typeof color === "string") {
232
+ let c = color.startsWith("#") ? color.substring(1) : color;
233
+ if (c.length === 3) {
234
+ c = c.split("").map((char) => char + char).join("");
235
+ }
236
+ if (c.length !== 6 && c.length !== 8) {
237
+ console.warn(`'${color}' is not a valid rgb color`);
238
+ }
239
+ rgb = parseInt(c, 16);
240
+ } else {
241
+ throw new TypeError(`Colors can only be numbers or strings, recieved ${color == null ? color : color.constructor.name} instead`);
242
+ }
243
+ if (rgb < 0) {
244
+ console.warn(`Colors cannot be negative: '${color}'`);
245
+ rgb = 0;
246
+ } else if (rgb > 4294967295 || isNaN(rgb)) {
247
+ console.warn(`'${color}' is not a valid rgb color`);
248
+ rgb = 16777215;
249
+ }
250
+ return rgb;
251
+ }
252
+
253
+ const mainTRC = 2.4;
254
+ const Rco = 0.2126729;
255
+ const Gco = 0.7151522;
256
+ const Bco = 0.072175;
257
+ const normBG = 0.55;
258
+ const normTXT = 0.58;
259
+ const revTXT = 0.57;
260
+ const revBG = 0.62;
261
+ const blkThrs = 0.03;
262
+ const blkClmp = 1.45;
263
+ const deltaYmin = 5e-4;
264
+ const scaleBoW = 1.25;
265
+ const scaleWoB = 1.25;
266
+ const loConThresh = 0.078;
267
+ const loConFactor = 12.82051282051282;
268
+ const loConOffset = 0.06;
269
+ const loClip = 1e-3;
270
+ function APCAcontrast(text, background) {
271
+ const Rtxt = ((text >> 16 & 255) / 255) ** mainTRC;
272
+ const Gtxt = ((text >> 8 & 255) / 255) ** mainTRC;
273
+ const Btxt = ((text >> 0 & 255) / 255) ** mainTRC;
274
+ const Rbg = ((background >> 16 & 255) / 255) ** mainTRC;
275
+ const Gbg = ((background >> 8 & 255) / 255) ** mainTRC;
276
+ const Bbg = ((background >> 0 & 255) / 255) ** mainTRC;
277
+ let Ytxt = Rtxt * Rco + Gtxt * Gco + Btxt * Bco;
278
+ let Ybg = Rbg * Rco + Gbg * Gco + Bbg * Bco;
279
+ if (Ytxt <= blkThrs) {
280
+ Ytxt += (blkThrs - Ytxt) ** blkClmp;
281
+ }
282
+ if (Ybg <= blkThrs) {
283
+ Ybg += (blkThrs - Ybg) ** blkClmp;
284
+ }
285
+ if (Math.abs(Ybg - Ytxt) < deltaYmin) {
286
+ return 0;
287
+ }
288
+ let outputContrast;
289
+ if (Ybg > Ytxt) {
290
+ const SAPC = (Ybg ** normBG - Ytxt ** normTXT) * scaleBoW;
291
+ outputContrast = SAPC < loClip ? 0 : SAPC < loConThresh ? SAPC - SAPC * loConFactor * loConOffset : SAPC - loConOffset;
292
+ } else {
293
+ const SAPC = (Ybg ** revBG - Ytxt ** revTXT) * scaleWoB;
294
+ outputContrast = SAPC > -loClip ? 0 : SAPC > -loConThresh ? SAPC - SAPC * loConFactor * loConOffset : SAPC + loConOffset;
295
+ }
296
+ return outputContrast * 100;
297
+ }
298
+
299
+ class Theme extends PresetCore {
300
+ constructor(options) {
301
+ super(options);
302
+ const parsedOptions = this.parseThemeOptions(options?.themes);
303
+ this.themes = this.parseTheme(parsedOptions);
304
+ this.preflights = options?.preflights ?? {};
305
+ }
306
+ getPreflight() {
307
+ return {
308
+ layer: "preflight",
309
+ getCSS: () => {
310
+ const lines = [];
311
+ lines.push(createCssSelector({
312
+ selector: "root:",
313
+ content: [
314
+ core.entriesToCss(Object.entries(this.remapVariables({ tokens: this.preflights })))
315
+ ]
316
+ }));
317
+ return lines.join("");
318
+ }
319
+ };
320
+ }
321
+ getRules() {
322
+ return [
323
+ this.getVariablesRule()
324
+ ];
325
+ }
326
+ parseThemeOptions(options) {
327
+ if (!options) {
328
+ return DEFAULT_THEME;
329
+ }
330
+ return jsUtilities.mergeDeep(
331
+ DEFAULT_THEME,
332
+ { ...options }
333
+ );
334
+ }
335
+ parseTheme(_themes) {
336
+ const acc = {};
337
+ for (const [name, original] of Object.entries(_themes)) {
338
+ const theme = acc[name] = {
339
+ ...original,
340
+ colors: {
341
+ ...original.colors
342
+ }
343
+ };
344
+ for (const color of Object.keys(theme.colors)) {
345
+ if (/^on-[a-z]/.test(color) || theme.colors[`on-${color}`]) {
346
+ continue;
347
+ }
348
+ const onColor = `on-${color}`;
349
+ const colorValue = colorToInt(theme.colors[color]);
350
+ const blackContrast = Math.abs(APCAcontrast(0, colorValue));
351
+ const whiteContrast = Math.abs(APCAcontrast(16777215, colorValue));
352
+ theme.colors[onColor] = whiteContrast > Math.min(blackContrast, 50) ? "#fff" : "#000";
353
+ this.colorKeys.push(color);
354
+ }
355
+ }
356
+ return acc;
357
+ }
358
+ getVariablesRule() {
359
+ return [
360
+ new RegExp(`^theme-(?<name>${Object.keys(this.themes).join("|")})$`),
361
+ ({ groups }) => {
362
+ if (!groups?.name) {
363
+ return {};
364
+ }
365
+ const themeName = this.themes[groups.name];
366
+ const themeColors = themeName.colors ?? {};
367
+ const rgbs = generateRGBs(themeColors);
368
+ return {
369
+ "color-scheme": themeName.dark ? "dark" : "light",
370
+ ...this.remapVariables({ tokens: rgbs, key: "theme-" }),
371
+ ...this.remapVariables({ tokens: themeName.variables })
372
+ };
373
+ },
374
+ { layer: "vinicunca" }
375
+ ];
376
+ }
377
+ }
378
+
379
+ class Button extends PresetCore {
380
+ constructor(options) {
381
+ super(options);
382
+ this.sizes = options.sizes ?? {};
383
+ this.variants = options.variants ?? {};
384
+ }
385
+ transformClass(content) {
386
+ const reSize = new RegExp(`(${Object.keys(this.sizes).join("|")})`);
387
+ return content.replace(
388
+ new RegExp(`(${this.prefix}button)(?:--\\[((?:[\\w\\s-])+?)\\])`, "gm"),
389
+ (_from, pre, props = "") => {
390
+ const results = [];
391
+ const [size] = props.match(reSize) ?? [];
392
+ const [variant] = props.match(/outline|text|circle/) ?? [];
393
+ const [, color] = props.match(/brand-(\w+)/) ?? [];
394
+ results.push(pre + `--size-${size ?? "default"}`);
395
+ const variants = variant ?? "default";
396
+ results.push(pre + `--variant-${variants}`);
397
+ const hasVariants = variants !== "default";
398
+ if (color) {
399
+ if (hasVariants) {
400
+ results.push(`${this.prefix}text-${color}`);
401
+ results.push(`hover:${this.prefix}text-on-${color}`);
402
+ results.push(`hover:before:${this.prefix}bg-${color}`);
403
+ } else {
404
+ results.push(`${this.prefix}bg-${color}`);
405
+ }
406
+ } else if (hasVariants) {
407
+ results.push(`hover:${this.prefix}text-on-invert`);
408
+ results.push(`hover:before:${this.prefix}bg-invert`);
409
+ }
410
+ return results.join(" ");
411
+ }
412
+ );
413
+ }
414
+ getRules() {
415
+ return [];
416
+ }
417
+ getShortcuts() {
418
+ return [
419
+ [
420
+ /^button$/,
421
+ () => {
422
+ const size = this.sizes.default ?? "";
423
+ const variant = this.variants.default ?? "";
424
+ return `${size} ${variant}`;
425
+ },
426
+ { layer: "vinicunca" }
427
+ ],
428
+ [
429
+ new RegExp(`^button--size-(?<size>${Object.keys(this.sizes).join("|")})?$`),
430
+ ({ groups }) => {
431
+ const size = groups?.size || "default";
432
+ return this.sizes[size] ?? "";
433
+ },
434
+ { layer: "vinicunca" }
435
+ ],
436
+ [
437
+ new RegExp(`^button--variant-(?<variant>${Object.keys(this.variants).join("|")})?$`),
438
+ ({ groups }) => {
439
+ const variant = groups?.variant || "elevated";
440
+ return this.variants[variant] ?? "";
441
+ },
442
+ { layer: "variants" }
443
+ ]
444
+ ];
445
+ }
446
+ }
447
+
448
+ class Overlay extends PresetCore {
449
+ constructor(options) {
450
+ super(options);
451
+ this.scrollBlockedClass = options.scrollBlockedClass ?? {};
452
+ }
453
+ getPreflight() {
454
+ return {
455
+ layer: "preflight",
456
+ getCSS: () => {
457
+ const lines = [];
458
+ lines.push(createCssSelector({
459
+ selector: `html.${this.scrollBlockedClass.name}`,
460
+ content: [
461
+ unocss.entriesToCss(Object.entries(this.scrollBlockedClass.html))
462
+ ]
463
+ }));
464
+ return lines.join("");
465
+ }
466
+ };
467
+ }
468
+ getShortcuts() {
469
+ const trimmedClass = this.scrollBlockedClass.name.replace(this.prefix, "");
470
+ return [
471
+ [
472
+ trimmedClass,
473
+ this.scrollBlockedClass.rules,
474
+ { layer: "vinicunca" }
475
+ ]
476
+ ];
477
+ }
478
+ }
479
+
480
+ class VinicuncaConfig {
481
+ constructor(options) {
482
+ const { prefix, components, theme } = options;
483
+ this.prefix = prefix ?? DEFAULT_PREFIX;
484
+ this.theme = new Theme({
485
+ prefix: this.prefix,
486
+ ...theme
487
+ });
488
+ const colorKeys = this.theme.getColorKeys();
489
+ this.color = new Color({
490
+ prefix: this.prefix,
491
+ colorKeys
492
+ });
493
+ this.elevation = new Elevation();
494
+ this.button = new Button({
495
+ prefix: this.prefix,
496
+ colorKeys,
497
+ ...components?.button
498
+ });
499
+ this.overlay = new Overlay({
500
+ prefix: this.prefix,
501
+ ...components?.overlay
502
+ });
503
+ }
504
+ getPreset() {
505
+ return {
506
+ name: "unocss-preset-vinicunca",
507
+ layers: {
508
+ preflight: -2,
509
+ vinicunca: -1,
510
+ default: 0,
511
+ variants: 1
512
+ },
513
+ prefix: this.prefix,
514
+ preflights: this.definePreflights(),
515
+ rules: this.defineRules(),
516
+ shortcuts: this.defineShortcuts()
517
+ };
518
+ }
519
+ getTransformer() {
520
+ return {
521
+ name: "vinicunca-transformers",
522
+ enforce: "pre",
523
+ transform: (str) => {
524
+ let content = str.toString();
525
+ content = this.button.transformClass(content);
526
+ str.overwrite(0, str.length(), content);
527
+ }
528
+ };
529
+ }
530
+ definePreflights() {
531
+ return [
532
+ this.theme.getPreflight(),
533
+ this.overlay.getPreflight()
534
+ ];
535
+ }
536
+ defineRules() {
537
+ return [
538
+ this.theme.getRules(),
539
+ this.color.getRules(),
540
+ this.elevation.getRules(),
541
+ this.button.getRules()
542
+ ].flat(1);
543
+ }
544
+ defineShortcuts() {
545
+ return [
546
+ ...this.button.getShortcuts(),
547
+ ...this.overlay.getShortcuts()
548
+ ];
549
+ }
550
+ }
551
+
552
+ function defineVinicuncaConfig(options = {}) {
553
+ return new VinicuncaConfig(options);
554
+ }
555
+
556
+ exports.defineVinicuncaConfig = defineVinicuncaConfig;