Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: default enable for
preset-applet
and preset-rem-to-rpx
- Loading branch information
Showing
11 changed files
with
343 additions
and
253 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,6 @@ | |
"stub": "unbuild --stub" | ||
}, | ||
"dependencies": { | ||
"@unocss/core": "^0.45.22" | ||
"@unocss/core": "^0.45.23" | ||
} | ||
} |
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,43 +1,46 @@ | ||
import type { Preset } from "unocss"; | ||
import type { Preset } from 'unocss' | ||
|
||
const remRE = /^-?[\.\d]+rem$/; | ||
const remRE = /^-?[\.\d]+rem$/ | ||
|
||
export interface RemToRpxOptions { | ||
/** | ||
* Enable applet, only build applet should be true | ||
* e.g. In uniapp set `enable: !(process.env.UNI_PLATFORM === 'h5')` to disable for h5 | ||
* @default true | ||
*/ | ||
enable?: boolean; | ||
enable?: boolean | ||
|
||
/** | ||
* 1rem = n px | ||
* @default 16 | ||
*/ | ||
baseFontSize?: number; | ||
baseFontSize?: number | ||
|
||
/** | ||
* screen width in px | ||
* @default 375 | ||
*/ | ||
screenWidth?: number; | ||
screenWidth?: number | ||
} | ||
|
||
export default function remToRpxPreset(options: RemToRpxOptions = {}): Preset { | ||
const { baseFontSize = 16, screenWidth = 375 } = options; | ||
const { baseFontSize = 16, screenWidth = 375 } = options | ||
|
||
const enable = options.enable ?? true | ||
|
||
return { | ||
name: "unocss-preset-rem-to-rpx", | ||
postprocess: options.enable | ||
name: 'unocss-preset-rem-to-rpx', | ||
postprocess: enable | ||
? (util) => { | ||
util.entries.forEach((i) => { | ||
const value = i[1]; | ||
if (value && typeof value === "string" && remRE.test(value)) | ||
const value = i[1] | ||
if (value && typeof value === 'string' && remRE.test(value)) { | ||
i[1] = `${ | ||
+value.slice(0, -3) * baseFontSize * (750 / screenWidth) | ||
}rpx`; | ||
}); | ||
}rpx` | ||
} | ||
}) | ||
} | ||
: undefined, | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.