@unocss/preset-mini 0.55.7 → 0.56.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/rules.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { g as globalKeywords, h, c as colorResolver, l as directionMap, a as hasParseableColor, o as cornerMap, p as parseColor, k as colorToString, j as colorOpacityToString, z as numberWithUnitRE, m as makeGlobalStaticRules, s as splitShorthand, b as colorableShadows, n as insetMap, u as resolveVerticalBreakpoints, t as resolveBreakpoints, r as directionSize } from './shared/preset-mini.f1fe435e.mjs';
1
+ import { g as globalKeywords, h, c as colorResolver, e as directionMap, a as hasParseableColor, f as cornerMap, p as parseColor, n as numberWithUnitRE, m as makeGlobalStaticRules, s as splitShorthand, b as colorableShadows, i as insetMap, r as resolveVerticalBreakpoints, j as resolveBreakpoints, k as directionSize } from './shared/preset-mini.8929b018.mjs';
2
+ import { colorToString, colorOpacityToString } from '@unocss/rule-utils';
2
3
  import { warnOnce, toArray } from '@unocss/core';
3
- import { d as displays, c as contentVisibility, a as contents, e as textOverflows, f as textTransforms, g as fontStyles, h as fontSmoothings, i as boxShadows, j as rings, k as cursors, l as appearances, p as pointerEvents, m as resizes, u as userSelects, w as whitespaces, n as breaks, o as transforms, q as contains, s as textWraps } from './shared/preset-mini.0fac4963.mjs';
4
- export { b as boxShadowsBase, r as ringBase, t as transformBase, v as varEmpty } from './shared/preset-mini.0fac4963.mjs';
4
+ import { d as displays, c as contentVisibility, a as contents, e as textOverflows, f as textTransforms, g as fontStyles, h as fontSmoothings, i as boxShadows, j as rings, k as cursors, l as appearances, p as pointerEvents, m as resizes, u as userSelects, w as whitespaces, n as breaks, o as transforms, q as contains, s as textWraps } from './shared/preset-mini.4fe01d46.mjs';
5
+ export { b as boxShadowsBase, r as ringBase, t as transformBase, v as varEmpty } from './shared/preset-mini.4fe01d46.mjs';
5
6
 
6
7
  const verticalAlignAlias = {
7
8
  "mid": "middle",
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const ruleUtils = require('@unocss/rule-utils');
3
4
  const core = require('@unocss/core');
4
5
 
5
6
  const directionMap = {
@@ -360,7 +361,7 @@ const valueHandlers = {
360
361
  time: time
361
362
  };
362
363
 
363
- const handler = core.createValueHandler(valueHandlers);
364
+ const handler = ruleUtils.createValueHandler(valueHandlers);
364
365
  const h = handler;
365
366
 
366
367
  const CONTROL_MINI_NO_NEGATIVE = "$$mini-no-negative";
@@ -399,7 +400,7 @@ function splitShorthand(body, type) {
399
400
  }
400
401
  return split;
401
402
  }
402
- function parseColor$1(body, theme) {
403
+ function parseColor(body, theme) {
403
404
  const [main, opacity] = splitShorthand(body, "color");
404
405
  const colors = main.replace(/([a-z])([0-9])/g, "$1-$2").split(/-/g);
405
406
  const [name] = colors;
@@ -450,26 +451,26 @@ function parseColor$1(body, theme) {
450
451
  name,
451
452
  no,
452
453
  color,
453
- cssColor: parseCssColor(color),
454
+ cssColor: ruleUtils.parseCssColor(color),
454
455
  alpha: h.bracket.cssvar.percent(opacity ?? "")
455
456
  };
456
457
  }
457
458
  function colorResolver(property, varName, shouldPass) {
458
459
  return ([, body], { theme }) => {
459
- const data = parseColor$1(body, theme);
460
+ const data = parseColor(body, theme);
460
461
  if (!data)
461
462
  return;
462
463
  const { alpha, color, cssColor } = data;
463
464
  const css = {};
464
465
  if (cssColor) {
465
466
  if (alpha != null) {
466
- css[property] = colorToString(cssColor, alpha);
467
+ css[property] = ruleUtils.colorToString(cssColor, alpha);
467
468
  } else {
468
- css[`--un-${varName}-opacity`] = colorOpacityToString(cssColor);
469
- css[property] = colorToString(cssColor, `var(--un-${varName}-opacity)`);
469
+ css[`--un-${varName}-opacity`] = ruleUtils.colorOpacityToString(cssColor);
470
+ css[property] = ruleUtils.colorToString(cssColor, `var(--un-${varName}-opacity)`);
470
471
  }
471
472
  } else if (color) {
472
- css[property] = colorToString(color, alpha);
473
+ css[property] = ruleUtils.colorToString(color, alpha);
473
474
  }
474
475
  if (shouldPass?.(css) !== false)
475
476
  return css;
@@ -479,18 +480,18 @@ function colorableShadows(shadows, colorVar) {
479
480
  const colored = [];
480
481
  shadows = core.toArray(shadows);
481
482
  for (let i = 0; i < shadows.length; i++) {
482
- const components = getComponents(shadows[i], " ", 6);
483
+ const components = ruleUtils.getStringComponents(shadows[i], " ", 6);
483
484
  if (!components || components.length < 3)
484
485
  return shadows;
485
- const color = parseCssColor(components.pop());
486
+ const color = ruleUtils.parseCssColor(components.pop());
486
487
  if (color == null)
487
488
  return shadows;
488
- colored.push(`${components.join(" ")} var(${colorVar}, ${colorToString(color)})`);
489
+ colored.push(`${components.join(" ")} var(${colorVar}, ${ruleUtils.colorToString(color)})`);
489
490
  }
490
491
  return colored;
491
492
  }
492
493
  function hasParseableColor(color, theme) {
493
- return color != null && !!parseColor$1(color, theme)?.color;
494
+ return color != null && !!parseColor(color, theme)?.color;
494
495
  }
495
496
  function resolveBreakpoints({ theme, generator }) {
496
497
  let breakpoints;
@@ -511,292 +512,21 @@ function resolveVerticalBreakpoints({ theme, generator }) {
511
512
  function makeGlobalStaticRules(prefix, property) {
512
513
  return globalKeywords.map((keyword) => [`${prefix}-${keyword}`, { [property ?? prefix]: keyword }]);
513
514
  }
514
- function getBracket(str, open, close) {
515
- if (str === "")
516
- return;
517
- const l = str.length;
518
- let parenthesis = 0;
519
- let opened = false;
520
- let openAt = 0;
521
- for (let i = 0; i < l; i++) {
522
- switch (str[i]) {
523
- case open:
524
- if (!opened) {
525
- opened = true;
526
- openAt = i;
527
- }
528
- parenthesis++;
529
- break;
530
- case close:
531
- --parenthesis;
532
- if (parenthesis < 0)
533
- return;
534
- if (parenthesis === 0) {
535
- return [
536
- str.slice(openAt, i + 1),
537
- str.slice(i + 1),
538
- str.slice(0, openAt)
539
- ];
540
- }
541
- break;
542
- }
543
- }
544
- }
545
- function getComponent(str, open, close, separators) {
546
- if (str === "")
547
- return;
548
- if (core.isString(separators))
549
- separators = [separators];
550
- if (separators.length === 0)
551
- return;
552
- const l = str.length;
553
- let parenthesis = 0;
554
- for (let i = 0; i < l; i++) {
555
- switch (str[i]) {
556
- case open:
557
- parenthesis++;
558
- break;
559
- case close:
560
- if (--parenthesis < 0)
561
- return;
562
- break;
563
- default:
564
- for (const separator of separators) {
565
- const separatorLength = separator.length;
566
- if (separatorLength && separator === str.slice(i, i + separatorLength) && parenthesis === 0) {
567
- if (i === 0 || i === l - separatorLength)
568
- return;
569
- return [
570
- str.slice(0, i),
571
- str.slice(i + separatorLength)
572
- ];
573
- }
574
- }
575
- }
576
- }
577
- return [
578
- str,
579
- ""
580
- ];
581
- }
582
- function getComponents(str, separators, limit) {
583
- limit = limit ?? 10;
584
- const components = [];
585
- let i = 0;
586
- while (str !== "") {
587
- if (++i > limit)
588
- return;
589
- const componentPair = getComponent(str, "(", ")", separators);
590
- if (!componentPair)
591
- return;
592
- const [component, rest] = componentPair;
593
- components.push(component);
594
- str = rest;
595
- }
596
- if (components.length > 0)
597
- return components;
598
- }
599
-
600
- const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
601
- const alphaPlaceholders = ["%alpha", "<alpha-value>"];
602
- const alphaPlaceholdersRE = new RegExp(alphaPlaceholders.map((v) => core.escapeRegExp(v)).join("|"));
603
- function hex2rgba(hex = "") {
604
- const color = parseHexColor(hex);
605
- if (color != null) {
606
- const { components, alpha } = color;
607
- if (alpha == null)
608
- return components;
609
- return [...components, alpha];
610
- }
611
- }
612
- function parseCssColor(str = "") {
613
- const color = parseColor(str);
614
- if (color == null || color === false)
615
- return;
616
- const { type: casedType, components, alpha } = color;
617
- const type = casedType.toLowerCase();
618
- if (components.length === 0)
619
- return;
620
- if (["rgba", "hsla"].includes(type) && alpha == null)
621
- return;
622
- if (cssColorFunctions.includes(type) && ![1, 3].includes(components.length))
623
- return;
624
- return {
625
- type,
626
- components: components.map((c) => typeof c === "string" ? c.trim() : c),
627
- alpha: typeof alpha === "string" ? alpha.trim() : alpha
628
- };
629
- }
630
- function colorOpacityToString(color) {
631
- const alpha = color.alpha ?? 1;
632
- return typeof alpha === "string" && alphaPlaceholders.includes(alpha) ? 1 : alpha;
633
- }
634
- function colorToString(color, alphaOverride) {
635
- if (typeof color === "string")
636
- return color.replace(alphaPlaceholdersRE, `${alphaOverride ?? 1}`);
637
- const { components } = color;
638
- let { alpha, type } = color;
639
- alpha = alphaOverride ?? alpha;
640
- type = type.toLowerCase();
641
- if (["hsla", "hsl", "rgba", "rgb"].includes(type))
642
- return `${type.replace("a", "")}a(${components.join(",")}${alpha == null ? "" : `,${alpha}`})`;
643
- alpha = alpha == null ? "" : ` / ${alpha}`;
644
- if (cssColorFunctions.includes(type))
645
- return `${type}(${components.join(" ")}${alpha})`;
646
- return `color(${type} ${components.join(" ")}${alpha})`;
647
- }
648
- function parseColor(str) {
649
- if (!str)
650
- return;
651
- let color = parseHexColor(str);
652
- if (color != null)
653
- return color;
654
- color = cssColorKeyword(str);
655
- if (color != null)
656
- return color;
657
- color = parseCssCommaColorFunction(str);
658
- if (color != null)
659
- return color;
660
- color = parseCssSpaceColorFunction(str);
661
- if (color != null)
662
- return color;
663
- color = parseCssColorFunction(str);
664
- if (color != null)
665
- return color;
666
- }
667
- function parseHexColor(str) {
668
- const [, body] = str.match(/^#([\da-f]+)$/i) || [];
669
- if (!body)
670
- return;
671
- switch (body.length) {
672
- case 3:
673
- case 4:
674
- const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
675
- return {
676
- type: "rgb",
677
- components: digits.slice(0, 3),
678
- alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
679
- };
680
- case 6:
681
- case 8:
682
- const value = Number.parseInt(body, 16);
683
- return {
684
- type: "rgb",
685
- components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
686
- alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
687
- };
688
- }
689
- }
690
- function cssColorKeyword(str) {
691
- const color = {
692
- rebeccapurple: [102, 51, 153, 1]
693
- }[str];
694
- if (color != null) {
695
- return {
696
- type: "rgb",
697
- components: color.slice(0, 3),
698
- alpha: color[3]
699
- };
700
- }
701
- }
702
- function parseCssCommaColorFunction(color) {
703
- const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
704
- if (!match)
705
- return;
706
- const [, type, componentString] = match;
707
- const components = getComponents(componentString, ",", 5);
708
- if (components) {
709
- if ([3, 4].includes(components.length)) {
710
- return {
711
- type,
712
- components: components.slice(0, 3),
713
- alpha: components[3]
714
- };
715
- } else if (components.length !== 1) {
716
- return false;
717
- }
718
- }
719
- }
720
- const cssColorFunctionsRe = new RegExp(`^(${cssColorFunctions.join("|")})\\((.+)\\)$`, "i");
721
- function parseCssSpaceColorFunction(color) {
722
- const match = color.match(cssColorFunctionsRe);
723
- if (!match)
724
- return;
725
- const [, fn, componentString] = match;
726
- const parsed = parseCssSpaceColorValues(`${fn} ${componentString}`);
727
- if (parsed) {
728
- const { alpha, components: [type, ...components] } = parsed;
729
- return {
730
- type,
731
- components,
732
- alpha
733
- };
734
- }
735
- }
736
- function parseCssColorFunction(color) {
737
- const match = color.match(/^color\((.+)\)$/);
738
- if (!match)
739
- return;
740
- const parsed = parseCssSpaceColorValues(match[1]);
741
- if (parsed) {
742
- const { alpha, components: [type, ...components] } = parsed;
743
- return {
744
- type,
745
- components,
746
- alpha
747
- };
748
- }
749
- }
750
- function parseCssSpaceColorValues(componentString) {
751
- const components = getComponents(componentString, " ");
752
- if (!components)
753
- return;
754
- let totalComponents = components.length;
755
- if (components[totalComponents - 2] === "/") {
756
- return {
757
- components: components.slice(0, totalComponents - 2),
758
- alpha: components[totalComponents - 1]
759
- };
760
- }
761
- if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
762
- const removed = components.splice(totalComponents - 2);
763
- components.push(removed.join(" "));
764
- --totalComponents;
765
- }
766
- const withAlpha = getComponents(components[totalComponents - 1], "/", 2);
767
- if (!withAlpha)
768
- return;
769
- if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "")
770
- return { components };
771
- const alpha = withAlpha.pop();
772
- components[totalComponents - 1] = withAlpha.join("/");
773
- return {
774
- components,
775
- alpha
776
- };
777
- }
778
515
 
779
516
  exports.CONTROL_MINI_NO_NEGATIVE = CONTROL_MINI_NO_NEGATIVE;
780
- exports.colorOpacityToString = colorOpacityToString;
781
517
  exports.colorResolver = colorResolver;
782
- exports.colorToString = colorToString;
783
518
  exports.colorableShadows = colorableShadows;
784
519
  exports.cornerMap = cornerMap;
785
520
  exports.directionMap = directionMap;
786
521
  exports.directionSize = directionSize;
787
- exports.getBracket = getBracket;
788
- exports.getComponent = getComponent;
789
- exports.getComponents = getComponents;
790
522
  exports.globalKeywords = globalKeywords;
791
523
  exports.h = h;
792
524
  exports.handler = handler;
793
525
  exports.hasParseableColor = hasParseableColor;
794
- exports.hex2rgba = hex2rgba;
795
526
  exports.insetMap = insetMap;
796
527
  exports.makeGlobalStaticRules = makeGlobalStaticRules;
797
528
  exports.numberWithUnitRE = numberWithUnitRE;
798
- exports.parseColor = parseColor$1;
799
- exports.parseCssColor = parseCssColor;
529
+ exports.parseColor = parseColor;
800
530
  exports.positionMap = positionMap;
801
531
  exports.resolveBreakpoints = resolveBreakpoints;
802
532
  exports.resolveVerticalBreakpoints = resolveVerticalBreakpoints;
@@ -1,4 +1,4 @@
1
- import { h, m as makeGlobalStaticRules, g as globalKeywords, c as colorResolver, a as hasParseableColor, b as colorableShadows, d as positionMap, x as xyzMap } from './preset-mini.f1fe435e.mjs';
1
+ import { h, m as makeGlobalStaticRules, g as globalKeywords, c as colorResolver, a as hasParseableColor, b as colorableShadows, d as positionMap, x as xyzMap } from './preset-mini.8929b018.mjs';
2
2
 
3
3
  const cursorValues = ["auto", "default", "none", "context-menu", "help", "pointer", "progress", "wait", "cell", "crosshair", "text", "vertical-text", "alias", "copy", "move", "no-drop", "not-allowed", "grab", "grabbing", "all-scroll", "col-resize", "row-resize", "n-resize", "e-resize", "s-resize", "w-resize", "ne-resize", "nw-resize", "se-resize", "sw-resize", "ew-resize", "ns-resize", "nesw-resize", "nwse-resize", "zoom-in", "zoom-out"];
4
4
  const containValues = ["none", "strict", "content", "size", "inline-size", "layout", "style", "paint"];
@@ -110,13 +110,11 @@ const fontStyles = [
110
110
  const fontSmoothings = [
111
111
  ["antialiased", {
112
112
  "-webkit-font-smoothing": "antialiased",
113
- "-moz-osx-font-smoothing": "grayscale",
114
- "font-smoothing": "grayscale"
113
+ "-moz-osx-font-smoothing": "grayscale"
115
114
  }],
116
115
  ["subpixel-antialiased", {
117
116
  "-webkit-font-smoothing": "auto",
118
- "-moz-osx-font-smoothing": "auto",
119
- "font-smoothing": "auto"
117
+ "-moz-osx-font-smoothing": "auto"
120
118
  }]
121
119
  ];
122
120
 
@@ -51,8 +51,8 @@ declare function parseColor(body: string, theme: Theme): ParsedColorValue | unde
51
51
  *
52
52
  * @param {string} property - Property for the css value to be created.
53
53
  * @param {string} varName - Base name for the opacity variable.
54
- * @param {function} [shouldPass] - Function to decide whether to pass the css.
55
- * @return {@link DynamicMatcher} object.
54
+ * @param {Function} [shouldPass] - Function to decide whether to pass the css.
55
+ * @return {DynamicMatcher} object.
56
56
  */
57
57
  declare function colorResolver(property: string, varName: string, shouldPass?: (css: CSSObject) => boolean): DynamicMatcher;
58
58
  declare function colorableShadows(shadows: string | string[], colorVar: string): string[];
@@ -60,8 +60,5 @@ declare function hasParseableColor(color: string | undefined, theme: Theme): boo
60
60
  declare function resolveBreakpoints({ theme, generator }: Readonly<VariantContext<Theme>>): Record<string, string> | undefined;
61
61
  declare function resolveVerticalBreakpoints({ theme, generator }: Readonly<VariantContext<Theme>>): Record<string, string> | undefined;
62
62
  declare function makeGlobalStaticRules(prefix: string, property?: string): StaticRule[];
63
- declare function getBracket(str: string, open: string, close: string): string[] | undefined;
64
- declare function getComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
65
- declare function getComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
66
63
 
67
- export { CONTROL_MINI_NO_NEGATIVE as C, colorableShadows as a, resolveVerticalBreakpoints as b, colorResolver as c, directionSize as d, getComponent as e, getComponents as f, getBracket as g, hasParseableColor as h, makeGlobalStaticRules as m, parseColor as p, resolveBreakpoints as r, splitShorthand as s };
64
+ export { CONTROL_MINI_NO_NEGATIVE as C, colorableShadows as a, resolveVerticalBreakpoints as b, colorResolver as c, directionSize as d, hasParseableColor as h, makeGlobalStaticRules as m, parseColor as p, resolveBreakpoints as r, splitShorthand as s };