8000 fix: handle edge cases · unocss/unocss@8827afa · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 8827afa

Browse files
committed
fix: handle edge cases
1 parent 597124f commit 8827afa

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

src/default/rules/spacing.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { directionMap } from '../../utils'
33
import { h } from '../../handlers'
44

55
const directionSize = (prefix: string) => ([_, direction, size]: string[]): NanowindCssEntries | undefined => {
6-
const v = h.size.fraction(size)
6+
const v = h.bracket.size.fraction(size)
77
if (v)
88
return directionMap[direction].map(i => [prefix + i, v])
99
}
1010

1111
export const paddings: NanowindRule[] = [
12-
[/^p()-(\w+)$/, directionSize('padding')],
13-
[/^p([xy]?)-(\w+)$/, directionSize('padding')],
14-
[/^p([rltb]?)-(\w+)$/, directionSize('padding')],
12+
[/^p()-([^-]+)$/, directionSize('padding')],
13+
[/^p([xy]?)-([^-]+)$/, directionSize('padding')],
14+
[/^p([rltb]?)-([^-]+)$/, directionSize('padding')],
1515
]
1616

1717
export const margins: NanowindRule[] = [
18-
[/^m()-(\w+)$/, directionSize('margin')],
19-
[/^m([xy]?)-(\w+)$/, directionSize('margin')],
20-
[/^m([rltb]?)-(\w+)$/, directionSize('margin')],
18+
[/^m()-([^-]+)$/, directionSize('margin')],
19+
[/^m([xy]?)-([^-]+)$/, directionSize('margin')],
20+
[/^m([rltb]?)-([^-]+)$/, directionSize('margin')],
2121
]

src/generator/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { cssEscape, NanowindVariant, entriesToCss } from '..'
22
import { NanowindConfig } from '../types'
33

4+
const cheatFilter = /[a-z]/
5+
46
export function createGenerator(config: NanowindConfig) {
57
const { rules, theme, variants } = config
68

@@ -11,7 +13,10 @@ export function createGenerator(config: NanowindConfig) {
1113
const sheet: [number, string][] = []
1214

1315
tokens.forEach((token) => {
14-
if (cache.has(token)) {
16+
if (!token.match(cheatFilter)) {
17+
tokens.delete(token)
18+
}
19+
else if (cache.has(token)) {
1520
const r = cache.get(token)
1621
if (r)
1722
sheet.push(r)

src/handlers/handlers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export function size(str: string) {
2+
if (str === 'auto')
3+
return str
24
const match = str.match(/^([0-9.]+)([a-z]*)$/i)
35
if (!match)
46
return
@@ -36,3 +38,8 @@ export function fraction(str: string) {
3638
if (!Number.isNaN(num))
3739
return `${num * 100}%`
3840
}
41+
42+
export function bracket(str: string) {
43+
if (str[0] === '[' && str[str.length - 1] === ']')
44+
return str.slice(1, -1)
45+
}

test/__snapshots__/default.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ exports[`default 1`] = `
99
.\\\\!hover\\\\:px-10:hover{padding-left:2.5rem !important; padding-right:2.5rem !important;}
1010
.pt-2{padding-top:0.5rem;}
1111
.pl-10px{padding-left:10px;}
12+
.m-auto{margin:auto;}
13+
.m-\\\\[3em\\\\]{margin:3em;}
14+
.my-auto{margin-top:auto; margin-bottom:auto;}
1215
.flex{display:flex;}
1316
.op-10{opacity:0.1;}
1417
.opacity-0{opacity:0;}

test/default.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ test('default', () => {
2121
'border',
2222
'border-2',
2323
'font-mono',
24+
'm-auto',
25+
'my-auto',
26+
'm-[3em]',
2427
].join(' '))).toMatchSnapshot()
2528
})

0 commit comments

Comments
 (0)
0