@vinicunca/unocss-preset 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  const pluginutils = require('@rollup/pluginutils');
6
6
  const jsUtilities = require('@vinicunca/js-utilities');
7
7
  const core = require('@unocss/core');
8
+ const utils = require('@unocss/preset-mini/utils');
8
9
 
9
10
  const DEFAULT_PREFIX = "vin-";
10
11
  class VinicuncaCore {
@@ -29,10 +30,6 @@ class VinicuncaCore {
29
30
  }
30
31
  }
31
32
 
32
- function trimAll(str) {
33
- return str.replace(/[\s\n\r]+/g, " ").trim();
34
- }
35
-
36
33
  class Button extends VinicuncaCore {
37
34
  constructor(options) {
38
35
  super(options);
@@ -92,7 +89,7 @@ class Button extends VinicuncaCore {
92
89
  )
93
90
  );
94
91
  }
95
- return trimAll(results.join(" "));
92
+ return jsUtilities.trimAll(results.join(" "));
96
93
  }
97
94
  );
98
95
  }
@@ -164,7 +161,7 @@ class Divider extends VinicuncaCore {
164
161
  results.push("border-r-1");
165
162
  }
166
163
  }
167
- return trimAll(results.join(" "));
164
+ return jsUtilities.trimAll(results.join(" "));
168
165
  }
169
166
  );
170
167
  }
@@ -206,147 +203,6 @@ class Overlay extends VinicuncaCore {
206
203
  }
207
204
  }
208
205
 
209
- const DEFAULT_THEME = {
210
- light: {
211
- dark: false,
212
- colors: {
213
- "background": "#FFFFFF",
214
- "surface": "#FFFFFF",
215
- "surface-variant": "#424242",
216
- "on-surface-variant": "#EEEEEE",
217
- "primary": "#1976D2",
218
- "secondary": "#9c27b0",
219
- "error": "#d32f2f",
220
- "info": "#0288d1",
221
- "success": "#2e7d32",
222
- "warning": "#ed6c02",
223
- "border": "#000000"
224
- },
225
- variables: {
226
- "opacity-border": 0.12,
227
- "opacity-high-emphasis": 0.87,
228
- "opacity-medium-emphasis": 0.6,
229
- "opacity-disabled": 0.38,
230
- "opacity-idle": 0.04,
231
- "opacity-hover": 0.04,
232
- "opacity-focus": 0.12,
233
- "opacity-selected": 0.08,
234
- "opacity-activated": 0.12,
235
- "opacity-pressed": 0.12,
236
- "opacity-dragged": 0.08
237
- }
238
- },
239
- dark: {
240
- dark: true,
241
- colors: {
242
- "background": "#121212",
243
- "surface": "#212121",
244
- "surface-variant": "#BDBDBD",
245
- "on-surface-variant": "#424242",
246
- "primary": "#1565C0",
247
- "secondary": "#7b1fa2",
248
- "error": "#c62828",
249
- "info": "#01579b",
250
- "success": "#1b5e20",
251
- "warning": "#e65100",
252
- "border": "#FFFFFF"
253
- },
254
- variables: {
255
- "opacity-border": 0.12,
256
- "opacity-high-emphasis": 0.87,
257
- "opacity-medium-emphasis": 0.6,
258
- "opacity-disabled": 0.38,
259
- "opacity-idle": 0.1,
260
- "opacity-hover": 0.04,
261
- "opacity-focus": 0.12,
262
- "opacity-selected": 0.08,
263
- "opacity-activated": 0.12,
264
- "opacity-pressed": 0.16,
265
- "opacity-dragged": 0.08
266
- }
267
- }
268
- };
269
-
270
- class Brand extends VinicuncaCore {
271
- constructor(options) {
272
- super(options);
273
- const parsedOptions = this.parseBrandOptions(options?.themes);
274
- this.themes = this.parseBrand(parsedOptions);
275
- this.preflights = options?.preflights ?? {};
276
- }
277
- getPreflight() {
278
- return {
279
- getCSS: () => {
280
- const lines = [];
281
- lines.push(createCssSelector({
282
- selector: ":root",
283
- content: [
284
- core.entriesToCss(Object.entries(this.remapVariables({ tokens: this.preflights })))
285
- ]
286
- }));
287
- lines.push(createCssSelector({
288
- selector: ":root",
289
- content: this.genCssVariables(this.themes.light)
290
- }));
291
- return lines.join("\n");
292
- }
293
- };
294
- }
295
- genCssVariables(theme) {
296
- const lightOverlay = theme.dark ? 2 : 1;
297
- const darkOverlay = theme.dark ? 1 : 2;
298
- const themeVariables = {};
299
- for (const [key, value] of Object.entries(theme.colors)) {
300
- const rgb = jsUtilities.parseColor(value);
301
- themeVariables[key] = `${rgb.r},${rgb.g},${rgb.b}`;
302
- if (!key.startsWith("on-")) {
303
- themeVariables[`${key}-overlay-multiplier`] = (jsUtilities.getLuma(value) > 0.18 ? lightOverlay : darkOverlay).toString();
304
- }
305
- }
306
- const variables = {};
307
- for (const [key, value] of Object.entries(theme.variables)) {
308
- const color = typeof value === "string" && value.startsWith("#") ? jsUtilities.parseColor(value) : void 0;
309
- const rgb = color ? `${color.r},${color.g},${color.b}` : void 0;
310
- variables[key] = `${rgb ?? value}`;
311
- }
312
- return [
313
- core.entriesToCss(Object.entries(this.remapVariables({ tokens: themeVariables, key: "theme-" }))),
314
- core.entriesToCss(Object.entries(this.remapVariables({ tokens: variables })))
315
- ];
316
- }
317
- parseBrandOptions(options) {
318
- if (!options) {
319
- return DEFAULT_THEME;
320
- }
321
- return jsUtilities.mergeDeep(
322
- DEFAULT_THEME,
323
- { ...options }
324
- );
325
- }
326
- parseBrand(_themes) {
327
- const acc = {};
328
- for (const [name, original] of Object.entries(_themes)) {
329
- const theme = acc[name] = {
330
- ...original,
331
- colors: {
332
- ...original.colors
333
- }
334
- };
335
- for (const color of Object.keys(theme.colors)) {
336
- if (/^on-[a-z]/.test(color) || theme.colors[`on-${color}`]) {
337
- continue;
338
- }
339
- const onColor = `on-${color}`;
340
- const colorValue = jsUtilities.parseColor(theme.colors[color]);
341
- const blackContrast = Math.abs(jsUtilities.APCAContrast(jsUtilities.parseColor(0), colorValue));
342
- const whiteContrast = Math.abs(jsUtilities.APCAContrast(jsUtilities.parseColor(16777215), colorValue));
343
- theme.colors[onColor] = whiteContrast > Math.min(blackContrast, 50) ? "#fff" : "#000";
344
- }
345
- }
346
- return acc;
347
- }
348
- }
349
-
350
206
  const KEY_CIRCULAR_DASH = "progress-circular-dash";
351
207
  const KEY_CIRCULAR_ROTATE = "progress-circular-rotate";
352
208
  const KEY_LINE = "progress-line";
@@ -408,60 +264,111 @@ class Color extends VinicuncaCore {
408
264
  constructor(options) {
409
265
  super(options);
410
266
  }
411
- getRules() {
412
- return [
413
- this.getTextRule(),
414
- this.getBgRule(),
415
- this.getBorderRule()
416
- ];
417
- }
418
- getBorderRule() {
419
- return [
420
- /^border-brand-(?<body>(?:on-)?(?<color>.+))/,
421
- ({ groups }) => {
422
- const { body, color } = groups;
423
- const colorBody = /^on-[a-z]/.test(body) ? `on-${color}` : color;
424
- const colorVar = this.genVariable(`theme-${colorBody}`);
425
- return {
426
- "--un-border-opacity": 1,
427
- "border-color": `rgba(var(${colorVar}), var(--un-border-opacity))`
428
- };
429
- },
430
- { layer: "vinicunca" }
431
- ];
267
+ static getThemes() {
268
+ return {
269
+ colors: {
270
+ surface: {
271
+ DEFAULT: "#FFFFFF",
272
+ variant: "#424242",
273
+ onVariant: "#EEEEEE",
274
+ dark: {
275
+ DEFAULT: "#212121",
276
+ variant: "#BDBDBD",
277
+ onVariant: "#424242"
278
+ }
279
+ },
280
+ primary: {
281
+ DEFAULT: "#1976D2",
282
+ dark: "#1565C0"
283
+ },
284
+ error: {
285
+ DEFAULT: "#d32f2f",
286
+ dark: "#c62828"
287
+ },
288
+ success: {
289
+ DEFAULT: "#2e7d32",
290
+ dark: "#1b5e20"
291
+ },
292
+ secondary: {
293
+ DEFAULT: "#9c27b0",
294
+ dark: "#7b1fa2"
295
+ },
296
+ info: {
297
+ DEFAULT: "#0288d1",
298
+ dark: "#01579b"
299
+ },
300
+ warning: {
301
+ DEFAULT: "#ed6c02",
302
+ dark: "#e65100"
303
+ },
304
+ border: {
305
+ DEFAULT: "#000000",
306
+ dark: "#FFFFFF"
307
+ }
308
+ }
309
+ };
432
310
  }
433
- getTextRule() {
311
+ getRules() {
434
312
  return [
435
- /^text-brand-(?<body>(?:on-)?(?<color>.+))/,
436
- ({ groups }) => {
437
- const { body, color } = groups;
438
- const colorBody = /^on-[a-z]/.test(body) ? `on-${color}` : color;
439
- const colorVar = this.genVariable(`theme-${colorBody}`);
440
- return {
441
- "--un-text-opacity": 1,
442
- "color": `rgba(var(${colorVar}), var(--un-text-opacity))`
443
- };
444
- },
445
- { layer: "vinicunca" }
313
+ this.getBgRule()
446
314
  ];
447
315
  }
448
316
  getBgRule() {
317
+ function getTextColorName(color) {
318
+ const colorValue = jsUtilities.parseColor(color);
319
+ const blackContrast = Math.abs(jsUtilities.APCAContrast(jsUtilities.parseColor(0), colorValue));
320
+ const whiteContrast = Math.abs(jsUtilities.APCAContrast(jsUtilities.parseColor(16777215), colorValue));
321
+ return whiteContrast > Math.min(blackContrast, 50) ? "white" : "black";
322
+ }
449
323
  return [
450
- /^bg-brand-(.+)$/,
451
- ([, body]) => {
452
- const bgColorVar = this.genVariable(`theme-${body}`);
453
- const colorVar = this.genVariable(`theme-on-${body}`);
454
- return {
455
- "--un-text-opacity": 1,
456
- "--un-bg-opacity": 1,
457
- "background-color": `rgba(var(${bgColorVar}),var(--un-bg-opacity))`,
458
- "color": `rgba(var(${colorVar}), var(--un-text-opacity))`
459
- };
324
+ /^bg-(.+)$/,
325
+ ([, body], { theme }) => {
326
+ const css = {};
327
+ const bgCss = colorResolver({
328
+ property: "background-color",
329
+ varName: "bg",
330
+ body,
331
+ theme
332
+ });
333
+ Object.assign(css, bgCss?.css);
334
+ if (bgCss?.data.color) {
335
+ const textCss = colorResolver({
336
+ property: "color",
337
+ varName: "text",
338
+ body: getTextColorName(bgCss?.data.color),
339
+ theme
340
+ });
341
+ Object.assign(css, textCss?.css);
342
+ }
343
+ return css;
460
344
  },
461
345
  { layer: "vinicunca" }
462
346
  ];
463
347
  }
464
348
  }
349
+ function colorResolver({ property, varName, body, theme }) {
350
+ const data = utils.parseColor(body, theme);
351
+ if (!data) {
352
+ return;
353
+ }
354
+ const { alpha, color, cssColor } = data;
355
+ const varOpacity = `--un-${varName}-opacity`;
356
+ const css = {};
357
+ if (cssColor) {
358
+ if (jsUtilities.hasValue(alpha)) {
359
+ css[varOpacity] = alpha;
360
+ } else {
361
+ css[varOpacity] = utils.colorOpacityToString(cssColor);
362
+ }
363
+ css[property] = utils.colorToString(cssColor, `var(${varOpacity})`);
364
+ } else if (color) {
365
+ css[property] = utils.colorToString(color, alpha);
366
+ }
367
+ return {
368
+ css,
369
+ data
370
+ };
371
+ }
465
372
 
466
373
  const COLOR_RING_OFFSET = "rgba(0, 0, 0, 0.2)";
467
374
  const COLOR_RING_SHADOW = "rgba(0, 0, 0, 0.14)";
@@ -523,6 +430,40 @@ class Elevation {
523
430
  }
524
431
  }
525
432
 
433
+ class Opacity {
434
+ static getThemes() {
435
+ return {
436
+ opacity: {
437
+ "border": 0.12,
438
+ "emphasis-high": 0.87,
439
+ "emphasis-medium": 0.6,
440
+ "disabled": 0.38,
441
+ "idle": 0.04,
442
+ "hover": 0.04,
443
+ "focus": 0.12,
444
+ "selected": 0.08,
445
+ "activated": 0.12,
446
+ "pressed": 0.12,
447
+ "dragged": 0.08
448
+ }
449
+ };
450
+ }
451
+ static getRules() {
452
+ return [
453
+ [
454
+ /^opacity-(.+)$/,
455
+ ([, body], { theme }) => {
456
+ const opacityTheme = theme.opacity;
457
+ const opacityValue = opacityTheme[body];
458
+ return {
459
+ opacity: opacityValue ?? utils.handler.bracket.percent.cssvar(body)
460
+ };
461
+ }
462
+ ]
463
+ ];
464
+ }
465
+ }
466
+
526
467
  const FONT_NAMES = {
527
468
  "h1": {
528
469
  fontSize: "6rem",
@@ -610,12 +551,8 @@ class Typography {
610
551
 
611
552
  class VinicuncaConfig {
612
553
  constructor(options) {
613
- const { prefix, components, brands } = options;
554
+ const { prefix, components } = options;
614
555
  this.enablePreflight = options.enablePreflight ?? true;
615
- this.brand = new Brand({
616
- prefix,
617
- ...brands
618
- });
619
556
  this.color = new Color({
620
557
  prefix
621
558
  });
@@ -648,13 +585,13 @@ class VinicuncaConfig {
648
585
  };
649
586
  }
650
587
  definePreflights() {
651
- return [
652
- this.brand.getPreflight()
653
- ];
588
+ return [];
654
589
  }
655
590
  defineTheme() {
656
591
  const themes = [
657
592
  Typography.getThemes(),
593
+ Color.getThemes(),
594
+ Opacity.getThemes(),
658
595
  Animation.getThemes(),
659
596
  Button.getThemes(),
660
597
  {
@@ -691,12 +628,10 @@ class VinicuncaConfig {
691
628
  defineRules() {
692
629
  return [
693
630
  this.color.getRules(),
694
- Elevation.getRules()
631
+ Elevation.getRules(),
632
+ Opacity.getRules()
695
633
  ].flat(1);
696
634
  }
697
- defineShortcuts() {
698
- return [];
699
- }
700
635
  }
701
636
 
702
637
  function defineVinicuncaConfig(options = {}) {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DeepPartial, Preset, SourceCodeTransformer } from '@unocss/core';
1
+ import { Preset, SourceCodeTransformer } from '@unocss/core';
2
2
 
3
3
  interface CoreOptions {
4
4
  prefix?: string;
@@ -17,53 +17,9 @@ interface OverlayOptions {
17
17
  };
18
18
  }
19
19
 
20
- interface Colors extends BaseColors, OnColors {
21
- [key: string]: string;
22
- }
23
- interface BaseColors {
24
- background: string;
25
- surface: string;
26
- primary: string;
27
- secondary: string;
28
- success: string;
29
- warning: string;
30
- error: string;
31
- info: string;
32
- }
33
- interface OnColors {
34
- 'on-background': string;
35
- 'on-surface': string;
36
- 'on-primary': string;
37
- 'on-secondary': string;
38
- 'on-success': string;
39
- 'on-warning': string;
40
- 'on-error': string;
41
- 'on-info': string;
42
- }
43
- interface InternalBrandDefinition {
44
- dark: boolean;
45
- colors: Colors;
46
- variables: Record<string, string | number>;
47
- }
48
- type BrandDefinition = DeepPartial<InternalBrandDefinition>;
49
- type BrandOptions = Record<string, BrandDefinition>;
50
- interface BrandPreflight {
51
- background: string;
52
- 'on-background': string;
53
- surface: string;
54
- 'on-surface': string;
55
- 'overlay-multiplier': number;
56
- 'scrollbar-offset': string;
57
- }
58
- interface BrandConfig {
59
- themes?: BrandOptions;
60
- preflights?: DeepPartial<BrandPreflight>;
61
- }
62
-
63
20
  interface IVinicuncaConfig {
64
21
  enablePreflight?: boolean;
65
22
  prefix?: string;
66
- brands?: BrandConfig;
67
23
  components?: {
68
24
  button?: CoreOptions;
69
25
  divider?: CoreOptions;
@@ -72,7 +28,6 @@ interface IVinicuncaConfig {
72
28
  }
73
29
  declare class VinicuncaConfig {
74
30
  private enablePreflight;
75
- private brand;
76
31
  private color;
77
32
  private divider;
78
33
  private button;
@@ -83,7 +38,6 @@ declare class VinicuncaConfig {
83
38
  private defineTheme;
84
39
  getTransformer(): SourceCodeTransformer;
85
40
  private defineRules;
86
- private defineShortcuts;
87
41
  }
88
42
 
89
43
  /**
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createFilter } from '@rollup/pluginutils';
2
- import { toKebabCase, partition, parseColor, getLuma, mergeDeep, APCAContrast, convertToUnit } from '@vinicunca/js-utilities';
2
+ import { toKebabCase, partition, trimAll, hasValue, parseColor as parseColor$1, APCAContrast, convertToUnit, mergeDeep } from '@vinicunca/js-utilities';
3
3
  import { entriesToCss } from '@unocss/core';
4
+ import { parseColor, colorOpacityToString, colorToString, handler } from '@unocss/preset-mini/utils';
4
5
 
5
6
  const DEFAULT_PREFIX = "vin-";
6
7
  class VinicuncaCore {
@@ -25,10 +26,6 @@ class VinicuncaCore {
25
26
  }
26
27
  }
27
28
 
28
- function trimAll(str) {
29
- return str.replace(/[\s\n\r]+/g, " ").trim();
30
- }
31
-
32
29
  class Button extends VinicuncaCore {
33
30
  constructor(options) {
34
31
  super(options);
@@ -202,147 +199,6 @@ class Overlay extends VinicuncaCore {
202
199
  }
203
200
  }
204
201
 
205
- const DEFAULT_THEME = {
206
- light: {
207
- dark: false,
208
- colors: {
209
- "background": "#FFFFFF",
210
- "surface": "#FFFFFF",
211
- "surface-variant": "#424242",
212
- "on-surface-variant": "#EEEEEE",
213
- "primary": "#1976D2",
214
- "secondary": "#9c27b0",
215
- "error": "#d32f2f",
216
- "info": "#0288d1",
217
- "success": "#2e7d32",
218
- "warning": "#ed6c02",
219
- "border": "#000000"
220
- },
221
- variables: {
222
- "opacity-border": 0.12,
223
- "opacity-high-emphasis": 0.87,
224
- "opacity-medium-emphasis": 0.6,
225
- "opacity-disabled": 0.38,
226
- "opacity-idle": 0.04,
227
- "opacity-hover": 0.04,
228
- "opacity-focus": 0.12,
229
- "opacity-selected": 0.08,
230
- "opacity-activated": 0.12,
231
- "opacity-pressed": 0.12,
232
- "opacity-dragged": 0.08
233
- }
234
- },
235
- dark: {
236
- dark: true,
237
- colors: {
238
- "background": "#121212",
239
- "surface": "#212121",
240
- "surface-variant": "#BDBDBD",
241
- "on-surface-variant": "#424242",
242
- "primary": "#1565C0",
243
- "secondary": "#7b1fa2",
244
- "error": "#c62828",
245
- "info": "#01579b",
246
- "success": "#1b5e20",
247
- "warning": "#e65100",
248
- "border": "#FFFFFF"
249
- },
250
- variables: {
251
- "opacity-border": 0.12,
252
- "opacity-high-emphasis": 0.87,
253
- "opacity-medium-emphasis": 0.6,
254
- "opacity-disabled": 0.38,
255
- "opacity-idle": 0.1,
256
- "opacity-hover": 0.04,
257
- "opacity-focus": 0.12,
258
- "opacity-selected": 0.08,
259
- "opacity-activated": 0.12,
260
- "opacity-pressed": 0.16,
261
- "opacity-dragged": 0.08
262
- }
263
- }
264
- };
265
-
266
- class Brand extends VinicuncaCore {
267
- constructor(options) {
268
- super(options);
269
- const parsedOptions = this.parseBrandOptions(options?.themes);
270
- this.themes = this.parseBrand(parsedOptions);
271
- this.preflights = options?.preflights ?? {};
272
- }
273
- getPreflight() {
274
- return {
275
- getCSS: () => {
276
- const lines = [];
277
- lines.push(createCssSelector({
278
- selector: ":root",
279
- content: [
280
- entriesToCss(Object.entries(this.remapVariables({ tokens: this.preflights })))
281
- ]
282
- }));
283
- lines.push(createCssSelector({
284
- selector: ":root",
285
- content: this.genCssVariables(this.themes.light)
286
- }));
287
- return lines.join("\n");
288
- }
289
- };
290
- }
291
- genCssVariables(theme) {
292
- const lightOverlay = theme.dark ? 2 : 1;
293
- const darkOverlay = theme.dark ? 1 : 2;
294
- const themeVariables = {};
295
- for (const [key, value] of Object.entries(theme.colors)) {
296
- const rgb = parseColor(value);
297
- themeVariables[key] = `${rgb.r},${rgb.g},${rgb.b}`;
298
- if (!key.startsWith("on-")) {
299
- themeVariables[`${key}-overlay-multiplier`] = (getLuma(value) > 0.18 ? lightOverlay : darkOverlay).toString();
300
- }
301
- }
302
- const variables = {};
303
- for (const [key, value] of Object.entries(theme.variables)) {
304
- const color = typeof value === "string" && value.startsWith("#") ? parseColor(value) : void 0;
305
- const rgb = color ? `${color.r},${color.g},${color.b}` : void 0;
306
- variables[key] = `${rgb ?? value}`;
307
- }
308
- return [
309
- entriesToCss(Object.entries(this.remapVariables({ tokens: themeVariables, key: "theme-" }))),
310
- entriesToCss(Object.entries(this.remapVariables({ tokens: variables })))
311
- ];
312
- }
313
- parseBrandOptions(options) {
314
- if (!options) {
315
- return DEFAULT_THEME;
316
- }
317
- return mergeDeep(
318
- DEFAULT_THEME,
319
- { ...options }
320
- );
321
- }
322
- parseBrand(_themes) {
323
- const acc = {};
324
- for (const [name, original] of Object.entries(_themes)) {
325
- const theme = acc[name] = {
326
- ...original,
327
- colors: {
328
- ...original.colors
329
- }
330
- };
331
- for (const color of Object.keys(theme.colors)) {
332
- if (/^on-[a-z]/.test(color) || theme.colors[`on-${color}`]) {
333
- continue;
334
- }
335
- const onColor = `on-${color}`;
336
- const colorValue = parseColor(theme.colors[color]);
337
- const blackContrast = Math.abs(APCAContrast(parseColor(0), colorValue));
338
- const whiteContrast = Math.abs(APCAContrast(parseColor(16777215), colorValue));
339
- theme.colors[onColor] = whiteContrast > Math.min(blackContrast, 50) ? "#fff" : "#000";
340
- }
341
- }
342
- return acc;
343
- }
344
- }
345
-
346
202
  const KEY_CIRCULAR_DASH = "progress-circular-dash";
347
203
  const KEY_CIRCULAR_ROTATE = "progress-circular-rotate";
348
204
  const KEY_LINE = "progress-line";
@@ -404,60 +260,111 @@ class Color extends VinicuncaCore {
404
260
  constructor(options) {
405
261
  super(options);
406
262
  }
407
- getRules() {
408
- return [
409
- this.getTextRule(),
410
- this.getBgRule(),
411
- this.getBorderRule()
412
- ];
413
- }
414
- getBorderRule() {
415
- return [
416
- /^border-brand-(?<body>(?:on-)?(?<color>.+))/,
417
- ({ groups }) => {
418
- const { body, color } = groups;
419
- const colorBody = /^on-[a-z]/.test(body) ? `on-${color}` : color;
420
- const colorVar = this.genVariable(`theme-${colorBody}`);
421
- return {
422
- "--un-border-opacity": 1,
423
- "border-color": `rgba(var(${colorVar}), var(--un-border-opacity))`
424
- };
425
- },
426
- { layer: "vinicunca" }
427
- ];
263
+ static getThemes() {
264
+ return {
265
+ colors: {
266
+ surface: {
267
+ DEFAULT: "#FFFFFF",
268
+ variant: "#424242",
269
+ onVariant: "#EEEEEE",
270
+ dark: {
271
+ DEFAULT: "#212121",
272
+ variant: "#BDBDBD",
273
+ onVariant: "#424242"
274
+ }
275
+ },
276
+ primary: {
277
+ DEFAULT: "#1976D2",
278
+ dark: "#1565C0"
279
+ },
280
+ error: {
281
+ DEFAULT: "#d32f2f",
282
+ dark: "#c62828"
283
+ },
284
+ success: {
285
+ DEFAULT: "#2e7d32",
286
+ dark: "#1b5e20"
287
+ },
288
+ secondary: {
289
+ DEFAULT: "#9c27b0",
290
+ dark: "#7b1fa2"
291
+ },
292
+ info: {
293
+ DEFAULT: "#0288d1",
294
+ dark: "#01579b"
295
+ },
296
+ warning: {
297
+ DEFAULT: "#ed6c02",
298
+ dark: "#e65100"
299
+ },
300
+ border: {
301
+ DEFAULT: "#000000",
302
+ dark: "#FFFFFF"
303
+ }
304
+ }
305
+ };
428
306
  }
429
- getTextRule() {
307
+ getRules() {
430
308
  return [
431
- /^text-brand-(?<body>(?:on-)?(?<color>.+))/,
432
- ({ groups }) => {
433
- const { body, color } = groups;
434
- const colorBody = /^on-[a-z]/.test(body) ? `on-${color}` : color;
435
- const colorVar = this.genVariable(`theme-${colorBody}`);
436
- return {
437
- "--un-text-opacity": 1,
438
- "color": `rgba(var(${colorVar}), var(--un-text-opacity))`
439
- };
440
- },
441
- { layer: "vinicunca" }
309
+ this.getBgRule()
442
310
  ];
443
311
  }
444
312
  getBgRule() {
313
+ function getTextColorName(color) {
314
+ const colorValue = parseColor$1(color);
315
+ const blackContrast = Math.abs(APCAContrast(parseColor$1(0), colorValue));
316
+ const whiteContrast = Math.abs(APCAContrast(parseColor$1(16777215), colorValue));
317
+ return whiteContrast > Math.min(blackContrast, 50) ? "white" : "black";
318
+ }
445
319
  return [
446
- /^bg-brand-(.+)$/,
447
- ([, body]) => {
448
- const bgColorVar = this.genVariable(`theme-${body}`);
449
- const colorVar = this.genVariable(`theme-on-${body}`);
450
- return {
451
- "--un-text-opacity": 1,
452
- "--un-bg-opacity": 1,
453
- "background-color": `rgba(var(${bgColorVar}),var(--un-bg-opacity))`,
454
- "color": `rgba(var(${colorVar}), var(--un-text-opacity))`
455
- };
320
+ /^bg-(.+)$/,
321
+ ([, body], { theme }) => {
322
+ const css = {};
323
+ const bgCss = colorResolver({
324
+ property: "background-color",
325
+ varName: "bg",
326
+ body,
327
+ theme
328
+ });
329
+ Object.assign(css, bgCss?.css);
330
+ if (bgCss?.data.color) {
331
+ const textCss = colorResolver({
332
+ property: "color",
333
+ varName: "text",
334
+ body: getTextColorName(bgCss?.data.color),
335
+ theme
336
+ });
337
+ Object.assign(css, textCss?.css);
338
+ }
339
+ return css;
456
340
  },
457
341
  { layer: "vinicunca" }
458
342
  ];
459
343
  }
460
344
  }
345
+ function colorResolver({ property, varName, body, theme }) {
346
+ const data = parseColor(body, theme);
347
+ if (!data) {
348
+ return;
349
+ }
350
+ const { alpha, color, cssColor } = data;
351
+ const varOpacity = `--un-${varName}-opacity`;
352
+ const css = {};
353
+ if (cssColor) {
354
+ if (hasValue(alpha)) {
355
+ css[varOpacity] = alpha;
356
+ } else {
357
+ css[varOpacity] = colorOpacityToString(cssColor);
358
+ }
359
+ css[property] = colorToString(cssColor, `var(${varOpacity})`);
360
+ } else if (color) {
361
+ css[property] = colorToString(color, alpha);
362
+ }
363
+ return {
364
+ css,
365
+ data
366
+ };
367
+ }
461
368
 
462
369
  const COLOR_RING_OFFSET = "rgba(0, 0, 0, 0.2)";
463
370
  const COLOR_RING_SHADOW = "rgba(0, 0, 0, 0.14)";
@@ -519,6 +426,40 @@ class Elevation {
519
426
  }
520
427
  }
521
428
 
429
+ class Opacity {
430
+ static getThemes() {
431
+ return {
432
+ opacity: {
433
+ "border": 0.12,
434
+ "emphasis-high": 0.87,
435
+ "emphasis-medium": 0.6,
436
+ "disabled": 0.38,
437
+ "idle": 0.04,
438
+ "hover": 0.04,
439
+ "focus": 0.12,
440
+ "selected": 0.08,
441
+ "activated": 0.12,
442
+ "pressed": 0.12,
443
+ "dragged": 0.08
444
+ }
445
+ };
446
+ }
447
+ static getRules() {
448
+ return [
449
+ [
450
+ /^opacity-(.+)$/,
451
+ ([, body], { theme }) => {
452
+ const opacityTheme = theme.opacity;
453
+ const opacityValue = opacityTheme[body];
454
+ return {
455
+ opacity: opacityValue ?? handler.bracket.percent.cssvar(body)
456
+ };
457
+ }
458
+ ]
459
+ ];
460
+ }
461
+ }
462
+
522
463
  const FONT_NAMES = {
523
464
  "h1": {
524
465
  fontSize: "6rem",
@@ -606,12 +547,8 @@ class Typography {
606
547
 
607
548
  class VinicuncaConfig {
608
549
  constructor(options) {
609
- const { prefix, components, brands } = options;
550
+ const { prefix, components } = options;
610
551
  this.enablePreflight = options.enablePreflight ?? true;
611
- this.brand = new Brand({
612
- prefix,
613
- ...brands
614
- });
615
552
  this.color = new Color({
616
553
  prefix
617
554
  });
@@ -644,13 +581,13 @@ class VinicuncaConfig {
644
581
  };
645
582
  }
646
583
  definePreflights() {
647
- return [
648
- this.brand.getPreflight()
649
- ];
584
+ return [];
650
585
  }
651
586
  defineTheme() {
652
587
  const themes = [
653
588
  Typography.getThemes(),
589
+ Color.getThemes(),
590
+ Opacity.getThemes(),
654
591
  Animation.getThemes(),
655
592
  Button.getThemes(),
656
593
  {
@@ -687,12 +624,10 @@ class VinicuncaConfig {
687
624
  defineRules() {
688
625
  return [
689
626
  this.color.getRules(),
690
- Elevation.getRules()
627
+ Elevation.getRules(),
628
+ Opacity.getRules()
691
629
  ].flat(1);
692
630
  }
693
- defineShortcuts() {
694
- return [];
695
- }
696
631
  }
697
632
 
698
633
  function defineVinicuncaConfig(options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinicunca/unocss-preset",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "packageManager": "pnpm@8.2.0",
5
5
  "description": "UnoCSS custom preset",
6
6
  "author": "praburangki<https://github.com/praburangki>",
@@ -50,23 +50,23 @@
50
50
  "unocss": "*"
51
51
  },
52
52
  "devDependencies": {
53
- "@commitlint/cli": "^17.4.2",
54
- "@commitlint/config-conventional": "^17.4.2",
53
+ "@commitlint/cli": "^17.6.1",
54
+ "@commitlint/config-conventional": "^17.6.1",
55
55
  "@vinicunca/eslint-config": "^1.7.1",
56
- "@vinicunca/js-utilities": "^3.1.0",
56
+ "@vinicunca/js-utilities": "^3.2.0",
57
57
  "bumpp": "^9.1.0",
58
- "commitizen": "^4.2.6",
58
+ "commitizen": "^4.3.0",
59
59
  "conventional-changelog-cli": "^2.2.2",
60
60
  "cz-customizable": "^7.0.0",
61
61
  "eslint": "^8.38.0",
62
- "eslint-define-config": "^1.17.0",
62
+ "eslint-define-config": "^1.18.0",
63
63
  "husky": "^8.0.3",
64
64
  "is-ci": "^3.0.1",
65
- "lint-staged": "^13.2.0",
66
- "typescript": "^5.0.3",
65
+ "lint-staged": "^13.2.1",
66
+ "typescript": "^5.0.4",
67
67
  "unbuild": "^0.8.11",
68
- "unocss": "^0.51.2",
69
- "vitest": "^0.30.0"
68
+ "unocss": "^0.51.4",
69
+ "vitest": "^0.30.1"
70
70
  },
71
71
  "publishConfig": {
72
72
  "access": "public"