Skip to content

Commit

Permalink
fix(attributify): allow decimal value (#2011)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris <1633711653@qq.com>
close #2006
  • Loading branch information
equt committed Dec 19, 2022
1 parent 996b915 commit 94c0754
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/preset-attributify/src/extractor.ts
Expand Up @@ -9,7 +9,7 @@ const strippedPrefixes = [

const splitterRE = /[\s'"`;]+/g
const elementRE = /<\w(?=.*>)[\w:\.$-]*\s((?:['"`\{].*?['"`\}]|.*?)*?)>/gs
const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-]+)=?(?:["]([^"]*)["]|[']([^']*)[']|[{]([^}]*)[}])?/gms
const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-.]+)=?(?:["]([^"]*)["]|[']([^']*)[']|[{]([^}]*)[}])?/gms

export const defaultIgnoreAttributes = ['placeholder']

Expand Down
4 changes: 2 additions & 2 deletions packages/preset-mini/src/_utils/handlers/regex.ts
@@ -1,3 +1,3 @@
export const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|%|r?em|ex|ch|ic|(?:[sld]?v|cq)(?:[whib]|min|max)|in|cm|mm|rpx)?$/i
export const numberRE = /^(-?[0-9.]+)$/i
export const numberWithUnitRE = /^(-?\d*(?:\.\d+)?)(px|pt|pc|%|r?em|ex|ch|ic|(?:[sld]?v|cq)(?:[whib]|min|max)|in|cm|mm|rpx)?$/i
export const numberRE = /^(-?\d*(?:\.\d+)?)$/i
export const unitOnlyRE = /^(px)$/i
7 changes: 7 additions & 0 deletions test/__snapshots__/preset-attributify.test.ts.snap
Expand Up @@ -47,6 +47,8 @@ Set {
"[m~=\\"1\\"]",
"[m~=\\"2\\"]",
"[m~=\\"3\\"]",
"[ml-1.5=\\"\\"]",
"[ml-1..6=\\"\\"]",
}
`;

Expand Down Expand Up @@ -157,6 +159,7 @@ Set {
"[m~=\\"1\\"]",
"[m~=\\"2\\"]",
"[m~=\\"3\\"]",
"[ml-1.5=\\"\\"]",
}
`;

Expand All @@ -172,6 +175,7 @@ exports[`attributify > fixture1 1`] = `
[m~=\\"\\\\33 \\"]{margin:0.75rem;}
[ma=\\"\\"],
[un-children~=\\"m-auto\\"]>*{margin:auto;}
[ml-1\\\\.5=\\"\\"]{margin-left:0.375rem;}
[inline-block=\\"\\"]{display:inline-block;}
[flex~=\\"\\\\!\\\\~\\"]{display:flex !important;}
[flex~=\\"col\\"]{flex-direction:column;}
Expand Down Expand Up @@ -283,6 +287,7 @@ exports[`attributify > fixture4 1`] = `
[m~=\\"\\\\33 \\"]{margin:0.75rem;}
[ma=\\"\\"],
[un-children~=\\"m-auto\\"]>*{margin:auto;}
[ml-1\\\\.5=\\"\\"]{margin-left:0.375rem;}
[inline-block=\\"\\"]{display:inline-block;}
[flex~=\\"\\\\!\\\\~\\"]{display:flex !important;}
[flex~=\\"col\\"]{flex-direction:column;}
Expand Down Expand Up @@ -372,5 +377,7 @@ exports[`attributify > variant 1`] = `
"m-1",
"m-2",
"m-3",
"ml-1.5",
"ml-1..6",
]
`;
3 changes: 3 additions & 0 deletions test/preset-attributify.test.ts
Expand Up @@ -35,6 +35,8 @@ describe('attributify', () => {
1 2
3
\`'
ml-1.5
ml-1..6
>
Button
</button>
Expand Down Expand Up @@ -108,6 +110,7 @@ describe('attributify', () => {
1 2
3
\`'
ml-1.5
>
Button
</button>
Expand Down

0 comments on commit 94c0754

Please sign in to comment.