Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
177 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`prefix 1`] = ` | ||
"/* layer: icons */ | ||
.dark .uno\\\\:dark\\\\:i-carbon-moon{--un-icon:url(\\"data:image/svg+xml;utf8,%3Csvg preserveAspectRatio='xMidYMid meet' viewBox='0 0 32 32' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3Z'/%3E%3C/svg%3E\\");mask:var(--un-icon) no-repeat;mask-size:100% 100%;-webkit-mask:var(--un-icon) no-repeat;-webkit-mask-size:100% 100%;background-color:currentColor;width:1em;height:1em;} | ||
/* layer: shortcuts */ | ||
.uno\\\\:btn{margin-right:2.5rem;} | ||
.uno\\\\:btn1{margin-left:2.5rem;margin-right:2.5rem;} | ||
/* layer: default */ | ||
.uno\\\\:\\\\!p-5px{padding:5px !important;} | ||
.uno\\\\:hover\\\\:p-4:hover{padding:1rem;} | ||
.uno\\\\:pl-10px{padding-left:10px;} | ||
@media (min-width: 640px){ | ||
.uno\\\\:sm\\\\:p-6{padding:1.5rem;} | ||
}" | ||
`; | ||
|
||
exports[`tailwind prefix 1`] = ` | ||
"/* layer: shortcuts */ | ||
.uno-btn{margin-right:2.5rem;} | ||
.uno\\\\:btn1{margin-left:2.5rem;margin-right:2.5rem;} | ||
/* layer: default */ | ||
.\\\\!uno\\\\:p-5px{padding:5px !important;} | ||
.hover\\\\:uno\\\\:p-4:hover{padding:1rem;} | ||
.uno\\\\:pl-10px{padding-left:10px;} | ||
@media (min-width: 640px){ | ||
.sm\\\\:uno\\\\:p-6{padding:1.5rem;} | ||
}" | ||
exports[`prefix > preset prefix 2`] = ` | ||
"/* layer: default */ | ||
.hover\\\\:foo-p4:hover{padding:1rem;} | ||
.foo-text-red{--un-text-opacity:1;color:rgba(248,113,113,var(--un-text-opacity));} | ||
.bar-bar{color:bar;}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`preprocess > prefix 1`] = ` | ||
"/* layer: icons */ | ||
.dark .uno\\\\:dark\\\\:i-carbon-moon{--un-icon:url(\\"data:image/svg+xml;utf8,%3Csvg preserveAspectRatio='xMidYMid meet' viewBox='0 0 32 32' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='currentColor' d='M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3Z'/%3E%3C/svg%3E\\");mask:var(--un-icon) no-repeat;mask-size:100% 100%;-webkit-mask:var(--un-icon) no-repeat;-webkit-mask-size:100% 100%;background-color:currentColor;width:1em;height:1em;} | ||
/* layer: shortcuts */ | ||
.uno\\\\:btn{margin-right:2.5rem;} | ||
.uno\\\\:btn1{margin-left:2.5rem;margin-right:2.5rem;} | ||
/* layer: default */ | ||
.uno\\\\:\\\\!p-5px{padding:5px !important;} | ||
.uno\\\\:hover\\\\:p-4:hover{padding:1rem;} | ||
.uno\\\\:pl-10px{padding-left:10px;} | ||
@media (min-width: 640px){ | ||
.uno\\\\:sm\\\\:p-6{padding:1.5rem;} | ||
}" | ||
`; | ||
|
||
exports[`preprocess > tailwind prefix 1`] = ` | ||
"/* layer: shortcuts */ | ||
.uno-btn{margin-right:2.5rem;} | ||
.uno\\\\:btn1{margin-left:2.5rem;margin-right:2.5rem;} | ||
/* layer: default */ | ||
.\\\\!uno\\\\:p-5px{padding:5px !important;} | ||
.hover\\\\:uno\\\\:p-4:hover{padding:1rem;} | ||
.uno\\\\:pl-10px{padding-left:10px;} | ||
@media (min-width: 640px){ | ||
.sm\\\\:uno\\\\:p-6{padding:1.5rem;} | ||
}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,35 @@ | ||
import { createGenerator } from '@unocss/core' | ||
import presetUno from '@unocss/preset-uno' | ||
import presetIcons from '@unocss/preset-icons' | ||
import { expect, test } from 'vitest' | ||
import { describe, expect, test } from 'vitest' | ||
import presetMini from '@unocss/preset-mini' | ||
|
||
test('prefix', async () => { | ||
const positive = [ | ||
'uno:pl-10px', | ||
'uno:hover:p-4', | ||
'uno:sm:p-6', | ||
'uno:!p-5px', | ||
'uno:btn', | ||
'uno:btn1', | ||
'uno:dark:i-carbon-moon', | ||
] | ||
describe('prefix', () => { | ||
test('preset prefix', async () => { | ||
const uno = createGenerator({ | ||
presets: [ | ||
presetMini({ prefix: 'foo-' }), | ||
], | ||
rules: [ | ||
['bar', { color: 'bar' }, { prefix: 'bar-' }], | ||
], | ||
}) | ||
|
||
const negative = [ | ||
'pl-10px', | ||
'hover:p-4', | ||
'!p-5px', | ||
'btn', | ||
'btn1', | ||
'i-carbon-moon', | ||
] | ||
const { css, matched } = await uno.generate(new Set([ | ||
'text-red', | ||
'foo-text-red', | ||
'hover:p4', | ||
'hover:foo-p4', | ||
'bar', | ||
'bar-bar', | ||
]), { preflights: false }) | ||
|
||
const uno = createGenerator({ | ||
preprocess: m => m.startsWith('uno:') ? m.substr(4) : '', | ||
presets: [ | ||
presetUno(), | ||
presetIcons(), | ||
], | ||
shortcuts: { | ||
btn: 'mr-10', | ||
btn1: 'ml-10 btn', | ||
}, | ||
}) | ||
const { css, matched } = await uno.generate(new Set([...positive, ...negative]), { preflights: false }) | ||
expect(matched).eql(new Set(positive)) | ||
expect(css).toMatchSnapshot() | ||
}) | ||
|
||
test('tailwind prefix', async () => { | ||
const positive = [ | ||
'uno:pl-10px', | ||
'hover:uno:p-4', | ||
'sm:uno:p-6', | ||
'!uno:p-5px', | ||
'uno-btn', | ||
'uno:btn1', | ||
] | ||
|
||
const negative = [ | ||
'pl-10px', | ||
'hover:p-4', | ||
'!p-5px', | ||
'btn', | ||
'btn1', | ||
] | ||
expect(matched).toMatchInlineSnapshot(` | ||
Set { | ||
"bar-bar", | ||
"foo-text-red", | ||
"hover:foo-p4", | ||
} | ||
`) | ||
|
||
const prefixRE = /uno[:-]/ | ||
const uno = createGenerator({ | ||
preprocess: m => prefixRE.test(m) ? m.replace(prefixRE, '') : '', | ||
presets: [ | ||
presetUno(), | ||
presetIcons(), | ||
], | ||
shortcuts: { | ||
btn: 'mr-10', | ||
btn1: 'ml-10 btn', | ||
}, | ||
expect(css).toMatchSnapshot() | ||
}) | ||
const { css, matched } = await uno.generate(new Set([...positive, ...negative]), { preflights: false }) | ||
expect(matched).eql(new Set(positive)) | ||
expect(css).toMatchSnapshot() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { createGenerator } from '@unocss/core' | ||
import presetUno from '@unocss/preset-uno' | ||
import presetIcons from '@unocss/preset-icons' | ||
import { describe, expect, test } from 'vitest' | ||
|
||
describe('preprocess', () => { | ||
test('prefix', async () => { | ||
const positive = [ | ||
'uno:pl-10px', | ||
'uno:hover:p-4', | ||
'uno:sm:p-6', | ||
'uno:!p-5px', | ||
'uno:btn', | ||
'uno:btn1', | ||
'uno:dark:i-carbon-moon', | ||
] | ||
|
||
const negative = [ | ||
'pl-10px', | ||
'hover:p-4', | ||
'!p-5px', | ||
'btn', | ||
'btn1', | ||
'i-carbon-moon', | ||
] | ||
|
||
const uno = createGenerator({ | ||
preprocess: m => m.startsWith('uno:') ? m.substr(4) : '', | ||
presets: [ | ||
presetUno(), | ||
presetIcons(), | ||
], | ||
shortcuts: { | ||
btn: 'mr-10', | ||
btn1: 'ml-10 btn', | ||
}, | ||
}) | ||
const { css, matched } = await uno.generate(new Set([...positive, ...negative]), { preflights: false }) | ||
expect(matched).eql(new Set(positive)) | ||
expect(css).toMatchSnapshot() | ||
}) | ||
|
||
test('tailwind prefix', async () => { | ||
const positive = [ | ||
'uno:pl-10px', | ||
'hover:uno:p-4', | ||
'sm:uno:p-6', | ||
'!uno:p-5px', | ||
'uno-btn', | ||
'uno:btn1', | ||
] | ||
|
||
const negative = [ | ||
'pl-10px', | ||
'hover:p-4', | ||
'!p-5px', | ||
'btn', | ||
'btn1', | ||
] | ||
|
||
const prefixRE = /uno[:-]/ | ||
const uno = createGenerator({ | ||
preprocess: m => prefixRE.test(m) ? m.replace(prefixRE, '') : '', | ||
presets: [ | ||
presetUno(), | ||
presetIcons(), | ||
], | ||
shortcuts: { | ||
btn: 'mr-10', | ||
btn1: 'ml-10 btn', | ||
}, | ||
}) | ||
const { css, matched } = await uno.generate(new Set([...positive, ...negative]), { preflights: false }) | ||
expect(matched).eql(new Set(positive)) | ||
expect(css).toMatchSnapshot() | ||
}) | ||
}) |