|
1 | | -# winjs-plugin-example |
| 1 | +# @winner-fed/plugin-viewport |
2 | 2 |
|
3 | | -Example plugin for WinJS. |
| 3 | +Viewport plugin for WinJS. |
4 | 4 |
|
5 | 5 | <p> |
6 | | - <a href="https://npmjs.com/package/winjs-plugin-example"> |
7 | | - <img src="https://img.shields.io/npm/v/winjs-plugin-example?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /> |
| 6 | + <a href="https://npmjs.com/package/@winner-fed/plugin-viewport"> |
| 7 | + <img src="https://img.shields.io/npm/v/@winner-fed/plugin-viewport?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /> |
8 | 8 | </a> |
9 | 9 | <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" /> |
10 | | - <a href="https://npmcharts.com/compare/winjs-plugin-example?minimal=true"><img src="https://img.shields.io/npm/dm/winjs-plugin-example.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a> |
| 10 | + <a href="https://npmcharts.com/compare/@winner-fed/plugin-viewport?minimal=true"><img src="https://img.shields.io/npm/dm/@winner-fed/plugin-viewport.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a> |
11 | 11 | </p> |
12 | 12 |
|
| 13 | +底层基于 [postcss-mobile-forever](https://github.com/wswmsword/postcss-mobile-forever) 封装。 |
| 14 | + |
13 | 15 | ## Usage |
14 | 16 |
|
15 | 17 | Install: |
16 | 18 |
|
17 | 19 | ```bash |
18 | | -npm add winjs-plugin-example -D |
| 20 | +npm add @winner-fed/plugin-viewport -D |
19 | 21 | ``` |
20 | 22 |
|
21 | 23 | Add plugin to your `.winrc.ts`: |
22 | 24 |
|
23 | 25 | ```ts |
24 | 26 | // .winrc.ts |
25 | 27 | export default { |
26 | | - plugins: ['winjs-plugin-example'], |
| 28 | + plugins: ['@winner-fed/plugin-viewport'], |
27 | 29 | // 开启配置 |
28 | | - example: {} |
| 30 | + // 参考 https://github.com/wswmsword/postcss-mobile-forever?tab=readme-ov-file#%E9%85%8D%E7%BD%AE%E5%8F%82%E6%95%B0 |
| 31 | + viewport: {} |
29 | 32 | }; |
30 | 33 | ``` |
31 | 34 |
|
32 | 35 | ## Options |
33 | 36 |
|
34 | | -### foo |
35 | | - |
36 | | -Some description. |
| 37 | +| Name | Type | Default | Desc | |
| 38 | +|:--|:--|:--|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 39 | +| viewportWidth | number\|(file: string) => number | 750 | 应用基于该宽度进行开发,转换后的伸缩视图将会以该宽度的视图作为标准进行比例伸缩;可以传递函数动态生成宽度,例如 `file => file.includes("vant") ? 375 : 750` 表示在名称包含“vant”的文件内使用 375px 的宽度,而其他文件使用 750px 的宽度 | |
| 40 | +| mobileUnit | string | "vw" | 移动端竖屏视口视图,转换成什么伸缩单位?设置为 `rem` 后激活 **rem-mode** | |
| 41 | +| maxDisplayWidth | number | / | 伸缩视图的最大宽度 | |
| 42 | +| basicRemWidth | number | / | *rem-mode* 的基准宽度,若不设定,将通过 `viewportWidth` 获取 | |
| 43 | +| enableMediaQuery | boolean | false | 打开媒体查询模式,打开后将自动关闭 `maxDisplayWidth`,激活 **mq-mode** | |
| 44 | +| desktopWidth | number | 600 | 适配到桌面端宽度时,展示的视图宽度 | |
| 45 | +| landscapeWidth | number | 425 | 适配到移动端横屏宽度时,展示的视图宽度 | |
| 46 | +| appSelector | string | / | 页面最外层选择器,例如“`#app`”,用于设置在桌面端和移动端横屏时的居中样式,样式文件中至少要包含空的选择器 `#app {}` | |
| 47 | +| appContainingBlock | "calc"\|"manual"\|"auto" | "calc" | 该属性和矫正 `fixed` 定位元素有关,`manual` 将不矫正;`calc` 将通过插件主动计算的方式矫正元素尺寸,是默认行为;`auto` 将通过 `transform: translateZ(0)` 强制设置根[包含块](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Containing_block)为 `appSelector`,从而自动矫正元素,并且此时需要设置属性 `necessarySelectorWhenAuto` | |
| 48 | +| necessarySelectorWhenAuto | string | / | 当 `appContainingBlock` 设为 `auto` 时,需要指定该属性,该属性指定了 `appSelector` 往内一层的元素选择器,查看一个[关于指定元素作为包含块的实验](https://github.com/wswmsword/web-experiences/tree/main/css/fixed-on-containing-block)以了解如何使用该属性,您也可以查看[使用这个属性的示例项目](./example/cases/auto-app-containing-block/postcss.config.js)以了解如何使用这个属性 | |
| 49 | +| border | boolean\|string | false | 在页面外层展示边框吗,用于分辨居中的小版心布局和背景,可以设置颜色字符串 | |
| 50 | +| disableDesktop | boolean | false | 打开则不做桌面端适配,使用该参数前需要打开 `enableMediaQuery` | |
| 51 | +| disableLandscape | boolean | false | 打开则不做移动端横屏适配,使用该参数前需要打开 `enableMediaQuery` | |
| 52 | +| disableMobile | boolean | false | 打开则不做移动端竖屏适配,把 px 转换为视口单位,如 vw | |
| 53 | +| exclude | RegExp\|RegExp[] | / | 排除文件或文件夹 | |
| 54 | +| include | RegExp\|RegExp[] | / | 包括文件或文件夹 | |
| 55 | +| unitPrecision | number | 3 | 单位精确到小数点后几位? | |
| 56 | +| propList | string[] | ['*'] | 哪些属性要替换,哪些属性忽略?用法参考 [postcss-px-to-viewport 文档](https://github.com/evrone/postcss-px-to-viewport/blob/HEAD/README_CN.md) | |
| 57 | +| selectorBlackList | (string\|RegExp)[] | [] | 选择器黑名单,名单上的不转换 | |
| 58 | +| propertyBlackList | propertyBlackList | [] | 属性黑名单,名单上的不转换,如果要指定选择器内的属性,用对象的键表示选择器名称,具体用法见 [vant 的范例代码](./example/others/vant-vue/postcss.config.cjs#L9C17-L9C17) | |
| 59 | +| valueBlackList | (string\|RegExp)[] | [] | 属性值黑名单,名单上的值不转换 | |
| 60 | +| rootContainingBlockSelectorList | (string\|RegExp)[] | [] | 包含块是根元素的选择器列表,效果和标注注释 `/* root-containing-block */` 相同 | |
| 61 | +| verticalWritingSelectorList | (string\|RegExp)[] | [] | 纵向书写模式的选择器列表,效果和在选择器顶部标注注释 `/* vertical-writing-mode */` 相同 | |
| 62 | +| minDesktopDisplayWidth | number | / | 宽度断点,如果不提供这个值,默认使用 `desktopWidth` 的值,视图大于这个宽度,则页面宽度是桌面端宽度 `desktopWidth`,“原理和输入输出范例”一节具体介绍了该值的触发情况 | |
| 63 | +| maxLandscapeDisplayHeight | number | 640 | 高度断点,视图小于这个高度,并满足一定条件,则页面使用移动端横屏宽度,“原理和输入输出范例”一节具体介绍了该值的触发情况 | |
| 64 | +| side | any | / | 侧边配置,在桌面端媒体查询中生效,用于利用宽屏的空间,后文将介绍它的若干子属性 | |
| 65 | +| comment | any | / | 自定义注释,改变注释的名称,后文将介绍它的若干子属性 | |
| 66 | +| customLengthProperty | any | / | 用于指定需要添加到桌面端或横屏的自定义变量(css 变量,`var(...)`),如果不指定,默认**所有**和长度有关的属性,如果使用了自定义变量,都会被添加入桌面端和横屏,后文将介绍它的若干子属性 | |
| 67 | +| experimental.extract | boolean | false | 提取桌面端与横屏样式代码,用于生产环境,用于代码分割优化产包,具体查看“注意事项”一节 | |
| 68 | +| experimental.minDisplayWidth | number | / | 限制最小宽度,和 `maxDisplayWidth` 搭配使用 |
37 | 69 |
|
38 | | -- Type: `string` |
39 | | -- Default: `undefined` |
40 | | -- Example: |
| 70 | +### 默认配置参数 |
41 | 71 |
|
42 | 72 | ```js |
43 | | -export default { |
44 | | - plugins: ['winjs-plugin-example'], |
45 | | - // 开启配置 |
46 | | - example: { |
47 | | - foo: 'bar' |
| 73 | +{ |
| 74 | + "viewportWidth": 750, |
| 75 | + "maxDisplayWidth": null, |
| 76 | + "enableMediaQuery": false, |
| 77 | + "desktopWidth": 600, |
| 78 | + "landscapeWidth": 425, |
| 79 | + "minDesktopDisplayWidth": null, |
| 80 | + "maxLandscapeDisplayHeight": 640, |
| 81 | + "appSelector": "#app", |
| 82 | + "appContainingBlock": "calc", |
| 83 | + "necessarySelectorWhenAuto": null, |
| 84 | + "border": false, |
| 85 | + "disableDesktop": false, |
| 86 | + "disableLandscape": false, |
| 87 | + "disableMobile": false, |
| 88 | + "exclude": null, |
| 89 | + "include": null, |
| 90 | + "unitPrecision": 3, |
| 91 | + "selectorBlackList": [], |
| 92 | + "valueBlackList": [], |
| 93 | + "rootContainingBlockSelectorList": [], |
| 94 | + "verticalWritingSelectorList": [], |
| 95 | + "propList": ["*"], |
| 96 | + "mobileUnit": "vw", |
| 97 | + "side": { |
| 98 | + "width": null, |
| 99 | + "gap": 18, |
| 100 | + "selector1": null, |
| 101 | + "selector2": null, |
| 102 | + "selector3": null, |
| 103 | + "selector4": null, |
| 104 | + "width1": null, |
| 105 | + "width2": null, |
| 106 | + "width3": null, |
| 107 | + "width4": null |
| 108 | + }, |
| 109 | + "comment": { |
| 110 | + "applyWithoutConvert": "apply-without-convert", |
| 111 | + "rootContainingBlock": "root-containing-block", |
| 112 | + "notRootContainingBlock": "not-root-containing-block", |
| 113 | + "ignoreNext": "mobile-ignore-next", |
| 114 | + "ignoreLine": "mobile-ignore", |
| 115 | + "verticalWritingMode": "vertical-writing-mode" |
| 116 | + }, |
| 117 | + "customLengthProperty": { |
| 118 | + "rootContainingBlockList_LR": [], |
| 119 | + "rootContainingBlockList_NOT_LR": [], |
| 120 | + "ancestorContainingBlockList": [], |
| 121 | + "disableAutoApply": false |
| 122 | + }, |
| 123 | + "experimental": { |
| 124 | + "extract": false, |
| 125 | + "minDisplayWidth": null |
48 | 126 | } |
49 | | -}; |
| 127 | +} |
50 | 128 | ``` |
51 | 129 |
|
52 | 130 | ## License |
|
0 commit comments