@vinicunca/unocss-preset 0.3.0 → 0.3.1

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
@@ -263,49 +263,29 @@ class Animation {
263
263
  class Color extends VinicuncaCore {
264
264
  constructor(options) {
265
265
  super(options);
266
+ this.onColors = {};
267
+ this.brands = this.resolveBrands(options.brands ?? {});
266
268
  }
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"
269
+ resolveBrands(brands) {
270
+ for (const brand of Object.keys(brands)) {
271
+ const brandColors = brands[brand];
272
+ if (jsUtilities.isString(brandColors)) {
273
+ continue;
274
+ } else {
275
+ for (const color of Object.keys(brandColors)) {
276
+ if (/^on-[a-z]/.test(color)) {
277
+ const onKey = color.replace(/^on-/, "");
278
+ this.onColors[`${brand}-${onKey}`] = brandColors[color];
279
+ delete brandColors[color];
278
280
  }
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
281
  }
308
282
  }
283
+ }
284
+ return brands;
285
+ }
286
+ getThemes() {
287
+ return {
288
+ colors: this.brands
309
289
  };
310
290
  }
311
291
  getRules() {
@@ -314,36 +294,44 @@ class Color extends VinicuncaCore {
314
294
  ];
315
295
  }
316
296
  getBgRule() {
297
+ return [
298
+ /^bg-(.+)$/,
299
+ ([, body], { theme }) => this.resolveBgRule(body, theme)
300
+ ];
301
+ }
302
+ resolveBgRule(body, theme) {
317
303
  function getTextColorName(color) {
318
304
  const colorValue = jsUtilities.parseColor(color);
319
305
  const blackContrast = Math.abs(jsUtilities.APCAContrast(jsUtilities.parseColor(0), colorValue));
320
306
  const whiteContrast = Math.abs(jsUtilities.APCAContrast(jsUtilities.parseColor(16777215), colorValue));
321
307
  return whiteContrast > Math.min(blackContrast, 50) ? "white" : "black";
322
308
  }
323
- return [
324
- /^bg-(.+)$/,
325
- ([, body], { theme }) => {
326
- const css = {};
327
- const bgCss = colorResolver({
328
- property: "background-color",
329
- varName: "bg",
330
- body,
309
+ const css = {};
310
+ const bgCss = colorResolver({
311
+ property: "background-color",
312
+ varName: "bg",
313
+ body,
314
+ theme
315
+ });
316
+ Object.assign(css, bgCss?.css);
317
+ if (bgCss?.data.color) {
318
+ let bodyText = body;
319
+ if (!["inherit", "current", "transparent"].includes(body)) {
320
+ if (bodyText in this.onColors) {
321
+ bodyText = this.onColors[bodyText];
322
+ } else {
323
+ bodyText = getTextColorName(bgCss?.data.color);
324
+ }
325
+ const textCss = colorResolver({
326
+ property: "color",
327
+ varName: "text",
328
+ body: bodyText,
331
329
  theme
332
330
  });
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;
344
- },
345
- { layer: "vinicunca" }
346
- ];
331
+ Object.assign(css, textCss?.css);
332
+ }
333
+ }
334
+ return css;
347
335
  }
348
336
  }
349
337
  function colorResolver({ property, varName, body, theme }) {
@@ -431,23 +419,6 @@ class Elevation {
431
419
  }
432
420
 
433
421
  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
422
  static getRules() {
452
423
  return [
453
424
  [
@@ -551,10 +522,11 @@ class Typography {
551
522
 
552
523
  class VinicuncaConfig {
553
524
  constructor(options) {
554
- const { prefix, components } = options;
555
- this.enablePreflight = options.enablePreflight ?? true;
525
+ const { prefix, components, opacities, brands } = options;
526
+ this.opacities = opacities ?? {};
556
527
  this.color = new Color({
557
- prefix
528
+ prefix,
529
+ brands
558
530
  });
559
531
  this.divider = new Divider({
560
532
  prefix,
@@ -570,31 +542,34 @@ class VinicuncaConfig {
570
542
  });
571
543
  }
572
544
  getPreset() {
573
- const preflights = this.enablePreflight ? this.definePreflights() : [];
574
545
  return {
575
546
  name: "unocss-preset-vinicunca",
576
547
  layers: {
577
- preflight: -3,
578
- vinicunca: -2,
548
+ preflight: -1,
579
549
  default: 0,
580
- variants: 1
550
+ vinicunca: 1
581
551
  },
582
- preflights,
583
552
  theme: this.defineTheme(),
584
- rules: this.defineRules()
553
+ rules: this.defineRules(),
554
+ variants: [
555
+ (matcher) => {
556
+ if (matcher.startsWith("vin:")) {
557
+ return {
558
+ matcher: matcher.replace("vin:", "uno-layer-vinicunca:")
559
+ };
560
+ }
561
+ }
562
+ ]
585
563
  };
586
564
  }
587
- definePreflights() {
588
- return [];
589
- }
590
565
  defineTheme() {
591
566
  const themes = [
567
+ this.color.getThemes(),
592
568
  Typography.getThemes(),
593
- Color.getThemes(),
594
- Opacity.getThemes(),
595
569
  Animation.getThemes(),
596
570
  Button.getThemes(),
597
571
  {
572
+ opacity: this.opacities,
598
573
  lineWidth: {
599
574
  thin: "thin",
600
575
  medium: "medium",
package/dist/index.d.ts CHANGED
@@ -17,9 +17,14 @@ interface OverlayOptions {
17
17
  };
18
18
  }
19
19
 
20
+ type ColorBrands = Record<string, Record<string, string> | string>;
21
+
22
+ type OpacityTheme = Record<string, number | string>;
23
+
20
24
  interface IVinicuncaConfig {
21
- enablePreflight?: boolean;
22
25
  prefix?: string;
26
+ brands?: ColorBrands;
27
+ opacities?: OpacityTheme;
23
28
  components?: {
24
29
  button?: CoreOptions;
25
30
  divider?: CoreOptions;
@@ -27,14 +32,13 @@ interface IVinicuncaConfig {
27
32
  };
28
33
  }
29
34
  declare class VinicuncaConfig {
30
- private enablePreflight;
31
35
  private color;
36
+ private opacities;
32
37
  private divider;
33
38
  private button;
34
39
  private overlay;
35
40
  constructor(options: IVinicuncaConfig);
36
41
  getPreset(): Preset;
37
- private definePreflights;
38
42
  private defineTheme;
39
43
  getTransformer(): SourceCodeTransformer;
40
44
  private defineRules;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createFilter } from '@rollup/pluginutils';
2
- import { toKebabCase, partition, trimAll, hasValue, parseColor as parseColor$1, APCAContrast, convertToUnit, mergeDeep } from '@vinicunca/js-utilities';
2
+ import { toKebabCase, partition, trimAll, isString, hasValue, parseColor as parseColor$1, APCAContrast, convertToUnit, mergeDeep } from '@vinicunca/js-utilities';
3
3
  import { entriesToCss } from '@unocss/core';
4
4
  import { parseColor, colorOpacityToString, colorToString, handler } from '@unocss/preset-mini/utils';
5
5
 
@@ -259,49 +259,29 @@ class Animation {
259
259
  class Color extends VinicuncaCore {
260
260
  constructor(options) {
261
261
  super(options);
262
+ this.onColors = {};
263
+ this.brands = this.resolveBrands(options.brands ?? {});
262
264
  }
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"
265
+ resolveBrands(brands) {
266
+ for (const brand of Object.keys(brands)) {
267
+ const brandColors = brands[brand];
268
+ if (isString(brandColors)) {
269
+ continue;
270
+ } else {
271
+ for (const color of Object.keys(brandColors)) {
272
+ if (/^on-[a-z]/.test(color)) {
273
+ const onKey = color.replace(/^on-/, "");
274
+ this.onColors[`${brand}-${onKey}`] = brandColors[color];
275
+ delete brandColors[color];
274
276
  }
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
277
  }
304
278
  }
279
+ }
280
+ return brands;
281
+ }
282
+ getThemes() {
283
+ return {
284
+ colors: this.brands
305
285
  };
306
286
  }
307
287
  getRules() {
@@ -310,36 +290,44 @@ class Color extends VinicuncaCore {
310
290
  ];
311
291
  }
312
292
  getBgRule() {
293
+ return [
294
+ /^bg-(.+)$/,
295
+ ([, body], { theme }) => this.resolveBgRule(body, theme)
296
+ ];
297
+ }
298
+ resolveBgRule(body, theme) {
313
299
  function getTextColorName(color) {
314
300
  const colorValue = parseColor$1(color);
315
301
  const blackContrast = Math.abs(APCAContrast(parseColor$1(0), colorValue));
316
302
  const whiteContrast = Math.abs(APCAContrast(parseColor$1(16777215), colorValue));
317
303
  return whiteContrast > Math.min(blackContrast, 50) ? "white" : "black";
318
304
  }
319
- return [
320
- /^bg-(.+)$/,
321
- ([, body], { theme }) => {
322
- const css = {};
323
- const bgCss = colorResolver({
324
- property: "background-color",
325
- varName: "bg",
326
- body,
305
+ const css = {};
306
+ const bgCss = colorResolver({
307
+ property: "background-color",
308
+ varName: "bg",
309
+ body,
310
+ theme
311
+ });
312
+ Object.assign(css, bgCss?.css);
313
+ if (bgCss?.data.color) {
314
+ let bodyText = body;
315
+ if (!["inherit", "current", "transparent"].includes(body)) {
316
+ if (bodyText in this.onColors) {
317
+ bodyText = this.onColors[bodyText];
318
+ } else {
319
+ bodyText = getTextColorName(bgCss?.data.color);
320
+ }
321
+ const textCss = colorResolver({
322
+ property: "color",
323
+ varName: "text",
324
+ body: bodyText,
327
325
  theme
328
326
  });
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;
340
- },
341
- { layer: "vinicunca" }
342
- ];
327
+ Object.assign(css, textCss?.css);
328
+ }
329
+ }
330
+ return css;
343
331
  }
344
332
  }
345
333
  function colorResolver({ property, varName, body, theme }) {
@@ -427,23 +415,6 @@ class Elevation {
427
415
  }
428
416
 
429
417
  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
418
  static getRules() {
448
419
  return [
449
420
  [
@@ -547,10 +518,11 @@ class Typography {
547
518
 
548
519
  class VinicuncaConfig {
549
520
  constructor(options) {
550
- const { prefix, components } = options;
551
- this.enablePreflight = options.enablePreflight ?? true;
521
+ const { prefix, components, opacities, brands } = options;
522
+ this.opacities = opacities ?? {};
552
523
  this.color = new Color({
553
- prefix
524
+ prefix,
525
+ brands
554
526
  });
555
527
  this.divider = new Divider({
556
528
  prefix,
@@ -566,31 +538,34 @@ class VinicuncaConfig {
566
538
  });
567
539
  }
568
540
  getPreset() {
569
- const preflights = this.enablePreflight ? this.definePreflights() : [];
570
541
  return {
571
542
  name: "unocss-preset-vinicunca",
572
543
  layers: {
573
- preflight: -3,
574
- vinicunca: -2,
544
+ preflight: -1,
575
545
  default: 0,
576
- variants: 1
546
+ vinicunca: 1
577
547
  },
578
- preflights,
579
548
  theme: this.defineTheme(),
580
- rules: this.defineRules()
549
+ rules: this.defineRules(),
550
+ variants: [
551
+ (matcher) => {
552
+ if (matcher.startsWith("vin:")) {
553
+ return {
554
+ matcher: matcher.replace("vin:", "uno-layer-vinicunca:")
555
+ };
556
+ }
557
+ }
558
+ ]
581
559
  };
582
560
  }
583
- definePreflights() {
584
- return [];
585
- }
586
561
  defineTheme() {
587
562
  const themes = [
563
+ this.color.getThemes(),
588
564
  Typography.getThemes(),
589
- Color.getThemes(),
590
- Opacity.getThemes(),
591
565
  Animation.getThemes(),
592
566
  Button.getThemes(),
593
567
  {
568
+ opacity: this.opacities,
594
569
  lineWidth: {
595
570
  thin: "thin",
596
571
  medium: "medium",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinicunca/unocss-preset",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "packageManager": "pnpm@8.2.0",
5
5
  "description": "UnoCSS custom preset",
6
6
  "author": "praburangki<https://github.com/praburangki>",