Skip to content

Commit

Permalink
fix: default enable for preset-applet and preset-rem-to-rpx
Browse files Browse the repository at this point in the history
  • Loading branch information
zguolee committed Sep 26, 2022
1 parent 790dcf5 commit 7fea351
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 253 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -24,18 +24,18 @@
},
"devDependencies": {
"@antfu/eslint-config": "^0.27.0",
"@types/node": "^18.7.18",
"@types/node": "^18.7.22",
"@unocss-applet/preset-applet": "workspace:*",
"@unocss-applet/preset-rem-to-rpx": "workspace:*",
"@unocss-applet/transformer-applet": "workspace:*",
"@unocss-applet/transformer-attributify": "workspace:*",
"bumpp": "^8.2.1",
"eslint": "^8.23.1",
"eslint": "^8.24.0",
"esno": "^0.16.3",
"rimraf": "^3.0.2",
"typescript": "^4.8.3",
"unbuild": "^0.8.11",
"unocss": "^0.45.22",
"unocss": "^0.45.23",
"unocss-applet": "workspace:*",
"vite": "^3.1.3",
"vitest": "^0.23.4"
Expand Down
6 changes: 3 additions & 3 deletions packages/preset-applet/package.json
Expand Up @@ -54,8 +54,8 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.22",
"@unocss/preset-mini": "^0.45.22",
"@unocss/preset-wind": "^0.45.22"
"@unocss/core": "^0.45.23",
"@unocss/preset-mini": "^0.45.23",
"@unocss/preset-wind": "^0.45.23"
}
}
5 changes: 3 additions & 2 deletions packages/preset-applet/src/index.ts
Expand Up @@ -21,6 +21,7 @@ export interface PresetAppletOptions extends PresetMiniOptions {
const presetApplet = (options: PresetAppletOptions = {}): Preset<Theme> => {
options.dark = options.dark ?? 'class'
options.attributifyPseudo = options.attributifyPseudo ?? false
const enable = options.enable ?? true

return {
name: 'unocss-preset-applet',
Expand All @@ -32,10 +33,10 @@ const presetApplet = (options: PresetAppletOptions = {}): Preset<Theme> => {
variantColorMix,
],
options,
preflights: options.enable ? preflightsApplet : defaultApplet,
preflights: enable ? preflightsApplet : defaultApplet,
postprocess: [
(util) => {
options.enable && (util.selector = unoCSSToAppletProcess(util.selector))
enable && (util.selector = unoCSSToAppletProcess(util.selector))
return util
}],
prefix: options.prefix,
Expand Down
6 changes: 3 additions & 3 deletions packages/preset-rem-to-rpx/README.md
Expand Up @@ -34,19 +34,19 @@ export interface RemToRpxOptions {
* 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
}
```

Expand Down
2 changes: 1 addition & 1 deletion packages/preset-rem-to-rpx/package.json
Expand Up @@ -37,6 +37,6 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.22"
"@unocss/core": "^0.45.23"
}
}
29 changes: 16 additions & 13 deletions packages/preset-rem-to-rpx/src/index.ts
@@ -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,
};
}
}
2 changes: 1 addition & 1 deletion packages/transformer-applet/README.md
Expand Up @@ -36,7 +36,7 @@ export interface TransformerAppletOptions {
* e.g. In uniapp set `enable: !(process.env.UNI_PLATFORM === 'h5')` to disable for h5
* @default true
*/
enable?: boolean;
enable?: boolean

/**
* Prefix for compile class name
Expand Down
4 changes: 2 additions & 2 deletions packages/transformer-applet/package.json
Expand Up @@ -35,9 +35,9 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.22"
"@unocss/core": "^0.45.23"
},
"devDependencies": {
"magic-string": "^0.26.3"
"magic-string": "^0.26.4"
}
}
10 changes: 5 additions & 5 deletions packages/transformer-applet/src/types.ts
Expand Up @@ -4,31 +4,31 @@ export interface TransformerAppletOptions {
* e.g. In uniapp set `enable: !(process.env.UNI_PLATFORM === 'h5')` to disable for h5
* @default true
*/
enable?: boolean;
enable?: boolean

/**
* Prefix for compile class name
* @default 'uno-'
* e.g. bg-[hsl(2.7,81.9%,69.6%)] to uno-98db2v
*/
classPrefix?: string;
classPrefix?: string

/**
* Prefix for ignore compile string
* If the string contains ignore prefix, it will be replaced with an empty string.
* e.g. 'applet-ignore: bg-[hsl(2.7,81.9%,69.6%)]' to 'bg-[hsl(2.7,81.9%,69.6%)]'
* @default 'applet-ignore:'
*/
ignorePrefix?: string;
ignorePrefix?: string

/**
* Hash function
*/
hashFn?: (str: string) => string;
hashFn?: (str: string) => string

/**
* The layer name of generated rules
* @default 'applet_shortcuts'
*/
layer?: string;
layer?: string
}
4 changes: 2 additions & 2 deletions packages/transformer-attributify/package.json
Expand Up @@ -35,9 +35,9 @@
"stub": "unbuild --stub"
},
"dependencies": {
"@unocss/core": "^0.45.22"
"@unocss/core": "^0.45.23"
},
"devDependencies": {
"magic-string": "^0.26.3"
"magic-string": "^0.26.4"
}
}

0 comments on commit 7fea351

Please sign in to comment.