Skip to content

Commit

Permalink
feat: support bg-[size:*]
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowCo committed Mar 21, 2024
1 parent ae4f356 commit b95ebc5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/rules/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const opacity: Rule[] = [
]

const bgUrlRE = /^\[url\(.+\)\]$/
const bgLengthRE = /^\[length:.+\]$/
const bgLengthRE = /^\[(length|size):.+\]$/
const bgPositionRE = /^\[position:.+\]$/
const bgGradientRE = /^\[(linear|conic|radial)-gradient\(.+\)\]$/
export const bgColors: Rule<Theme>[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/utils/handlers/regex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const numberWithUnitRE = /^(-?\d*(?:\.\d+)?)(px|pt|pc|%|r?(?:em|ex|lh|cap|ch|ic)|(?:[sld]?v|cq)(?:[whib]|min|max)|in|cm|mm|rpx)?$/i
export const numberRE = /^(-?[0-9.]+)$/i
export const unitOnlyRE = /^(px)$/i
export const bracketTypeRe = /^\[(color|length|position|quoted|string):/i
export const bracketTypeRe = /^\[(color|length|size|position|quoted|string):/i
9 changes: 6 additions & 3 deletions test/assets/output/preset-mini/targets.css
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,12 @@ unocss .scope-\[unocss\]\:block{display:block;}
.bg-\[calc\(10\%\+10px\)\]{background-position:calc(10% + 10px);}
.bg-\[calc\(10vw\+10px\)\]{background-position:calc(10vw + 10px);}
.bg-\[conic-gradient\(red\,blue\)\]{background-image:conic-gradient(red,blue);}
.bg-\[length\:--variable\]{background-size:var(--variable);}
.bg-\[length\:1\/2_20rem\]{background-size:50% 20rem;}
.bg-\[length\:10_20rem\]{background-size:10px 20rem;}
.bg-\[length\:--variable\],
.bg-\[size\:--variable\]{background-size:var(--variable);}
.bg-\[length\:1\/2_20rem\],
.bg-\[size\:1\/2_20rem\]{background-size:50% 20rem;}
.bg-\[length\:10_20rem\],
.bg-\[size\:10_20rem\]{background-size:10px 20rem;}
.bg-\[linear-gradient\(45deg\,\#0072ff\,\#00d2e8\,\#04fd8f\,\#70fd6c\)\]{background-image:linear-gradient(45deg,#0072ff,#00d2e8,#04fd8f,#70fd6c);}
.bg-\[position\:--variable\]{background-position:var(--variable);}
.bg-\[position\:1\/2_20rem\]{background-position:50% 20rem;}
Expand Down
9 changes: 6 additions & 3 deletions test/assets/output/preset-weapp/targets-custom-rules.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,12 @@ unocss .scope-_lfl11_unocss_lfr11__cl11_block{display:block;}
.bg-_lfl11_calc_lbl11_10_pes11__plus_10px_lbr11__lfr11_{background-position:calc(10% + 10px);}
.bg-_lfl11_calc_lbl11_10vw_plus_10px_lbr11__lfr11_{background-position:calc(10vw + 10px);}
.bg-_lfl11_conic-gradient_lbl11_red_lco11_blue_lbr11__lfr11_{background-image:conic-gradient(red,blue);}
.bg-_lfl11_length_cl11_--variable_lfr11_{background-size:var(--variable);}
.bg-_lfl11_length_cl11_1_sl11_2_20rem_lfr11_{background-size:50% 20rem;}
.bg-_lfl11_length_cl11_10_20rem_lfr11_{background-size:10px 20rem;}
.bg-_lfl11_length_cl11_--variable_lfr11_,
.bg-_lfl11_size_cl11_--variable_lfr11_{background-size:var(--variable);}
.bg-_lfl11_length_cl11_1_sl11_2_20rem_lfr11_,
.bg-_lfl11_size_cl11_1_sl11_2_20rem_lfr11_{background-size:50% 20rem;}
.bg-_lfl11_length_cl11_10_20rem_lfr11_,
.bg-_lfl11_size_cl11_10_20rem_lfr11_{background-size:10px 20rem;}
.bg-_lfl11_linear-gradient_lbl11_45deg_lco11__wn11_0072ff_lco11__wn11_00d2e8_lco11__wn11_04fd8f_lco11__wn11_70fd6c_lbr11__lfr11_{background-image:linear-gradient(45deg,#0072ff,#00d2e8,#04fd8f,#70fd6c);}
.bg-_lfl11_position_cl11_--variable_lfr11_{background-position:var(--variable);}
.bg-_lfl11_position_cl11_1_sl11_2_20rem_lfr11_{background-position:50% 20rem;}
Expand Down
9 changes: 6 additions & 3 deletions test/assets/output/preset-weapp/targets.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,12 @@ unocss .scope-_lfl_unocss_lfr__cl_block{display:block;}
.bg-_lfl_calc_lbl_10_pes__plus_10px_lbr__lfr_{background-position:calc(10% + 10px);}
.bg-_lfl_calc_lbl_10vw_plus_10px_lbr__lfr_{background-position:calc(10vw + 10px);}
.bg-_lfl_conic-gradient_lbl_red_lco_blue_lbr__lfr_{background-image:conic-gradient(red,blue);}
.bg-_lfl_length_cl_--variable_lfr_{background-size:var(--variable);}
.bg-_lfl_length_cl_1_sl_2_20rem_lfr_{background-size:50% 20rem;}
.bg-_lfl_length_cl_10_20rem_lfr_{background-size:10px 20rem;}
.bg-_lfl_length_cl_--variable_lfr_,
.bg-_lfl_size_cl_--variable_lfr_{background-size:var(--variable);}
.bg-_lfl_length_cl_1_sl_2_20rem_lfr_,
.bg-_lfl_size_cl_1_sl_2_20rem_lfr_{background-size:50% 20rem;}
.bg-_lfl_length_cl_10_20rem_lfr_,
.bg-_lfl_size_cl_10_20rem_lfr_{background-size:10px 20rem;}
.bg-_lfl_linear-gradient_lbl_45deg_lco__wn_0072ff_lco__wn_00d2e8_lco__wn_04fd8f_lco__wn_70fd6c_lbr__lfr_{background-image:linear-gradient(45deg,#0072ff,#00d2e8,#04fd8f,#70fd6c);}
.bg-_lfl_position_cl_--variable_lfr_{background-position:var(--variable);}
.bg-_lfl_position_cl_1_sl_2_20rem_lfr_{background-position:50% 20rem;}
Expand Down
3 changes: 3 additions & 0 deletions test/assets/preset-mini-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ export const presetMiniTargets: string[] = [
'bg-[length:--variable]',
'bg-[length:10_20rem]',
'bg-[length:1/2_20rem]',
'bg-[size:--variable]',
'bg-[size:10_20rem]',
'bg-[size:1/2_20rem]',
'bg-[position:--variable]',
'bg-[position:10_20rem]',
'bg-[position:1/2_20rem]',
Expand Down

0 comments on commit b95ebc5

Please sign in to comment.