@mapcss/preset-typography
Version:
Typography preset for MapCSS
104 lines (103 loc) • 3.97 kB
JavaScript
import { $2xl, lg, md, sm, xl } from "./breakpoint.js";
import { createDark } from "./color_scheme.js";
import { scrollbar, scrollbarThumb, scrollbarTrack } from "./pseudo.js";
import { createMedia } from "./at_rule.js";
import { content } from "./pseudo_elements.js";
import { $important } from "./important.js";
import { $minus } from "./minus.js";
import { group } from "./group.js";
import { selectorTransform } from "./_utils.js";
function prefix(prefix) {
return (value) => `${prefix}${value}`;
}
function suffix(suffix) {
return (value) => `${value}${suffix}`;
}
export function createModifierMap(darkMode) {
const modifierMap = {
sm,
md,
lg,
xl,
dark: createDark(darkMode),
"2xl": $2xl,
hover: selectorTransform(suffix(":hover")),
focus: {
DEFAULT: selectorTransform(suffix(":focus")),
within: selectorTransform(suffix(":focus-within")),
visible: selectorTransform(suffix(":focus-visible")),
},
open: selectorTransform(suffix("[open]")),
active: selectorTransform(suffix(":active")),
visited: selectorTransform(suffix(":visited")),
target: selectorTransform(suffix(":target")),
first: {
DEFAULT: selectorTransform(suffix(":first-child")),
of: {
type: selectorTransform(suffix(":first-of-type")),
},
letter: selectorTransform(suffix("::first-letter")),
line: selectorTransform(suffix("::first-line")),
},
last: {
DEFAULT: selectorTransform(suffix(":last-child")),
of: {
type: selectorTransform(suffix(":last-of-type")),
},
},
only: {
DEFAULT: selectorTransform(suffix(":only-child")),
of: {
type: selectorTransform(suffix(":only-of-type")),
},
},
empty: selectorTransform(suffix(":empty")),
disabled: selectorTransform(suffix(":disabled")),
checked: selectorTransform(suffix(":checked")),
odd: selectorTransform(suffix(":nth-child(odd)")),
even: selectorTransform(suffix(":nth-child(even)")),
indeterminate: selectorTransform(suffix(":indeterminate")),
default: selectorTransform(suffix(":default")),
required: selectorTransform(suffix(":required")),
valid: selectorTransform(suffix(":valid")),
invalid: selectorTransform(suffix(":invalid")),
in: {
range: selectorTransform(suffix(":in-range")),
},
out: {
of: {
range: selectorTransform(suffix(":out-of-range")),
},
},
placeholder: {
DEFAULT: selectorTransform(suffix("::placeholder")),
shown: selectorTransform(suffix(":placeholder-shown")),
},
autofill: selectorTransform(suffix(":autofill")),
read: {
only: selectorTransform(suffix(":read-only")),
},
before: content,
after: content,
portrait: createMedia("(orientation: portrait)"),
landscape: createMedia("(orientation: landscape)"),
motion: {
safe: createMedia("(prefers-reduced-motion: no-preference)"),
reduce: createMedia("(prefers-reduced-motion: reduce)"),
},
print: createMedia("print"),
// TODO(miyauci): add check the rule-set has valid declaration
marker: selectorTransform(suffix("::marker")),
selection: selectorTransform(suffix("::selection")),
rtl: selectorTransform(prefix('[dir="rtl"] ')),
ltr: selectorTransform(prefix('[dir="ltr"] ')),
file: selectorTransform(suffix("::file-selector-button")),
"!": $important,
"-": $minus,
scrollbar,
"scrollbar-track": scrollbarTrack,
"scrollbar-thumb": scrollbarThumb,
group,
};
return modifierMap;
}