Skip to content

Commit

Permalink
Goodbye Prettier!
Browse files Browse the repository at this point in the history
  • Loading branch information
kidonng committed Apr 12, 2023
1 parent 0629d4d commit 8b2aec8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
1 change: 0 additions & 1 deletion .xo-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"$schema": "https://json.schemastore.org/eslintrc.json",
"prettier": true,
"semicolon": false
}
59 changes: 36 additions & 23 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ export const presetDaisy = (

const styles = [
options.styled
? options.rtl
? styledRtl
: styled
: options.rtl
? unstyledRtl
: unstyled,
? (options.rtl ? styledRtl : styled)
: (options.rtl ? unstyledRtl : unstyled),
]
if (options.utils) styles.push(utilities, utilitiesUnstyled, utilitiesStyled)
if (options.utils) {
styles.push(utilities, utilitiesUnstyled, utilitiesStyled)
}

for (const node of styles.flatMap((style) => parse(style).nodes)) {
for (const node of styles.flatMap(style => parse(style).nodes)) {
const isAtRule = node.type === 'atrule'
// @keyframes
if (isAtRule && node.name === 'keyframes') {
Expand All @@ -74,12 +72,13 @@ export const presetDaisy = (
if (
// .collapse-open -> .collapse
// https://github.com/saadeghi/daisyui/blob/5c725a0778dd119c2016b8ea31bc1077a20e8c3b/src/components/styled/collapse.css#L57-L58
selector.startsWith('.collapse-open') ||
selector.startsWith('.collapse-open')
// .modal-open -> .modal-toggle
// https://github.com/saadeghi/daisyui/blob/5c725a0778dd119c2016b8ea31bc1077a20e8c3b/src/components/styled/modal.css#L14-L15
selector.startsWith('.modal-open')
)
|| selector.startsWith('.modal-open')
) {
selector = rule.selectors[1]!
}

const tokens = tokenize(selector)
const token = tokens[0]!
Expand All @@ -88,17 +87,23 @@ export const presetDaisy = (
if (token.type === 'class') {
// Resolve conflicts with @unocss/preset-wind link variant
// .link-* -> .link
if (selector.startsWith('.link-')) base = 'link'
if (selector.startsWith('.link-')) {
base = 'link'
}

// .btn-outline.btn-* -> .btn-*
if (selector.startsWith('.btn-outline.btn-'))
if (selector.startsWith('.btn-outline.btn-')) {
base = (tokens[1] as ClassToken).name
}

base = token.name
} else if (token.type === 'pseudo-class' && token.name === 'where')
} else if (token.type === 'pseudo-class' && token.name === 'where') {
// :where(.foo) -> .foo
base = (tokenize(token.argument!)[0] as ClassToken).name
else if (['[dir="rtl"]', ':root'].includes(token.content))
} else if (['[dir="rtl"]', ':root'].includes(token.content)) {
// Skip prefixes
base = (tokens[2] as ClassToken).name
}

rules.set(base, (rules.get(base) ?? '') + String(rule) + '\n')
}
Expand All @@ -110,15 +115,23 @@ export const presetDaisy = (

const preflights = [...keyframes]

if (options.base) preflights.unshift(replaceSlash(replacePrefix(toCss(base))))
if (options.base) {
preflights.unshift(replaceSlash(replacePrefix(toCss(base))))
}

colorFunctions.injectThemes(
(theme) => {
theme => {
preflights.push(replaceSpace(toCss(theme)))
},
// @ts-expect-error Return never
(key) => {
if (key === 'daisyui.themes') return options.themes
if (key === 'daisyui.darkTheme') return options.darkTheme
key => {
if (key === 'daisyui.themes') {
return options.themes
}

if (key === 'daisyui.darkTheme') {
return options.darkTheme
}
},
themes,
)
Expand All @@ -139,9 +152,9 @@ export const presetDaisy = (
([color]) =>
// Already in @unocss/preset-mini
// https://github.com/unocss/unocss/blob/0f7efcba592e71d81fbb295332b27e6894a0b4fa/packages/preset-mini/src/_theme/colors.ts#L11-L12
!['transparent', 'current'].includes(color) &&
!['transparent', 'current'].includes(color)
// Added below
!color.startsWith('base'),
&& !color.startsWith('base'),
)
.map(([color, value]) => [camelCase(color), value({})]),
),
Expand All @@ -153,7 +166,7 @@ export const presetDaisy = (
},
},
rules: [...rules].map(
(rule) =>
rule =>
[
new RegExp(`^${rule[0]}$`),
() => replaceSlash(replacePrefix(rule[1])),
Expand Down

0 comments on commit 8b2aec8

Please sign in to comment.