Skip to content

Commit

Permalink
feat: support !(text-red bg-blue) -> !text-red !bg-blue
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Oct 10, 2023
1 parent d6f5c21 commit fc50c30
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ UnoT is short for unocss tools that is to provide a better development experienc
- bg-[rgba(255, 255, 255, 0.5)] -> bg-[rgba(255,255,255,0.5)]
- translatex--50% -> translate-x-[-50%]
- hover:(text-red bg-blue) -> hover:text-red hover:bg-blue
- !(text-red bg-blue) -> !text-red !bg-blue

## :coffee:

Expand Down
1 change: 1 addition & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const rules: any = [
[/([\s'])contain(\s|'|!|$)/, (_: string, v1: string, v2: string) => `${v1}bg-contain${v2}`],
[/([\s'])cover(\s|'|!|$)/, (_: string, v1: string, v2: string) => `${v1}bg-cover${v2}`],
[/([\s'])line([0-9]+)(\s|'|!|$)/, (_: string, v1: string, v2: string, v3: string) => `${v1}line-clamp-${v2}${v3}`],
[/([\s!])\(([^\)]+)\)(\s|'|!|$)/, (_: string, v1: string, v2: string, v3: string) => v2.replace(/\s+/g, ' ').split(' ').map(item => `!${item}`).join(' ') + v3],
]

export function transform(content: string) {
Expand Down
8 changes: 8 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ describe('should', () => {
expect(
transform(':class="hover:(flex-center) w10"')).toMatchInlineSnapshot('":class=\\"hover:flex hover:justify-center hover:items-center w-10\\""')
})
it('match error', () => {
expect(
transform(':class="hover:(flex-center) w10"')).toMatchInlineSnapshot('":class=\\"hover:flex hover:justify-center hover:items-center w-10\\""')
})
it('match error', () => {
expect(
transform(':class=" w10 !(flex-center w10) w20"')).toMatchInlineSnapshot('":class=\\" w-10 !flex-center !w-10 w-20\\""')
})
})

0 comments on commit fc50c30

Please sign in to comment.