Skip to content

Commit ef57d08

Browse files
committed
build: 更新构建工具
1 parent 6c7ff48 commit ef57d08

33 files changed

+13491
-7373
lines changed

.babelrc

Lines changed: 0 additions & 11 deletions
This file was deleted.

.browserslistrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.editorconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
# Use 4 spaces for the Python files
13+
[*.py]
14+
indent_size = 4
15+
max_line_length = 80
16+
17+
# The JSON files contain newlines inconsistently
18+
[*.json]
19+
insert_final_newline = ignore
20+
21+
# Minified JavaScript files shouldn't be changed
22+
[**.min.js]
23+
indent_style = ignore
24+
insert_final_newline = ignore
25+
26+
# Makefiles always use tabs for indentation
27+
[Makefile]
28+
indent_style = tab
29+
30+
# Batch files use tabs for indentation
31+
[*.bat]
32+
indent_style = tab
33+
34+
[*.md]
35+
trim_trailing_whitespace = false
36+

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.mocharc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"require": "./tests/setup.js"
3+
}

.npmrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
engine-strict=true
2+
# 默认代理
3+
registry=https://registry.npm.taobao.org/
4+
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
5+
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
6+
pngquant-bin=https://npm.taobao.org/mirrors/pngquant-bin/
7+
optipng_binary_site=https://npm.taobao.org/mirrors/optipng-bin/
8+
9+
@infzm:registry=http://119.29.101.140:4873/

.nycrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extension": [".js", ".vue"]
3+
}

.release-it.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"git": {
3+
"commitMessage": "ci: 更新版本至 ${version} | [CI SKIP]"
4+
},
5+
"plugins": {
6+
"@release-it/conventional-changelog": {
7+
"infile": "CHANGELOG.md",
8+
"header": "# 更新日志\n\n本文件将由[release-it](https://github.com/release-it/release-it)工具根据[约定式提交规范](https://www.conventionalcommits.org/zh-hans/v1.0.0/)下自动产出更新日志内容。\n\n> 更详细内容可查看文章[《自动产出changelog-第二节:自动产出》](https://uxfeel.com/2021/04/13/20210413-auto-changelog-section-two-generate-changelog/)\n\n---\n\n",
9+
"preset": {
10+
"name": "conventionalcommits",
11+
"types": [
12+
{ "type": "feat", "section": "✨ Features | 新功能" },
13+
{ "type": "fix", "section": "🐛 Bug Fixes | Bug 修复" },
14+
{ "type":"perf", "section":"⚡ Performance Improvements | 性能优化" },
15+
{ "type": "revert", "section": "⏪ Reverts | 回退" },
16+
{ "type": "chore", "section": "📦 Chores | 其他更新" },
17+
{ "type": "docs", "section": "📝 Documentation | 文档" },
18+
{ "type": "style", "section": "💄 Styles | 风格", "hidden": true },
19+
{ "type": "refactor", "section": "♻ Code Refactoring | 代码重构" },
20+
{ "type": "test", "section": "✅ Tests | 测试" },
21+
{ "type": "build", "section": "👷‍ Build System | 构建" },
22+
{ "type": "ci", "section": "🔧 Continuous Integration | CI 配置" }
23+
],
24+
"commitUrlFormat": "https://github.com/lpreterite/vpin/commit/{{hash}}",
25+
"issueUrlFormat": "https://github.com/lpreterite/vpin/issues/{{id}}",
26+
"compareUrlFormat": "https://github.com/lpreterite/vpin/compare/{{previousTag}}...{{currentTag}}"
27+
}
28+
}
29+
}
30+
}

LICENSE

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2019 packy
3+
Copyright (c) packy-tang <lpreterite@126.com> (https://github.com/lpreterite)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,13 @@ import { matchRange } from "vpin"
123123
const { effective, x, y, xLimit, yLimit } = matchRange({}, {})
124124
console.log(`是否在有效范围:%s; 范围:%s, %s, %s, %s`, effective ? "" : "", x, y, xLimit, yLimit)
125125
```
126+
127+
## Develop
128+
129+
本地调试
130+
131+
```sh
132+
$ npm run serve
133+
# or
134+
$ yarn serve
135+
```

babel.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const plugins = []
2+
if (process.env.NODE_ENV === 'test') {
3+
plugins.push(["istanbul"])
4+
}
5+
6+
module.exports = {
7+
"exclude": "node_modules/**",
8+
9+
"presets": [["@vue/app", { "useBuiltIns": "entry" }]],
10+
11+
plugins
12+
}

docs/Memo2.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# 设计笔记
2+
3+
## 目的
4+
5+
1.元素B在元素A内部
6+
2.屏幕滚动到元素A的位置后,让元素B跟随屏幕滚动
7+
3.屏幕滚动出元素A的位置后,让元素B停止跟随屏幕滚动
8+
9+
## 解析
10+
11+
首先的说几个点:
12+
13+
1. 基于屏幕定位,元素B使用`position:fixed`定位就能满足,基本不用计算。
14+
2. 基于父级实现屏幕定位,元素B使用`position:absolute`定位,定位基于父级计算给样式的值需要减去元素A基于页面的坐标量
15+
3. 计算加入偏移量,偏移量是基于屏幕给出的,满足固定在屏幕位置需求。没用偏移量只会固定到屏幕原点:`{top:0,left:0}`
16+
17+
参数来源和定义:
18+
19+
- 屏幕滚动坐标使用`window.pageXOffset``window.pageYOffset`较为安全(出于兼容性考虑)
20+
- 元素A的位置=触发位置,触发位置加上元素A高宽=有效范围;屏幕滚动到这个平面内元素B才会跟随才会触发计算
21+
- 随屏幕滚动有**基于父级计算****基于屏幕计算**两种实现方式
22+
- 基于页面的变量使用`page`前序
23+
- 基于父级的原坐标位置使用`origin`命名
24+
- 偏移量使用`offset`来命名
25+
26+
### 触发位置的计算
27+
28+
其实就是单纯地判断是否在元素A内部,这里需要得出四个点:
29+
30+
- x:元素A基于页面的横坐标
31+
- y:元素A基于页面的纵坐标
32+
- xLimit:元素A横坐标边界:元素A基于页面的X坐标 + 元素A的宽
33+
- yLimit:元素A纵坐标边界:元素A基于页面的Y坐标 + 元素A的高
34+
35+
页面滚动到这四个点的构成的平面内将判断为触发定位
36+
37+
```js
38+
const effective = ( window.pageXOffset > x && window.pageXOffset < xLimit ) || ( window.pageYOffset > y && window.pageYOffset < yLimit )
39+
```
40+
41+
### 屏幕定位
42+
43+
这个用css就能实现
44+
45+
```js
46+
const styleB = {
47+
top: 0,
48+
left: 0,
49+
position: "fixed"
50+
}
51+
```
52+
53+
具体定位在屏幕哪里,给上偏移量就好:
54+
55+
```js
56+
const offset = { x: 50, y: 50 }
57+
const styleB = {
58+
top: `${offset.y}px`,
59+
left: `${offset.x}px`,
60+
position: "fixed"
61+
}
62+
```
63+
64+
### 基于父级实现屏幕定位
65+
66+
元素A、元素B、滚动坐标,首先得搞清楚这三者的关系。
67+
68+
元素A必须是元素B的父级
69+
70+
```js
71+
const styleA = {
72+
position: "relative"
73+
}
74+
const styleB = {
75+
position: "absolute"
76+
}
77+
```
78+
79+
由于元素B的定位是基于元素A的,那么计算公式大概是:
80+
81+
```js
82+
const pageA = pageOffset(elA)
83+
const position = {
84+
x: window.pageXOffset - pageA.x
85+
y: window.pageYOffset - pageA.y
86+
}
87+
```
88+
89+
加上偏移量:
90+
91+
```js
92+
const offset = { x: 50, y: 50 }
93+
const pageA = pageOffset(elA)
94+
const position = {
95+
x: window.pageXOffset - pageA.x + offset.x
96+
y: window.pageYOffset - pageA.y + offset.y
97+
}
98+
```
99+
100+
获取元素B在元素A内部的原始定位:
101+
102+
```js
103+
const pageA = pageOffset(elA)
104+
const pageB = pageOffset(elB)
105+
106+
const originB = { x:pageB.x-pageA.x, y:pageB.y-pageA.y }
107+
```
108+
109+
滚动坐标未曾进入触发位置时,使用默认坐标,进入后使用计算后坐标:
110+
111+
```js
112+
const effective = ( window.pageXOffset > x && window.pageXOffset < xLimit ) || ( window.pageYOffset > y && window.pageYOffset < yLimit )
113+
114+
const styleB = {
115+
left: window.pageXOffset > x ? position.x : originB.x,
116+
top: window.pageYOffset > y ? position.y : originB.y
117+
}
118+
```
119+
120+
### 更好的实现
121+
122+
只用屏幕定位并不能满足大多数情况,比如页面滚动至页脚时**侧栏**压在页脚上了。为满足这类情况,需要做到在**有效范围**内才使用屏幕定位(`fiexd`),在范围外的将退为基于父级定位(`absolute`),就有比较理想的显示效果。
123+
124+
首先根据是否在有效范围内得出定位方式:
125+
126+
```js
127+
const effective = ( window.pageXOffset > x && window.pageXOffset < xLimit ) || ( window.pageYOffset > y && window.pageYOffset < yLimit )
128+
129+
const styleB = {
130+
position: effective ? 'fixed':'absolute'
131+
}
132+
```
133+
134+
> 在有效范围时,坐标用偏移值;
135+
> 在未进入有效范围时,坐标使用基于父级的原坐标值;
136+
> 在进入有效范围并离开后,坐标使用基于父级的计算坐标值
137+
138+
```js
139+
const effective = ( window.pageXOffset > x && window.pageXOffset < xLimit ) || ( window.pageYOffset > y && window.pageYOffset < yLimit )
140+
141+
const styleB = {
142+
position: effective ? 'fixed':'absolute'
143+
left: effective ? offset.x : (window.pageXOffset > x ? position.x : originB.x),
144+
top: effective ? offset.y : (window.pageYOffset > y ? position.y : originB.y)
145+
}
146+
```

0 commit comments

Comments
 (0)