@unocss/preset-wind4
Version:
Tailwind 4 compact preset for UnoCSS
1,376 lines • 110 kB
JavaScript
import { A as bracketTypeRe, B as xyzMap, D as h, F as directionMap, I as globalKeywords, L as insetMap, M as cornerMap, R as positionMap, S as parseColor, U as SpecialColorKey, V as CONTROL_NO_NEGATIVE, _ as hyphenate, a as themeTracking, b as makeGlobalStaticRules, d as colorableShadows, g as hasParseableColor, j as splitComma, l as colorCSSGenerator, m as directionSize, n as detectThemeValue, p as defineProperty, r as generateThemeVariable, u as colorResolver, v as isCSSMathFn, w as resolveBreakpoints, x as numberResolver, y as isSize, z as xyzArray } from "./utils-CqAvZsCu.mjs";
import { n as containerParent, r as containerShortcuts, t as container } from "./container-BwY4Hhe2.mjs";
import { notNull, symbols } from "@unocss/core";
import { getStringComponent, getStringComponents } from "@unocss/rule-utils";
//#region src/rules/align.ts
const verticalAlignAlias = {
"mid": "middle",
"base": "baseline",
"btm": "bottom",
"baseline": "baseline",
"top": "top",
"start": "top",
"middle": "middle",
"bottom": "bottom",
"end": "bottom",
"text-top": "text-top",
"text-bottom": "text-bottom",
"sub": "sub",
"super": "super",
...Object.fromEntries(globalKeywords.map((x) => [x, x]))
};
const verticalAligns = [[
/^(?:vertical|align|v)-(.+)$/,
([, v], { theme }) => ({ "vertical-align": verticalAlignAlias[v] ?? h.bracket.cssvar.numberWithUnit(v, theme) }),
{ autocomplete: [`(vertical|align|v)-(${Object.keys(verticalAlignAlias).join("|")})`, "(vertical|align|v)-<percentage>"] }
]];
const textAlignValues = [
"center",
"left",
"right",
"justify",
"start",
"end"
];
const textAligns = [...textAlignValues.map((v) => [`text-${v}`, { "text-align": v }]), ...[...globalKeywords, ...textAlignValues].map((v) => [`text-align-${v}`, { "text-align": v }])];
//#endregion
//#region src/rules/animation.ts
const animations = [
[
/^(?:animate-)?keyframes-(.+)$/,
([, name], { theme }) => {
const kf = theme.animation?.keyframes?.[name];
if (kf) return [`@keyframes ${name}${kf}`, { animation: name }];
},
{ autocomplete: ["animate-keyframes-$animation.keyframes", "keyframes-$animation.keyframes"] }
],
[
/^animate-(.+)$/,
([, name], { theme }) => {
const kf = theme.animation?.keyframes?.[name];
if (kf) {
const duration = theme.animation?.durations?.[name] ?? "1s";
const timing = theme.animation?.timingFns?.[name] ?? "linear";
const count = theme.animation?.counts?.[name] ?? 1;
const props = theme.animation?.properties?.[name];
return [`@keyframes ${name}${kf}`, {
animation: `${name} ${duration} ${timing} ${count}`,
...props
}];
}
return { animation: h.bracket.cssvar(name, theme) };
},
{ autocomplete: "animate-$animation.keyframes" }
],
[/^animate-name-(.+)/, ([, d], { theme }) => ({ "animation-name": h.bracket.cssvar(d, theme) ?? d })],
[
/^animate-duration-(.+)$/,
([, d], { theme }) => ({ "animation-duration": theme.duration?.[d || "DEFAULT"] ?? h.bracket.cssvar.time(d, theme) }),
{ autocomplete: ["animate-duration"] }
],
[
/^animate-delay-(.+)$/,
([, d], { theme }) => ({ "animation-delay": theme.duration?.[d || "DEFAULT"] ?? h.bracket.cssvar.time(d, theme) }),
{ autocomplete: ["animate-delay"] }
],
[
/^animate-ease(?:-(.+))?$/,
([, d], { theme }) => ({ "animation-timing-function": theme.ease?.[d || "DEFAULT"] ?? h.bracket.cssvar(d, theme) }),
{ autocomplete: ["animate-ease", "animate-ease-$ease"] }
],
[
/^animate-(fill-mode-|fill-|mode-)?(.+)$/,
([, t, d]) => [
"none",
"forwards",
"backwards",
"both",
...[t ? globalKeywords : []]
].includes(d) ? { "animation-fill-mode": d } : void 0,
{ autocomplete: [
"animate-(fill|mode|fill-mode)",
"animate-(fill|mode|fill-mode)-(none|forwards|backwards|both|inherit|initial|revert|revert-layer|unset)",
"animate-(none|forwards|backwards|both|inherit|initial|revert|revert-layer|unset)"
] }
],
[
/^animate-(direction-)?(.+)$/,
([, t, d]) => [
"normal",
"reverse",
"alternate",
"alternate-reverse",
...[t ? globalKeywords : []]
].includes(d) ? { "animation-direction": d } : void 0,
{ autocomplete: [
"animate-direction",
"animate-direction-(normal|reverse|alternate|alternate-reverse|inherit|initial|revert|revert-layer|unset)",
"animate-(normal|reverse|alternate|alternate-reverse|inherit|initial|revert|revert-layer|unset)"
] }
],
[
/^animate-(?:iteration-count-|iteration-|count-)(.+)$/,
([, d], { theme }) => ({ "animation-iteration-count": h.bracket.cssvar(d, theme) ?? d.replace(/-/g, ",") }),
{ autocomplete: ["animate-(iteration|count|iteration-count)", "animate-(iteration|count|iteration-count)-<num>"] }
],
[
/^animate-(play-state-|play-|state-)?(.+)$/,
([, t, d]) => [
"paused",
"running",
...[t ? globalKeywords : []]
].includes(d) ? { "animation-play-state": d } : void 0,
{ autocomplete: [
"animate-(play|state|play-state)",
"animate-(play|state|play-state)-(paused|running|inherit|initial|revert|revert-layer|unset)",
"animate-(paused|running|inherit|initial|revert|revert-layer|unset)"
] }
],
["animate-none", { animation: "none" }],
...makeGlobalStaticRules("animate", "animation")
];
//#endregion
//#region src/rules/background.ts
const properties = {
"gradient-position": defineProperty("--un-gradient-position"),
"gradient-from": defineProperty("--un-gradient-from", {
syntax: "<color>",
initialValue: "#0000"
}),
"gradient-via": defineProperty("--un-gradient-via", {
syntax: "<color>",
initialValue: "#0000"
}),
"gradient-to": defineProperty("--un-gradient-to", {
syntax: "<color>",
initialValue: "#0000"
}),
"gradient-stops": defineProperty("--un-gradient-stops"),
"gradient-via-stops": defineProperty("--un-gradient-via-stops"),
"gradient-from-position": defineProperty("--un-gradient-from-position", {
syntax: "<length-percentage>",
initialValue: "0%"
}),
"gradient-via-position": defineProperty("--un-gradient-via-position", {
syntax: "<length-percentage>",
initialValue: "50%"
}),
"gradient-to-position": defineProperty("--un-gradient-to-position", {
syntax: "<length-percentage>",
initialValue: "100%"
})
};
function resolveModifier(modifier) {
let interpolationMethod = "in oklab";
if (modifier) if (modifier.startsWith("[") && modifier.endsWith("]")) interpolationMethod = modifier.slice(1, -1);
else switch (modifier) {
case "longer":
case "shorter":
case "increasing":
case "decreasing":
interpolationMethod = `in oklch ${modifier} hue`;
break;
default: interpolationMethod = `in ${modifier}`;
}
return interpolationMethod;
}
function bgGradientColorResolver() {
return function* ([, position, body], { theme }) {
const css = {};
const data = parseColor(body, theme);
if (data) {
const { color, keys, alpha } = data;
if (color) {
if (Object.values(SpecialColorKey).includes(color)) css[`--un-gradient-${position}`] = color;
else {
css[`--un-${position}-opacity`] = alpha;
const value = keys ? generateThemeVariable("colors", keys) : color;
css[`--un-gradient-${position}`] = `color-mix(in oklab, ${value} var(--un-${position}-opacity), transparent)`;
yield defineProperty(`--un-${position}-opacity`, {
syntax: "<percentage>",
initialValue: "100%"
});
}
if (keys) themeTracking(`colors`, keys);
if (theme) detectThemeValue(color, theme);
}
} else css[`--un-gradient-${position}`] = h.bracket.cssvar(body, theme);
if (css[`--un-gradient-${position}`]) {
switch (position) {
case "from":
yield {
...css,
"--un-gradient-stops": "var(--un-gradient-via-stops, var(--un-gradient-position), var(--un-gradient-from) var(--un-gradient-from-position), var(--un-gradient-to) var(--un-gradient-to-position))"
};
break;
case "via":
yield {
...css,
"--un-gradient-via-stops": `var(--un-gradient-position), var(--un-gradient-from) var(--un-gradient-from-position), var(--un-gradient-via) var(--un-gradient-via-position), var(--un-gradient-to) var(--un-gradient-to-position)`,
"--un-gradient-stops": `var(--un-gradient-via-stops)`
};
break;
case "to":
yield {
...css,
"--un-gradient-stops": "var(--un-gradient-via-stops, var(--un-gradient-position), var(--un-gradient-from) var(--un-gradient-from-position), var(--un-gradient-to) var(--un-gradient-to-position))"
};
break;
case "stops":
yield { ...css };
break;
}
for (const p of Object.values(properties)) yield p;
}
};
}
function bgGradientPositionResolver() {
return function* ([, mode, body], { theme }) {
yield { [`--un-gradient-${mode}-position`]: `${h.bracket.cssvar.percent(body, theme)}` };
for (const p of Object.values(properties)) yield p;
};
}
const backgroundStyles = [
[
/^bg-(linear|radial|conic)-([^/]+)(?:\/(.+))?$/,
([, m, d, s], { theme }) => {
let v;
if (h.number(d) != null) v = `from ${h.number(d)}deg ${resolveModifier(s)};`;
else v = h.bracket(d, theme);
if (v) return {
"--un-gradient-position": v,
"background-image": `${m}-gradient(var(--un-gradient-stops))`
};
},
{ autocomplete: [
"bg-(linear|radial|conic)",
"(from|to|via)-$colors",
"(from|to|via)-(op|opacity)",
"(from|to|via)-(op|opacity)-<percent>"
] }
],
[/^(from|via|to|stops)-(.+)$/, bgGradientColorResolver()],
[/^(from|via|to)-op(?:acity)?-?(.+)$/, ([, position, opacity], { theme }) => ({ [`--un-${position}-opacity`]: h.bracket.percent(opacity, theme) })],
[/^(from|via|to)-([\d.]+%)$/, bgGradientPositionResolver()],
[
/^bg-((?:repeating-)?(?:linear|radial|conic))$/,
([, s]) => ({ "background-image": `${s}-gradient(var(--un-gradient, var(--un-gradient-stops, rgb(255 255 255 / 0))))` }),
{ autocomplete: [
"bg-gradient-repeating",
"bg-gradient-(linear|radial|conic)",
"bg-gradient-repeating-(linear|radial|conic)"
] }
],
[
/^bg-(gradient|linear|radial|conic)(?:-to-([rltb]{1,2}))?(?:\/(.+))?$/,
([, m, d, s]) => {
return {
"--un-gradient-position": `${d in positionMap ? `to ${positionMap[d]} ` : " "}${resolveModifier(s)}`,
"background-image": `${m === "gradient" ? "linear" : m}-gradient(var(--un-gradient-stops))`
};
},
{ autocomplete: [
"gradient",
"linear",
"radial",
"conic"
].map((i) => {
return `bg-${i}-to-(${Object.keys(positionMap).filter((k) => k.length <= 2 && Array.from(k).every((c) => "rltb".includes(c))).join("|")})`;
}) }
],
["bg-none", { "background-image": "none" }],
["box-decoration-slice", { "box-decoration-break": "slice" }],
["box-decoration-clone", { "box-decoration-break": "clone" }],
...makeGlobalStaticRules("box-decoration", "box-decoration-break"),
["bg-auto", { "background-size": "auto" }],
["bg-cover", { "background-size": "cover" }],
["bg-contain", { "background-size": "contain" }],
[/^bg-size-(.+)$/, ([, v], { theme }) => ({ "background-size": h.bracket.cssvar(v, theme) })],
["bg-fixed", { "background-attachment": "fixed" }],
["bg-local", { "background-attachment": "local" }],
["bg-scroll", { "background-attachment": "scroll" }],
["bg-clip-border", {
"-webkit-background-clip": "border-box",
"background-clip": "border-box"
}],
["bg-clip-content", {
"-webkit-background-clip": "content-box",
"background-clip": "content-box"
}],
["bg-clip-padding", {
"-webkit-background-clip": "padding-box",
"background-clip": "padding-box"
}],
["bg-clip-text", {
"-webkit-background-clip": "text",
"background-clip": "text"
}],
...globalKeywords.map((keyword) => [`bg-clip-${keyword}`, {
"-webkit-background-clip": keyword,
"background-clip": keyword
}]),
[/^bg-([-\w]{3,})$/, ([, s]) => ({ "background-position": positionMap[s] })],
["bg-repeat", { "background-repeat": "repeat" }],
["bg-no-repeat", { "background-repeat": "no-repeat" }],
["bg-repeat-x", { "background-repeat": "repeat-x" }],
["bg-repeat-y", { "background-repeat": "repeat-y" }],
["bg-repeat-round", { "background-repeat": "round" }],
["bg-repeat-space", { "background-repeat": "space" }],
...makeGlobalStaticRules("bg-repeat", "background-repeat"),
["bg-origin-border", { "background-origin": "border-box" }],
["bg-origin-padding", { "background-origin": "padding-box" }],
["bg-origin-content", { "background-origin": "content-box" }],
...makeGlobalStaticRules("bg-origin", "background-origin")
];
//#endregion
//#region src/rules/behaviors.ts
const outline = [
[
/^outline-(?:width-|size-)?(.+)$/,
handleWidth$2,
{ autocomplete: "outline-(width|size)-<num>" }
],
[
/^outline-(?:color-)?(.+)$/,
handleColorOrWidth$2,
{ autocomplete: "outline-$colors" }
],
[
/^outline-op(?:acity)?-?(.+)$/,
([, opacity], { theme }) => ({ "--un-outline-opacity": h.bracket.percent.cssvar(opacity, theme) }),
{ autocomplete: "outline-(op|opacity)-<percent>" }
],
[
/^outline-offset-(.+)$/,
([, d], { theme }) => ({ "outline-offset": h.bracket.cssvar.global.px(d, theme) }),
{ autocomplete: "outline-(offset)-<num>" }
],
["outline-offset-none", { "outline-offset": "0" }],
["outline", [{
"outline-style": "var(--un-outline-style)",
"outline-width": "1px"
}, defineProperty("--un-outline-style", { initialValue: "solid" })]],
["outline-hidden", [{ "outline-style": "none" }, {
[symbols.parent]: `@media (forced-colors: active)`,
"outline": `2px solid transparent`,
"outline-offset": `2px`
}]],
["outline-none", {
"--un-outline-style": "none",
"outline-style": "none"
}],
...[
"auto",
"dashed",
"dotted",
"double",
"solid",
"groove",
"ridge",
"inset",
"outset",
...globalKeywords
].map((v) => [`outline-${v}`, {
"--un-outline-style": v,
"outline-style": v
}])
];
function* handleWidth$2([, b], { theme }) {
const v = h.bracket.cssvar.global.px(b, theme);
if (v != null) {
yield {
"outline-style": "var(--un-outline-style)",
"outline-width": v
};
yield defineProperty("--un-outline-style", { initialValue: "solid" });
}
}
function* handleColorOrWidth$2(match, ctx) {
if (isCSSMathFn(h.bracket(match[1], ctx.theme))) yield* handleWidth$2(match, ctx);
else {
const result = colorResolver("outline-color", "outline")(match, ctx);
if (result) for (const i of result) yield i;
}
}
const appearance = [["appearance-auto", {
"-webkit-appearance": "auto",
"appearance": "auto"
}], ["appearance-none", {
"-webkit-appearance": "none",
"appearance": "none"
}]];
function willChangeProperty(prop, theme) {
const v = h.bracket(prop, theme);
if (v && h.properties(v)) return v;
return h.properties.auto.cssvar.global(prop) ?? {
contents: "contents",
scroll: "scroll-position"
}[prop];
}
const willChange = [[/^will-change-(.+)/, ([, p], { theme }) => ({ "will-change": willChangeProperty(p, theme) })]];
const listStyles = {
"disc": "disc",
"circle": "circle",
"square": "square",
"decimal": "decimal",
"zero-decimal": "decimal-leading-zero",
"greek": "lower-greek",
"roman": "lower-roman",
"upper-roman": "upper-roman",
"alpha": "lower-alpha",
"upper-alpha": "upper-alpha",
"latin": "lower-latin",
"upper-latin": "upper-latin"
};
const listStyle = [
[
/^list-(.+?)(?:-(outside|inside))?$/,
([, alias, position]) => {
const style = listStyles[alias];
if (style) {
if (position) return {
"list-style-position": position,
"list-style-type": style
};
return { "list-style-type": style };
}
},
{ autocomplete: [`list-(${Object.keys(listStyles).join("|")})`, `list-(${Object.keys(listStyles).join("|")})-(outside|inside)`] }
],
["list-outside", { "list-style-position": "outside" }],
["list-inside", { "list-style-position": "inside" }],
["list-none", { "list-style-type": "none" }],
[/^list-image-(.+)$/, ([, d], { theme }) => {
if (/^\[url\(.+\)\]$/.test(d)) return { "list-style-image": h.bracket(d, theme) };
}],
["list-image-none", { "list-style-image": "none" }],
...makeGlobalStaticRules("list", "list-style-type")
];
const accents = [[
/^accent-(.+)$/,
colorResolver("accent-color", "accent"),
{ autocomplete: "accent-$colors" }
], [
/^accent-op(?:acity)?-?(.+)$/,
([, d], { theme }) => ({ "--un-accent-opacity": h.bracket.percent(d, theme) }),
{ autocomplete: ["accent-(op|opacity)", "accent-(op|opacity)-<percent>"] }
]];
const carets = [[
/^caret-(.+)$/,
colorResolver("caret-color", "caret"),
{ autocomplete: "caret-$colors" }
], [
/^caret-op(?:acity)?-?(.+)$/,
([, d], { theme }) => ({ "--un-caret-opacity": h.bracket.percent(d, theme) }),
{ autocomplete: ["caret-(op|opacity)", "caret-(op|opacity)-<percent>"] }
]];
const imageRenderings = [
["image-render-auto", { "image-rendering": "auto" }],
["image-render-edge", { "image-rendering": "crisp-edges" }],
["image-render-pixel", [
["-ms-interpolation-mode", "nearest-neighbor"],
["image-rendering", "-webkit-optimize-contrast"],
["image-rendering", "-moz-crisp-edges"],
["image-rendering", "-o-pixelated"],
["image-rendering", "pixelated"]
]]
];
const overscrolls = [
["overscroll-auto", { "overscroll-behavior": "auto" }],
["overscroll-contain", { "overscroll-behavior": "contain" }],
["overscroll-none", { "overscroll-behavior": "none" }],
...makeGlobalStaticRules("overscroll", "overscroll-behavior"),
["overscroll-x-auto", { "overscroll-behavior-x": "auto" }],
["overscroll-x-contain", { "overscroll-behavior-x": "contain" }],
["overscroll-x-none", { "overscroll-behavior-x": "none" }],
...makeGlobalStaticRules("overscroll-x", "overscroll-behavior-x"),
["overscroll-y-auto", { "overscroll-behavior-y": "auto" }],
["overscroll-y-contain", { "overscroll-behavior-y": "contain" }],
["overscroll-y-none", { "overscroll-behavior-y": "none" }],
...makeGlobalStaticRules("overscroll-y", "overscroll-behavior-y")
];
const scrollBehaviors = [
["scroll-auto", { "scroll-behavior": "auto" }],
["scroll-smooth", { "scroll-behavior": "smooth" }],
...makeGlobalStaticRules("scroll", "scroll-behavior")
];
//#endregion
//#region src/rules/border.ts
const borderStyles = [
"solid",
"dashed",
"dotted",
"double",
"hidden",
"none",
"groove",
"ridge",
"inset",
"outset",
...globalKeywords
];
const borders = [
[
/^(?:border|b)()(?:-(.+))?$/,
handlerBorderSize,
{ autocomplete: "(border|b)-<directions>" }
],
[/^(?:border|b)-([xy])(?:-(.+))?$/, handlerBorderSize],
[/^(?:border|b)-([rltbse])(?:-(.+))?$/, handlerBorderSize],
[/^(?:border|b)-(block|inline)(?:-(.+))?$/, handlerBorderSize],
[/^(?:border|b)-([bi][se])(?:-(.+))?$/, handlerBorderSize],
[
/^(?:border|b)-()(?:width|size)-(.+)$/,
handlerBorderSize,
{ autocomplete: ["(border|b)-<num>", "(border|b)-<directions>-<num>"] }
],
[/^(?:border|b)-([xy])-(?:width|size)-(.+)$/, handlerBorderSize],
[/^(?:border|b)-([rltbse])-(?:width|size)-(.+)$/, handlerBorderSize],
[/^(?:border|b)-(block|inline)-(?:width|size)-(.+)$/, handlerBorderSize],
[/^(?:border|b)-([bi][se])-(?:width|size)-(.+)$/, handlerBorderSize],
[
/^(?:border|b)-()(?:color-)?(.+)$/,
handlerBorderColorOrSize,
{ autocomplete: ["(border|b)-$colors", "(border|b)-<directions>-$colors"] }
],
[/^(?:border|b)-([xy])-(?:color-)?(.+)$/, handlerBorderColorOrSize],
[/^(?:border|b)-([rltbse])-(?:color-)?(.+)$/, handlerBorderColorOrSize],
[/^(?:border|b)-(block|inline)-(?:color-)?(.+)$/, handlerBorderColorOrSize],
[/^(?:border|b)-([bi][se])-(?:color-)?(.+)$/, handlerBorderColorOrSize],
[
/^(?:border|b)-()op(?:acity)?-?(.+)$/,
handlerBorderOpacity,
{ autocomplete: "(border|b)-(op|opacity)-<percent>" }
],
[/^(?:border|b)-([xy])-op(?:acity)?-?(.+)$/, handlerBorderOpacity],
[/^(?:border|b)-([rltbse])-op(?:acity)?-?(.+)$/, handlerBorderOpacity],
[/^(?:border|b)-(block|inline)-op(?:acity)?-?(.+)$/, handlerBorderOpacity],
[/^(?:border|b)-([bi][se])-op(?:acity)?-?(.+)$/, handlerBorderOpacity],
[
/^(?:border-|b-)?(?:rounded|rd)()(?:-(.+))?$/,
handlerRounded,
{ autocomplete: [
"(border|b)-(rounded|rd)",
"(border|b)-(rounded|rd)-$radius",
"(rounded|rd)",
"(rounded|rd)-$radius"
] }
],
[/^(?:border-|b-)?(?:rounded|rd)-([rltbse])(?:-(.+))?$/, handlerRounded],
[/^(?:border-|b-)?(?:rounded|rd)-([rltb]{2})(?:-(.+))?$/, handlerRounded],
[/^(?:border-|b-)?(?:rounded|rd)-([bise][se])(?:-(.+))?$/, handlerRounded],
[/^(?:border-|b-)?(?:rounded|rd)-([bi][se]-[bi][se])(?:-(.+))?$/, handlerRounded],
[
/^(?:border|b)-(?:style-)?()(.+)$/,
handlerBorderStyle,
{ autocomplete: [
"(border|b)-style",
`(border|b)-(${borderStyles.join("|")})`,
"(border|b)-<directions>-style",
`(border|b)-<directions>-(${borderStyles.join("|")})`,
`(border|b)-<directions>-style-(${borderStyles.join("|")})`,
`(border|b)-style-(${borderStyles.join("|")})`
] }
],
[/^(?:border|b)-([xy])-(?:style-)?(.+)$/, handlerBorderStyle],
[/^(?:border|b)-([rltbse])-(?:style-)?(.+)$/, handlerBorderStyle],
[/^(?:border|b)-(block|inline)-(?:style-)?(.+)$/, handlerBorderStyle],
[/^(?:border|b)-([bi][se])-(?:style-)?(.+)$/, handlerBorderStyle]
];
function borderColorResolver(direction) {
return ([, body], ctx) => {
const data = parseColor(body, ctx.theme);
const result = colorCSSGenerator(data, `border${direction}-color`, `border${direction}`, ctx);
if (result) {
const css = result[0];
if (data?.color && !Object.values(SpecialColorKey).includes(data.color) && !data.alpha && direction && direction !== "") css[`--un-border${direction}-opacity`] = `var(--un-border-opacity)`;
return result;
}
};
}
function handlerBorderSize([, a = "", b = "1"], { theme }) {
const v = h.bracket.bracketOfLength.cssvar.global.px(b, theme);
if (a in directionMap && v != null) return directionMap[a].map((i) => [`border${i}-width`, v]);
}
function handlerBorderColorOrSize([, a = "", b], ctx) {
if (a in directionMap) {
if (isCSSMathFn(h.bracket(b, ctx.theme))) return handlerBorderSize([
"",
a,
b
], ctx);
const bracketColor = h.bracketOfColor(b, ctx.theme);
b = bracketColor ?? b;
if (bracketColor != null || hasParseableColor(b, ctx.theme)) {
const directions = directionMap[a].map((i) => borderColorResolver(i)(["", b], ctx) ?? colorCSSGenerator({
color: b,
name: "_"
}, `border${i}-color`, `border${i}`, ctx)).filter(notNull);
return [directions.map((d) => d[0]).reduce((acc, item) => {
Object.assign(acc, item);
return acc;
}, {}), ...directions.flatMap((d) => d.slice(1))];
}
}
}
function handlerBorderOpacity([, a = "", opacity], { theme }) {
const v = h.bracket.percent.cssvar(opacity, theme);
if (a in directionMap && v != null) return directionMap[a].map((i) => [`--un-border${i}-opacity`, v]);
}
function handlerRounded([, a = "", s = "DEFAULT"], { theme }) {
if (a in cornerMap) {
if (s === "full") return cornerMap[a].map((i) => [`border${i}-radius`, "calc(infinity * 1px)"]);
const _v = theme.radius?.[s] ?? h.bracket.cssvar.global.fraction.rem(s, theme);
if (_v != null) {
const isVar = theme.radius && s in theme.radius;
if (isVar) themeTracking(`radius`, s);
return cornerMap[a].map((i) => [`border${i}-radius`, isVar ? generateThemeVariable("radius", s) : _v]);
}
}
}
function handlerBorderStyle([, a = "", s]) {
if (borderStyles.includes(s) && a in directionMap) return [["--un-border-style", s], ...directionMap[a].map((i) => [`border${i}-style`, s])];
}
//#endregion
//#region src/rules/color.ts
/**
* @example op10 op-30 opacity-100
*/
const opacity = [[/^op(?:acity)?-?(.+)$/, ([, d], { theme }) => ({ opacity: h.bracket.percent.cssvar(d, theme) })]];
const bgUrlRE = /^\[url\(.+\)\]$/;
const bgLengthRE = /^\[(?:length|size):.+\]$/;
const bgPositionRE = /^\[position:.+\]$/;
const bgGradientRE = /^\[(?:linear|conic|radial)-gradient\(.+\)\]$/;
const bgImageRE = /^\[image:.+\]$/;
const bgColors = [[
/^bg-(.+)$/,
(match, ctx) => {
const d = match[1];
const { theme } = ctx;
if (bgUrlRE.test(d)) return {
"--un-url": h.bracket(d, theme),
"background-image": "var(--un-url)"
};
const bracketLength = h.bracketOfLength(d, theme);
if (bgLengthRE.test(d) && bracketLength != null) return { "background-size": bracketLength.split(" ").map((e) => h.fraction.auto.px.cssvar(e) ?? e).join(" ") };
const bracketPosition = h.bracketOfPosition(d, theme);
if ((isSize(d) || bgPositionRE.test(d)) && bracketPosition != null) return { "background-position": bracketPosition.split(" ").map((e) => h.position.fraction.auto.px.cssvar(e) ?? e).join(" ") };
if (bgGradientRE.test(d) || bgImageRE.test(d)) {
const s = h.bracket(d, theme);
if (s) return { "background-image": (s.startsWith("http") ? `url(${s})` : h.cssvar(s)) ?? s };
}
return colorResolver("background-color", "bg")(match, ctx);
},
{ autocomplete: "bg-$colors" }
], [
/^bg-op(?:acity)?-?(.+)$/,
([, opacity], { theme }) => ({ "--un-bg-opacity": h.bracket.percent.cssvar(opacity, theme) }),
{ autocomplete: "bg-(op|opacity)-<percent>" }
]];
const colorScheme = [[/^(?:color-)?scheme-(.+)$/, ([, v]) => ({ "color-scheme": v.split("-").join(" ") })]];
//#endregion
//#region src/rules/columns.ts
const columns = [
[
/^columns-(.+)$/,
([, v], { theme }) => {
if (theme.container && v in theme.container) {
themeTracking("container", v);
return { columns: generateThemeVariable("container", v) };
}
return { columns: h.bracket.numberWithUnit.number.cssvar(v, theme) };
},
{ autocomplete: ["columns-<num>", "columns-$container"] }
],
["columns-auto", { columns: "auto" }],
["break-before-auto", { "break-before": "auto" }],
["break-before-avoid", { "break-before": "avoid" }],
["break-before-all", { "break-before": "all" }],
["break-before-avoid-page", { "break-before": "avoid-page" }],
["break-before-page", { "break-before": "page" }],
["break-before-left", { "break-before": "left" }],
["break-before-right", { "break-before": "right" }],
["break-before-column", { "break-before": "column" }],
...makeGlobalStaticRules("break-before"),
["break-inside-auto", { "break-inside": "auto" }],
["break-inside-avoid", { "break-inside": "avoid" }],
["break-inside-avoid-page", { "break-inside": "avoid-page" }],
["break-inside-avoid-column", { "break-inside": "avoid-column" }],
...makeGlobalStaticRules("break-inside"),
["break-after-auto", { "break-after": "auto" }],
["break-after-avoid", { "break-after": "avoid" }],
["break-after-all", { "break-after": "all" }],
["break-after-avoid-page", { "break-after": "avoid-page" }],
["break-after-page", { "break-after": "page" }],
["break-after-left", { "break-after": "left" }],
["break-after-right", { "break-after": "right" }],
["break-after-column", { "break-after": "column" }],
...makeGlobalStaticRules("break-after")
];
//#endregion
//#region src/rules/decoration.ts
const decorationStyles = [
"solid",
"double",
"dotted",
"dashed",
"wavy",
...globalKeywords
];
const textDecorations = [
[
/^(?:decoration-)?(underline|overline|line-through)$/,
([, s]) => ({ "text-decoration-line": s }),
{ autocomplete: "decoration-(underline|overline|line-through)" }
],
[
/^(?:underline|decoration)-(?:size-)?(.+)$/,
handleWidth$1,
{ autocomplete: "(underline|decoration)-<num>" }
],
[
/^(?:underline|decoration)-(auto|from-font)$/,
([, s]) => ({ "text-decoration-thickness": s }),
{ autocomplete: "(underline|decoration)-(auto|from-font)" }
],
[
/^(?:underline|decoration)-(.+)$/,
handleColorOrWidth$1,
{ autocomplete: "(underline|decoration)-$colors" }
],
[
/^(?:underline|decoration)-op(?:acity)?-?(.+)$/,
([, opacity], { theme }) => ({ "--un-line-opacity": h.bracket.percent.cssvar(opacity, theme) }),
{ autocomplete: "(underline|decoration)-(op|opacity)-<percent>" }
],
[
/^(?:underline|decoration)-offset-(.+)$/,
([, s], { theme }) => ({ "text-underline-offset": h.auto.bracket.cssvar.global.px(s, theme) }),
{ autocomplete: "(underline|decoration)-(offset)-<num>" }
],
...decorationStyles.map((v) => [`underline-${v}`, { "text-decoration-style": v }]),
...decorationStyles.map((v) => [`decoration-${v}`, { "text-decoration-style": v }]),
["no-underline", { "text-decoration": "none" }],
["decoration-none", { "text-decoration": "none" }]
];
function handleWidth$1([, b], { theme }) {
return { "text-decoration-thickness": h.bracket.cssvar.global.px(b, theme) };
}
function handleColorOrWidth$1(match, ctx) {
if (isCSSMathFn(h.bracket(match[1], ctx.theme))) return handleWidth$1(match, ctx);
const result = colorResolver("text-decoration-color", "line")(match, ctx);
if (result) {
const css = result[0];
css["-webkit-text-decoration-color"] = css["text-decoration-color"];
return result;
}
}
//#endregion
//#region src/rules/spacing.ts
const paddings = [
[
/^pa?()-?(.+)$/,
directionSize("padding"),
{ autocomplete: ["(m|p)<num>", "(m|p)-<num>"] }
],
[
/^p-?xy()()$/,
directionSize("padding"),
{ autocomplete: "(m|p)-(xy)" }
],
[/^p-?([xy])(?:-?(.+))?$/, directionSize("padding")],
[
/^p-?([rltbse])(?:-?(.+))?$/,
directionSize("padding"),
{ autocomplete: "(m|p)<directions>-<num>" }
],
[
/^p-(block|inline)(?:-(.+))?$/,
directionSize("padding"),
{ autocomplete: "(m|p)-(block|inline)-<num>" }
],
[
/^p-?([bi][se])(?:-?(.+))?$/,
directionSize("padding"),
{ autocomplete: "(m|p)-(bs|be|is|ie)-<num>" }
]
];
const margins = [
[/^ma?()-?(.+)$/, directionSize("margin")],
[/^m-?xy()()$/, directionSize("margin")],
[/^m-?([xy])(?:-?(.+))?$/, directionSize("margin")],
[/^m-?([rltbse])(?:-?(.+))?$/, directionSize("margin")],
[/^m-(block|inline)(?:-(.+))?$/, directionSize("margin")],
[/^m-?([bi][se])(?:-?(.+))?$/, directionSize("margin")]
];
const spaces = [[
/^space-([xy])-(.+)$/,
handlerSpace,
{ autocomplete: [
"space-(x|y)",
"space-(x|y)-reverse",
"space-(x|y)-$spacing"
] }
], [/^space-([xy])-reverse$/, function* ([m, d], { symbols }) {
yield {
[symbols.variants]: [notLastChildSelectorVariant(m)],
[`--un-space-${d}-reverse`]: "1"
};
yield defineProperty(`--un-space-${d}-reverse`, { initialValue: 0 });
}]];
function notLastChildSelectorVariant(s) {
return {
matcher: s,
order: 1,
handle: (input, next) => next({
...input,
parent: `${input.parent ? `${input.parent} $$ ` : ""}${input.selector}`,
selector: ":where(&>:not(:last-child))"
})
};
}
function* handlerSpace([m, d, s], { theme, symbols }) {
let v;
const num = numberResolver(s);
if (num != null) {
themeTracking(`spacing`);
v = `calc(var(--spacing) * ${num})`;
} else v = theme.spacing?.[s] ?? h.bracket.cssvar.auto.fraction.rem(s || "1", theme);
if (v != null) {
const results = directionMap[d === "x" ? "inline" : "block"].map((item, index) => {
return [`margin${item}`, `calc(${v} * ${index === 0 ? `var(--un-space-${d}-reverse)` : `calc(1 - var(--un-space-${d}-reverse))`})`];
});
if (results) {
yield {
[symbols.variants]: [notLastChildSelectorVariant(m)],
[`--un-space-${d}-reverse`]: "0",
...Object.fromEntries(results)
};
yield defineProperty(`--un-space-${d}-reverse`, { initialValue: 0 });
}
}
}
//#endregion
//#region src/rules/divide.ts
const divides = [
[
/^divide-(.+)$/,
function* (match, ctx) {
const result = colorResolver("border-color", "divide")(match, ctx);
if (result) {
yield {
[ctx.symbols.variants]: [notLastChildSelectorVariant(match[0])],
...result[0]
};
yield result[1];
}
},
{ autocomplete: "divide-$colors" }
],
[
/^divide-op(?:acity)?-?(.+)$/,
function* ([match, opacity], { symbols, theme }) {
yield {
[symbols.variants]: [notLastChildSelectorVariant(match)],
"--un-divide-opacity": h.bracket.percent(opacity, theme)
};
},
{ autocomplete: ["divide-(op|opacity)", "divide-(op|opacity)-<percent>"] }
],
[
/^divide-?([xy])$/,
handlerDivide,
{ autocomplete: ["divide-(x|y)", "divide-(x|y)-reverse"] }
],
[/^divide-?([xy])-?(.+)$/, handlerDivide],
[/^divide-?([xy])-reverse$/, function* ([m, d], { symbols }) {
yield {
[symbols.variants]: [notLastChildSelectorVariant(m)],
[`--un-divide-${d}-reverse`]: "1"
};
yield defineProperty(`--un-divide-${d}-reverse`, { initialValue: 0 });
}],
[
new RegExp(`^divide-(${borderStyles.join("|")})$`),
function* ([match, style], { symbols }) {
yield {
[symbols.variants]: [notLastChildSelectorVariant(match)],
"border-style": style
};
},
{ autocomplete: borderStyles.map((i) => `divide-${i}`) }
]
];
function* handlerDivide([m, d, s], { symbols, theme }) {
let v = h.bracket.cssvar.px(s || "1", theme);
if (v != null) {
if (v === "0") v = "0px";
const results = {
x: ["-left", "-right"],
y: ["-top", "-bottom"]
}[d].map((item) => {
const value = item.endsWith("left") || item.endsWith("top") ? `calc(${v} * var(--un-divide-${d}-reverse))` : `calc(${v} * calc(1 - var(--un-divide-${d}-reverse)))`;
return [[`border${item}-width`, value], [`border${item}-style`, `var(--un-border-style)`]];
});
if (results) {
yield {
[symbols.variants]: [notLastChildSelectorVariant(m)],
[`--un-divide-${d}-reverse`]: 0,
...Object.fromEntries(results.flat())
};
yield defineProperty(`--un-divide-${d}-reverse`, { initialValue: 0 });
yield defineProperty(`--un-border-style`, { initialValue: "solid" });
}
}
}
//#endregion
//#region src/rules/filters.ts
const filterBaseKeys = [
"blur",
"brightness",
"contrast",
"grayscale",
"hue-rotate",
"invert",
"saturate",
"sepia",
"drop-shadow"
];
const filterProperties = filterBaseKeys.map((i) => defineProperty(`--un-${i}`));
const filterCSS = filterBaseKeys.map((i) => `var(--un-${i},)`).join(" ");
const backdropBaseKeys = [
"backdrop-blur",
"backdrop-brightness",
"backdrop-contrast",
"backdrop-grayscale",
"backdrop-hue-rotate",
"backdrop-invert",
"backdrop-opacity",
"backdrop-saturate",
"backdrop-sepia"
];
const backdropProperties = backdropBaseKeys.map((i) => defineProperty(`--un-${i}`));
const backdropCSS = backdropBaseKeys.map((i) => `var(--un-${i},)`).join(" ");
function percentWithDefault(str, theme) {
let v = h.bracket.cssvar(str || "", theme);
if (v != null) return v;
v = str ? h.percent(str) : "100%";
if (v != null && Number.parseFloat(v.slice(0, -1)) <= 100) return v;
}
function toFilter(varName, resolver) {
return ([, b, s], { theme }) => {
const value = resolver(s, theme) ?? (s === "none" ? "0" : "");
if (value !== "") if (b) return [{
[`--un-${b}${varName}`]: `${varName}(${value})`,
"-webkit-backdrop-filter": backdropCSS,
"backdrop-filter": backdropCSS
}, ...backdropProperties];
else return [{
[`--un-${varName}`]: `${varName}(${value})`,
filter: filterCSS
}, ...filterProperties];
};
}
function dropShadowResolver(match, ctx) {
const [, s] = match;
const { theme } = ctx;
let res = [];
if (s) {
res = getStringComponents(s, "/", 2) ?? [];
if (s.startsWith("/")) res = ["", s.slice(1)];
}
let v = theme.dropShadow?.[res[0] || "DEFAULT"];
const c = s ? h.bracket.cssvar(s, theme) : void 0;
if ((v != null || c != null) && !hasParseableColor(c, theme)) {
const alpha = res[1] ? h.bracket.percent.cssvar(res[1], theme) : void 0;
return [{
"--un-drop-shadow-opacity": alpha,
"--un-drop-shadow": `drop-shadow(${colorableShadows(v || c, "--un-drop-shadow-color", alpha).join(") drop-shadow(")})`,
"filter": filterCSS
}, ...filterProperties];
}
if (hasParseableColor(s, theme)) return colorResolver("--un-drop-shadow-color", "drop-shadow")(match, ctx);
v = h.bracket.cssvar(s, theme) ?? (s === "none" ? "" : void 0);
if (v != null) return [{
"--un-drop-shadow": v ? `drop-shadow(${v})` : v,
"filter": filterCSS
}, ...filterProperties];
}
const filters = [
[
/^(?:(backdrop-)|filter-)?blur(?:-(.+))?$/,
toFilter("blur", (s, theme) => theme.blur?.[s || "DEFAULT"] || h.bracket.cssvar.px(s, theme)),
{ autocomplete: [
"(backdrop|filter)-blur-$blur",
"blur-$blur",
"filter-blur"
] }
],
[
/^(?:(backdrop-)|filter-)?brightness-(.+)$/,
toFilter("brightness", (s, theme) => h.bracket.cssvar.percent(s, theme)),
{ autocomplete: ["(backdrop|filter)-brightness-<percent>", "brightness-<percent>"] }
],
[
/^(?:(backdrop-)|filter-)?contrast-(.+)$/,
toFilter("contrast", (s, theme) => h.bracket.cssvar.percent(s, theme)),
{ autocomplete: ["(backdrop|filter)-contrast-<percent>", "contrast-<percent>"] }
],
[
/^(?:filter-)?drop-shadow(?:-?(.+))?$/,
dropShadowResolver,
{ autocomplete: [
"filter-drop",
"filter-drop-shadow",
"filter-drop-shadow-color",
"drop-shadow",
"drop-shadow-color",
"filter-drop-shadow-$dropShadow",
"drop-shadow-$dropShadow",
"filter-drop-shadow-$colors",
"drop-shadow-$colors",
"filter-drop-shadow-color-$colors",
"drop-shadow-color-$colors",
"filter-drop-shadow-color-(op|opacity)",
"drop-shadow-color-(op|opacity)",
"filter-drop-shadow-color-(op|opacity)-<percent>",
"drop-shadow(-color)?-(op|opacity)-<percent>"
] }
],
[/^(?:filter-)?drop-shadow-color-(.+)$/, colorResolver("--un-drop-shadow-color", "drop-shadow")],
[/^(?:filter-)?drop-shadow(?:-color)?-op(?:acity)?-?(.+)$/, ([, opacity], { theme }) => ({ "--un-drop-shadow-opacity": h.bracket.percent(opacity, theme) })],
[
/^(?:(backdrop-)|filter-)?grayscale(?:-(.+))?$/,
toFilter("grayscale", percentWithDefault),
{ autocomplete: [
"(backdrop|filter)-grayscale",
"(backdrop|filter)-grayscale-<percent>",
"grayscale-<percent>"
] }
],
[/^(?:(backdrop-)|filter-)?hue-rotate-(.+)$/, toFilter("hue-rotate", (s, theme) => h.bracket.cssvar.degree(s, theme))],
[
/^(?:(backdrop-)|filter-)?invert(?:-(.+))?$/,
toFilter("invert", percentWithDefault),
{ autocomplete: [
"(backdrop|filter)-invert",
"(backdrop|filter)-invert-<percent>",
"invert-<percent>"
] }
],
[
/^(backdrop-)op(?:acity)?-(.+)$/,
toFilter("opacity", (s, theme) => h.bracket.cssvar.percent(s, theme)),
{ autocomplete: ["backdrop-(op|opacity)", "backdrop-(op|opacity)-<percent>"] }
],
[
/^(?:(backdrop-)|filter-)?saturate-(.+)$/,
toFilter("saturate", (s, theme) => h.bracket.cssvar.percent(s, theme)),
{ autocomplete: [
"(backdrop|filter)-saturate",
"(backdrop|filter)-saturate-<percent>",
"saturate-<percent>"
] }
],
[
/^(?:(backdrop-)|filter-)?sepia(?:-(.+))?$/,
toFilter("sepia", percentWithDefault),
{ autocomplete: [
"(backdrop|filter)-sepia",
"(backdrop|filter)-sepia-<percent>",
"sepia-<percent>"
] }
],
["filter", { filter: filterCSS }],
["backdrop-filter", {
"-webkit-backdrop-filter": backdropCSS,
"backdrop-filter": backdropCSS
}],
["filter-none", { filter: "none" }],
["backdrop-filter-none", {
"-webkit-backdrop-filter": "none",
"backdrop-filter": "none"
}],
...globalKeywords.map((keyword) => [`filter-${keyword}`, { filter: keyword }]),
...globalKeywords.map((keyword) => [`backdrop-filter-${keyword}`, {
"-webkit-backdrop-filter": keyword,
"backdrop-filter": keyword
}])
];
//#endregion
//#region src/rules/flex.ts
const flex = [
["flex", { display: "flex" }],
["inline-flex", { display: "inline-flex" }],
["flex-inline", { display: "inline-flex" }],
[/^flex-(.*)$/, ([, d], { theme }) => {
const value = h.bracket(d, theme);
return { flex: value != null ? value.split(" ").map((e) => h.cssvar.fraction(e) ?? e).join(" ") : h.cssvar.fraction(d) };
}],
["flex-1", { flex: "1 1 0%" }],
["flex-auto", { flex: "1 1 auto" }],
["flex-initial", { flex: "0 1 auto" }],
["flex-none", { flex: "none" }],
[
/^(?:flex-)?shrink(?:-(.*))?$/,
([, d = ""], { theme }) => ({ "flex-shrink": h.bracket.cssvar.number(d, theme) ?? 1 }),
{ autocomplete: ["flex-shrink-<num>", "shrink-<num>"] }
],
[
/^(?:flex-)?grow(?:-(.*))?$/,
([, d = ""], { theme }) => ({ "flex-grow": h.bracket.cssvar.number(d, theme) ?? 1 }),
{ autocomplete: ["flex-grow-<num>", "grow-<num>"] }
],
[
/^(?:flex-)?basis-(.+)$/,
([, d], { theme }) => {
const v = numberResolver(d);
if (v != null) {
themeTracking(`spacing`);
return { "flex-basis": `calc(var(--spacing) * ${v})` };
}
return { "flex-basis": h.bracket.cssvar.auto.fraction.rem(d, theme) };
},
{ autocomplete: ["flex-basis-$spacing", "basis-$spacing"] }
],
["flex-row", { "flex-direction": "row" }],
["flex-row-reverse", { "flex-direction": "row-reverse" }],
["flex-col", { "flex-direction": "column" }],
["flex-col-reverse", { "flex-direction": "column-reverse" }],
["flex-wrap", { "flex-wrap": "wrap" }],
["flex-wrap-reverse", { "flex-wrap": "wrap-reverse" }],
["flex-nowrap", { "flex-wrap": "nowrap" }]
];
//#endregion
//#region src/rules/gap.ts
const directions = {
"": [""],
"x": ["column-"],
"y": ["row-"],
"col": ["column-"],
"row": ["row-"]
};
const gaps = [
[
/^(?:flex-|grid-)?gap-?()(.+)$/,
directionSize("gap", directions, (p, i) => `${i}${p}`),
{ autocomplete: ["gap-$spacing", "gap-<num>"] }
],
[
/^(?:flex-|grid-)?gap-([xy])-?(.+)$/,
directionSize("gap", directions, (p, i) => `${i}${p}`),
{ autocomplete: ["gap-(x|y)-$spacing", "gap-(x|y)-<num>"] }
],
[
/^(?:flex-|grid-)?gap-(col|row)-?(.+)$/,
directionSize("gap", directions, (p, i) => `${i}${p}`),
{ autocomplete: ["gap-(col|row)-$spacing", "gap-(col|row)-<num>"] }
]
];
//#endregion
//#region src/rules/grid.ts
function rowCol(s) {
return s.replace("col", "column");
}
function autoDirection(prop, theme) {
switch (prop) {
case "min": return "min-content";
case "max": return "max-content";
case "fr": return "minmax(0,1fr)";
}
return h.bracket.cssvar.auto.rem(prop, theme);
}
const grids = [
["grid", { display: "grid" }],
["inline-grid", { display: "inline-grid" }],
[/^(?:grid-)?(row|col)-(.+)$/, ([, c, v], { theme }) => ({ [`grid-${rowCol(c)}`]: h.bracket.number.cssvar.auto(v, theme) })],
[
/^(?:grid-)?(row|col)-span-(.+)$/,
([, c, s], { theme }) => {
if (s === "full") return { [`grid-${rowCol(c)}`]: "1/-1" };
const v = h.bracket.number.cssvar(s, theme);
if (v != null) return { [`grid-${rowCol(c)}`]: `span ${v}/span ${v}` };
},
{ autocomplete: "(grid-row|grid-col|row|col)-span-<num>" }
],
[/^(?:grid-)?(row|col)-start-(.+)$/, ([, c, v], { theme }) => ({ [`grid-${rowCol(c)}-start`]: h.bracket.cssvar(v, theme) ?? v })],
[
/^(?:grid-)?(row|col)-end-(.+)$/,
([, c, v], { theme }) => ({ [`grid-${rowCol(c)}-end`]: h.bracket.cssvar(v, theme) ?? v }),
{ autocomplete: "(grid-row|grid-col|row|col)-(start|end)-<num>" }
],
[
/^(?:grid-)?auto-(rows|cols)-(.+)$/,
([, c, v], { theme }) => ({ [`grid-auto-${rowCol(c)}`]: autoDirection(v, theme) }),
{ autocomplete: "(grid-auto|auto)-(rows|cols)-<num>" }
],
[/^(?:grid-auto-flow|auto-flow|grid-flow)-(.+)$/, ([, v], { theme }) => ({ "grid-auto-flow": h.bracket.cssvar(v, theme) })],
[
/^(?:grid-auto-flow|auto-flow|grid-flow)-(row|col|dense|row-dense|col-dense)$/,
([, v]) => ({ "grid-auto-flow": rowCol(v).replace("-", " ") }),
{ autocomplete: ["(grid-auto-flow|auto-flow|grid-flow)-(row|col|dense|row-dense|col-dense)"] }
],
[/^(?:grid-)?(rows|cols)-(.+)$/, ([, c, v], { theme }) => ({ [`grid-template-${rowCol(c)}`]: h.bracket.cssvar(v, theme) })],
[/^(?:grid-)?(rows|cols)-minmax-([\w.-]+)$/, ([, c, d]) => ({ [`grid-template-${rowCol(c)}`]: `repeat(auto-fill,minmax(${d},1fr))` })],
[
/^(?:grid-)?(rows|cols)-(\d+)$/,
([, c, d]) => ({ [`grid-template-${rowCol(c)}`]: `repeat(${d},minmax(0,1fr))` }),
{ autocomplete: "(grid-rows|grid-cols|rows|cols)-<num>" }
],
[/^grid-area(s)?-(.+)$/, ([, s, v], { theme }) => {
if (s != null) return { "grid-template-areas": h.cssvar(v) ?? v.split("-").map((s) => `"${h.bracket(s, theme)}"`).join(" ") };
return { "grid-area": h.bracket.cssvar(v, theme) };
}],
["grid-rows-none", { "grid-template-rows": "none" }],
["grid-cols-none", { "grid-template-columns": "none" }],
["grid-rows-subgrid", { "grid-template-rows": "subgrid" }],
["grid-cols-subgrid", { "grid-template-columns": "subgrid" }]
];
//#endregion
//#region src/rules/layout.ts
const overflowValues = [
"auto",
"hidden",
"clip",
"visible",
"scroll",
"overlay",
...globalKeywords
];
const overflows = [[
/^(?:overflow|of)-(.+)$/,
([, v]) => overflowValues.includes(v) ? { overflow: v } : void 0,
{ autocomplete: [`(overflow|of)-(${overflowValues.join("|")})`, `(overflow|of)-(x|y)-(${overflowValues.join("|")})`] }
], [/^(?:overflow|of)-([xy])-(.+)$/, ([, d, v]) => overflowValues.includes(v) ? { [`overflow-${d}`]: v } : void 0]];
//#endregion
//#region src/rules/line-clamp.ts
const lineClamps = [[
/^line-clamp-(\d+)$/,
([, v]) => ({
"overflow": "hidden",
"display": "-webkit-box",
"-webkit-box-orient": "vertical",
"-webkit-line-clamp": v
}),
{ autocomplete: ["line-clamp", "line-clamp-(1|2|3|4|5|6|none)"] }
], ["line-clamp-none", {
"overflow": "visible",
"display": "block",
"-webkit-box-orient": "horizontal",
"-webkit-line-clamp": "unset"
}]];
//#endregion
//#region src/rules/mask.ts
const linearMap = {
t: ["top"],
b: ["bottom"],
l: ["left"],
r: ["right"],
x: ["left", "right"],
y: ["top", "bottom"]
};
const maskInitialValue = "linear-gradient(#fff, #fff)";
const baseMaskImage = {
"mask-image": "var(--un-mask-linear), var(--un-mask-radial), var(--un-mask-conic)",
"mask-composite": "intersect"
};
function handlePosition([, v = ""], ctx) {
if (v in cornerMap) return { "mask-position": v.split("").flatMap((c) => linearMap[c]).join(" ") };
const _v = h.bracket.cssvar.global.position(v, ctx?.theme);
if (_v !== null) return { "mask-position": _v };
}
function handleImage([_, gradient = "", direction, val], ctx) {
const css = { ...baseMaskImage };
const props = [];
props.push(...[
"linear",
"radial",
"conic"
].map((g) => defineProperty(`--un-mask-${g}`, { initialValue: maskInitialValue })));
if (gradient in linearMap) {
css["--un-mask-linear"] = "var(--un-mask-left), var(--un-mask-right), var(--un-mask-bottom), var(--un-mask-top)";
for (const dir of linearMap[gradient]) {
css[`--un-mask-${dir}`] = `linear-gradient(to ${dir}, var(--un-mask-${dir}-from-color) var(--un-mask-${dir}-from-position), var(--un-mask-${dir}-to-color) var(--un-mask-${dir}-to-position))`;
if (numberResolver(val) != null) {
themeTracking("spacing");
css[`--un-mask-${dir}-${direction}-position`] = `calc(var(--spacing) * ${h.bracket.cssvar.fraction.number(val, ctx.theme)})`;
} else css[`--un-mask-${dir}-${direction}-position`] = h.bracket.cssvar.fraction.rem(val, ctx.theme);
if (hasParseableColor(val, ctx.theme)) {
const result = colorResolver(`--un-mask-${dir}-${direction}-color`, hyphenate("colors"))([_, val], ctx);
if (result) {
const [c, ...p] = result;
Object.assign(css, c);
props.push(...p);
}
}
props.push(...["from", "to"].flatMap((p) => [defineProperty(`--un-mask-${dir}-${p}-position`, {
syntax: "<length-percentage>",
initialValue: p === "from" ? "0%" : "100%"
}), defineProperty(`--un-mask-${dir}-${p}-color`, {
syntax: "<color>",
initialValue: p === "from" ? "black" : "transparent"
})]));
}
props.push(...[
"top",
"right",
"bottom",
"left"
].map((d) => defineProperty(`--un-mask-${d}`, { initialValue: maskInitialValue })));
} else {
if (direction == null) if (gradient === "radial") {
css["--un-mask-radial"] = "radial-gradient(var(--un-mask-radial-stops, var(--un-mask-radial-size)))";
css["--un-mask-radial-size"] = h.bracket.cssvar.rem(val, ctx.theme);
} else {
css[`--un-mask-${gradient}`] = `${gradient}-gradient(var(--un-mask-${gradient}-stops, var(--un-mask-${gradient}-position)))`;
css[`--un-mask-${gradient}-position`] = numberResolver(val) ? `calc(1deg * ${h.bracket.cssvar.number(val, ctx.theme)})` : h.bracket.cssvar.fraction(val, ctx.theme);
}
else {
const gradientStopsPrefixMap = {
linear: "",
radial: "var(--un-mask-radial-shape) var(--un-mask-radial-size) at ",
conic: "from "
};
css[`--un-mask-${gradient}-stops`] = `${gradientStopsPrefixMap[gradient]}var(--un-mask-${gradient}-position), var(--un-mask-${gradient}-from-color) var(--un-mask-${gradient}-from-position), var(--un-mask-${gradient}-to-color) var(--un-mask-${gradient}-to-position)`;
css[`--un-mask-${gradient}`] = `${gradient}-gradient(var(--un-mask-${gradient}-stops))`;
if (hasParseableColor(val, ctx.theme)) {
const result = colorResolver(`--un-mask-${gradient}-${direction}-color`, hyphenate("colors"))([_, val], ctx);
if (result) {
const [c, ...p] = result;
Object.assign(css, c);
props.push(...p);
}
} else if (numberResolver(val) != null) {
themeTracking("spacing");
css[`--un-mask-${gradient}-${direction}-position`] = `calc(var(--spacing) * ${h.bracket.cssvar.fraction.number(val, ctx.theme)})`;
} else css[`--un-mask-${gradient}-${direction}-position`] = h.bracket.cssvar.fraction.rem(val, ctx.theme);
}
if (gradient === "radial") props.push(...[defineProperty("--un-mask-radial-shape", { initialValue: "ellipse" }), defineProperty("--un-mask-radial-size", { initialValue: "farthest-corner" })]);
props.push(...["from", "to"].flatMap((p) => [
defineProperty(`--un-mask-${gradient}-position`, { initialValue: gradient === "radial" ? "center" : "0deg" }),
defineProperty(`--un-mask-${gradient}-${p}-position`, {
syntax: "<length-percentage>",
initialValue: p === "from" ? "0%" : "100%"
}),
defineProperty(`--un-mask-${gradient}-${p}-color`, {
syntax: "<color>",
initialValue: p === "from" ? "black" : "transparent"
})
]));
}
return [css, ...props];
}
function handleSize$1([, v = ""], ctx) {
const _v = h.bracket.cssvar.global.fraction.rem(v, ctx?.theme);
if (_v !== null) return { "mask-size": _v };
}
const masks = [
["mask-clip-border", { "mask-clip": "border-box" }],
["mask-clip-padding", { "mask-clip": "padding-box" }],
["mask-clip-content", { "mask-clip": "content-box" }],
["mask-clip-fill", { "mask-clip": "fill-box" }],
["mask-clip-stroke", { "mask-clip": "stroke-box" }],
["mask-clip-view", { "mask-clip": "view-box" }],
["mask-no-clip", { "mask-clip": "no-clip" }],
["mask-add", { "mask-composite": "add" }],
["mask-subtract", { "mask-composite": "sub