oipage 1.2.1 → 1.3.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +14 -1
- package/README.md +80 -80
- package/bin/data/mineTypes.json +104 -104
- package/bin/disk.js +31 -31
- package/bin/help.js +24 -24
- package/bin/intercept.js +8 -0
- package/bin/run +1 -0
- package/bin/serve.js +7 -1
- package/bin/template/404.html +171 -171
- package/bin/tools/format.js +88 -88
- package/bin/tools/network.js +42 -42
- package/bin/tools/resolve404.js +83 -83
- package/bin/tools/resolveImport.js +3 -1
- package/nodejs/animation/index.d.ts +11 -11
- package/nodejs/animation/index.js +104 -104
- package/nodejs/cmdlog/index.d.ts +20 -20
- package/nodejs/cmdlog/index.js +75 -75
- package/nodejs/disk/index.d.ts +16 -16
- package/nodejs/disk/index.js +78 -78
- package/nodejs/logform/index.d.ts +18 -18
- package/nodejs/logform/index.js +94 -94
- package/nodejs/reader/index.d.ts +33 -0
- package/nodejs/reader/index.js +26 -0
- package/nodejs/throttle/index.d.ts +30 -30
- package/nodejs/throttle/index.js +50 -50
- package/package.json +40 -40
- package/web/animation/index.d.ts +11 -11
- package/web/animation/index.js +104 -104
- package/web/onReady/index.d.ts +7 -7
- package/web/onReady/index.js +8 -8
- package/web/reader/index.d.ts +33 -0
- package/web/reader/index.js +25 -0
- package/web/style/index.d.ts +21 -21
- package/web/style/index.js +19 -19
- package/web/throttle/index.d.ts +30 -30
- package/web/throttle/index.js +50 -50
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "oipage",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
|
|
5
|
-
"sideEffects": false,
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "node ./build/index.js watch",
|
|
8
|
-
"build": "node ./build/index.js",
|
|
9
|
-
"serve": "node ./bin/run serve --config ./oipage.config.js"
|
|
10
|
-
},
|
|
11
|
-
"bin": {
|
|
12
|
-
"oipage-cli": "bin/run"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/oi-contrib/OIPage.git"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"dev",
|
|
20
|
-
"server",
|
|
21
|
-
"style",
|
|
22
|
-
"css",
|
|
23
|
-
"nodejs",
|
|
24
|
-
"core",
|
|
25
|
-
"oipage",
|
|
26
|
-
"browser"
|
|
27
|
-
],
|
|
28
|
-
"author": {
|
|
29
|
-
"name": "zxl20070701",
|
|
30
|
-
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
31
|
-
},
|
|
32
|
-
"license": "MIT",
|
|
33
|
-
"bugs": {
|
|
34
|
-
"url": "https://github.com/oi-contrib/OIPage/issues"
|
|
35
|
-
},
|
|
36
|
-
"homepage": "https://oi-contrib.github.io/OIPage",
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"vislite": "^1.3.0"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "oipage",
|
|
3
|
+
"version": "1.3.0-alpha.1",
|
|
4
|
+
"description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "node ./build/index.js watch",
|
|
8
|
+
"build": "node ./build/index.js",
|
|
9
|
+
"serve": "node ./bin/run serve --config ./oipage.config.js"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"oipage-cli": "bin/run"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/oi-contrib/OIPage.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"dev",
|
|
20
|
+
"server",
|
|
21
|
+
"style",
|
|
22
|
+
"css",
|
|
23
|
+
"nodejs",
|
|
24
|
+
"core",
|
|
25
|
+
"oipage",
|
|
26
|
+
"browser"
|
|
27
|
+
],
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "zxl20070701",
|
|
30
|
+
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/oi-contrib/OIPage/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://oi-contrib.github.io/OIPage",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"vislite": "^1.3.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/web/animation/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
interface animationFun {
|
|
2
|
-
(deep: number): void
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 轮询动画,返回一个函数,调用该函数,可以提前结束动画
|
|
7
|
-
*/
|
|
8
|
-
export interface animationType {
|
|
9
|
-
(doback: animationFun, duration?: number, callback?: animationFun): Function
|
|
10
|
-
}
|
|
11
|
-
|
|
1
|
+
interface animationFun {
|
|
2
|
+
(deep: number): void
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 轮询动画,返回一个函数,调用该函数,可以提前结束动画
|
|
7
|
+
*/
|
|
8
|
+
export interface animationType {
|
|
9
|
+
(doback: animationFun, duration?: number, callback?: animationFun): Function
|
|
10
|
+
}
|
|
11
|
+
|
|
12
12
|
export let animation: animationType
|
package/web/animation/index.js
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* animation of OIPage v1.
|
|
2
|
+
* animation of OIPage v1.3.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
//当前正在运动的动画的tick函数堆栈
|
|
7
|
-
var $timers = [];
|
|
8
|
-
//唯一定时器的定时间隔
|
|
9
|
-
var $interval = 13;
|
|
10
|
-
//定时器ID
|
|
11
|
-
var $timerId;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 动画轮播
|
|
15
|
-
* @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
|
|
16
|
-
* @param {number} duration 动画时长,可选
|
|
17
|
-
* @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
|
|
18
|
-
*
|
|
19
|
-
* @returns {function} 返回一个函数,调用该函数,可以提前结束动画
|
|
20
|
-
*/
|
|
21
|
-
export function animation(doback, duration, callback) {
|
|
22
|
-
if (arguments.length < 2) duration = 400;
|
|
23
|
-
if (arguments.length < 3) callback = function () { };
|
|
24
|
-
|
|
25
|
-
var clock = {
|
|
26
|
-
//把tick函数推入堆栈
|
|
27
|
-
"timer": function (tick, duration, callback) {
|
|
28
|
-
if (!tick) {
|
|
29
|
-
throw new Error('Tick is required!');
|
|
30
|
-
}
|
|
31
|
-
var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
|
|
32
|
-
$timers.push({
|
|
33
|
-
"id": id,
|
|
34
|
-
"createTime": new Date(),
|
|
35
|
-
"tick": tick,
|
|
36
|
-
"duration": duration,
|
|
37
|
-
"callback": callback
|
|
38
|
-
});
|
|
39
|
-
clock.start();
|
|
40
|
-
return id;
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
//开启唯一的定时器timerId
|
|
44
|
-
"start": function () {
|
|
45
|
-
if (!$timerId) {
|
|
46
|
-
$timerId = setInterval(clock.tick, $interval);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
//被定时器调用,遍历timers堆栈
|
|
51
|
-
"tick": function () {
|
|
52
|
-
var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
|
|
53
|
-
|
|
54
|
-
$timers = [];
|
|
55
|
-
$timers.length = 0;
|
|
56
|
-
|
|
57
|
-
for (flag = 0; flag < timers.length; flag++) {
|
|
58
|
-
//初始化数据
|
|
59
|
-
timer = timers[flag];
|
|
60
|
-
createTime = timer.createTime;
|
|
61
|
-
tick = timer.tick;
|
|
62
|
-
duration = timer.duration;
|
|
63
|
-
callback = timer.callback;
|
|
64
|
-
|
|
65
|
-
//执行
|
|
66
|
-
passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
|
|
67
|
-
passTime = passTime > 1 ? 1 : passTime;
|
|
68
|
-
tick(passTime);
|
|
69
|
-
if (passTime < 1 && timer.id) {
|
|
70
|
-
//动画没有结束再添加
|
|
71
|
-
$timers.push(timer);
|
|
72
|
-
} else {
|
|
73
|
-
callback(passTime);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if ($timers.length <= 0) {
|
|
77
|
-
clock.stop();
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
//停止定时器,重置timerId=null
|
|
82
|
-
"stop": function () {
|
|
83
|
-
if ($timerId) {
|
|
84
|
-
clearInterval($timerId);
|
|
85
|
-
$timerId = null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
var id = clock.timer(function (deep) {
|
|
91
|
-
//其中deep为0-1,表示改变的程度
|
|
92
|
-
doback(deep);
|
|
93
|
-
}, duration, callback);
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
// 一个函数
|
|
97
|
-
// 用于在动画结束前结束动画
|
|
98
|
-
stop: function () {
|
|
99
|
-
var i;
|
|
100
|
-
for (i in $timers) {
|
|
101
|
-
if ($timers[i].id == id) {
|
|
102
|
-
$timers[i].id = void 0;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
6
|
+
//当前正在运动的动画的tick函数堆栈
|
|
7
|
+
var $timers = [];
|
|
8
|
+
//唯一定时器的定时间隔
|
|
9
|
+
var $interval = 13;
|
|
10
|
+
//定时器ID
|
|
11
|
+
var $timerId;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 动画轮播
|
|
15
|
+
* @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
|
|
16
|
+
* @param {number} duration 动画时长,可选
|
|
17
|
+
* @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
|
|
18
|
+
*
|
|
19
|
+
* @returns {function} 返回一个函数,调用该函数,可以提前结束动画
|
|
20
|
+
*/
|
|
21
|
+
export function animation(doback, duration, callback) {
|
|
22
|
+
if (arguments.length < 2) duration = 400;
|
|
23
|
+
if (arguments.length < 3) callback = function () { };
|
|
24
|
+
|
|
25
|
+
var clock = {
|
|
26
|
+
//把tick函数推入堆栈
|
|
27
|
+
"timer": function (tick, duration, callback) {
|
|
28
|
+
if (!tick) {
|
|
29
|
+
throw new Error('Tick is required!');
|
|
30
|
+
}
|
|
31
|
+
var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
|
|
32
|
+
$timers.push({
|
|
33
|
+
"id": id,
|
|
34
|
+
"createTime": new Date(),
|
|
35
|
+
"tick": tick,
|
|
36
|
+
"duration": duration,
|
|
37
|
+
"callback": callback
|
|
38
|
+
});
|
|
39
|
+
clock.start();
|
|
40
|
+
return id;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
//开启唯一的定时器timerId
|
|
44
|
+
"start": function () {
|
|
45
|
+
if (!$timerId) {
|
|
46
|
+
$timerId = setInterval(clock.tick, $interval);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
//被定时器调用,遍历timers堆栈
|
|
51
|
+
"tick": function () {
|
|
52
|
+
var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
|
|
53
|
+
|
|
54
|
+
$timers = [];
|
|
55
|
+
$timers.length = 0;
|
|
56
|
+
|
|
57
|
+
for (flag = 0; flag < timers.length; flag++) {
|
|
58
|
+
//初始化数据
|
|
59
|
+
timer = timers[flag];
|
|
60
|
+
createTime = timer.createTime;
|
|
61
|
+
tick = timer.tick;
|
|
62
|
+
duration = timer.duration;
|
|
63
|
+
callback = timer.callback;
|
|
64
|
+
|
|
65
|
+
//执行
|
|
66
|
+
passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
|
|
67
|
+
passTime = passTime > 1 ? 1 : passTime;
|
|
68
|
+
tick(passTime);
|
|
69
|
+
if (passTime < 1 && timer.id) {
|
|
70
|
+
//动画没有结束再添加
|
|
71
|
+
$timers.push(timer);
|
|
72
|
+
} else {
|
|
73
|
+
callback(passTime);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if ($timers.length <= 0) {
|
|
77
|
+
clock.stop();
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
//停止定时器,重置timerId=null
|
|
82
|
+
"stop": function () {
|
|
83
|
+
if ($timerId) {
|
|
84
|
+
clearInterval($timerId);
|
|
85
|
+
$timerId = null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
var id = clock.timer(function (deep) {
|
|
91
|
+
//其中deep为0-1,表示改变的程度
|
|
92
|
+
doback(deep);
|
|
93
|
+
}, duration, callback);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
// 一个函数
|
|
97
|
+
// 用于在动画结束前结束动画
|
|
98
|
+
stop: function () {
|
|
99
|
+
var i;
|
|
100
|
+
for (i in $timers) {
|
|
101
|
+
if ($timers[i].id == id) {
|
|
102
|
+
$timers[i].id = void 0;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
109
|
}
|
package/web/onReady/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 等待DOM加载完毕执行
|
|
3
|
-
*/
|
|
4
|
-
export interface onReadyType {
|
|
5
|
-
(callback: Function): void
|
|
6
|
-
}
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 等待DOM加载完毕执行
|
|
3
|
+
*/
|
|
4
|
+
export interface onReadyType {
|
|
5
|
+
(callback: Function): void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
8
|
export let onReady: onReadyType
|
package/web/onReady/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* onReady of OIPage v1.
|
|
2
|
+
* onReady of OIPage v1.3.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export function onReady(callback) {
|
|
7
|
-
var readyState = document.readyState;
|
|
8
|
-
if (readyState === 'interactive' || readyState === 'complete') {
|
|
9
|
-
callback();
|
|
10
|
-
} else {
|
|
11
|
-
window.addEventListener("DOMContentLoaded", callback);
|
|
12
|
-
}
|
|
6
|
+
export function onReady(callback) {
|
|
7
|
+
var readyState = document.readyState;
|
|
8
|
+
if (readyState === 'interactive' || readyState === 'complete') {
|
|
9
|
+
callback();
|
|
10
|
+
} else {
|
|
11
|
+
window.addEventListener("DOMContentLoaded", callback);
|
|
12
|
+
}
|
|
13
13
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本分析读取器
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface readerInstanceType {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 当前字符位置
|
|
9
|
+
*/
|
|
10
|
+
index: number
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 当前字符内容
|
|
14
|
+
*/
|
|
15
|
+
value: string
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 读取下一个字符
|
|
19
|
+
*/
|
|
20
|
+
readNext(): string
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 获取往后count个值
|
|
24
|
+
* @param count
|
|
25
|
+
*/
|
|
26
|
+
getNextN(count: number): string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface readerType {
|
|
30
|
+
(plain: string): readerInstanceType
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export let reader: readerType
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* reader of OIPage v1.3.0-alpha.1
|
|
3
|
+
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function reader(plain) {
|
|
7
|
+
|
|
8
|
+
let handler = {
|
|
9
|
+
index: -1,
|
|
10
|
+
value: null
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// 读取下一个字符
|
|
14
|
+
handler.readNext = function () {
|
|
15
|
+
handler.value = handler.index++ < plain.length - 1 ? plain[handler.index] : null;
|
|
16
|
+
return handler.value;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// 获取往后num个值
|
|
20
|
+
handler.getNextN = function (num) {
|
|
21
|
+
return express.substring(handler.index, num + handler.index > plain.length ? plain.length : num + handler.index);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return handler;
|
|
25
|
+
}
|
package/web/style/index.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 设置节点样式
|
|
3
|
-
*/
|
|
4
|
-
export interface setStyleType {
|
|
5
|
-
(el: HTMLElement, styles: {
|
|
6
|
-
[key: string]: string | number
|
|
7
|
-
}): void
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export let setStyle: setStyleType
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 获取节点样式
|
|
14
|
-
*/
|
|
15
|
-
export interface getStyleType {
|
|
16
|
-
(el: HTMLElement, name: string): string
|
|
17
|
-
(el: HTMLElement): {
|
|
18
|
-
[key: string]: string
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 设置节点样式
|
|
3
|
+
*/
|
|
4
|
+
export interface setStyleType {
|
|
5
|
+
(el: HTMLElement, styles: {
|
|
6
|
+
[key: string]: string | number
|
|
7
|
+
}): void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export let setStyle: setStyleType
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 获取节点样式
|
|
14
|
+
*/
|
|
15
|
+
export interface getStyleType {
|
|
16
|
+
(el: HTMLElement, name: string): string
|
|
17
|
+
(el: HTMLElement): {
|
|
18
|
+
[key: string]: string
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
22
|
export let getStyle: getStyleType
|
package/web/style/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* style of OIPage v1.
|
|
2
|
+
* style of OIPage v1.3.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export function setStyle(el, styles) {
|
|
7
|
-
for (var key in styles) {
|
|
8
|
-
el.style[key] = styles[key];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function getStyle(el, name) {
|
|
13
|
-
|
|
14
|
-
// 获取结点的全部样式
|
|
15
|
-
var allStyle = document.defaultView && document.defaultView.getComputedStyle ?
|
|
16
|
-
document.defaultView.getComputedStyle(el, null) :
|
|
17
|
-
el.currentStyle;
|
|
18
|
-
|
|
19
|
-
// 如果没有指定属性名称,返回全部样式
|
|
20
|
-
return typeof name === 'string' ?
|
|
21
|
-
allStyle.getPropertyValue(name) :
|
|
22
|
-
allStyle;
|
|
23
|
-
|
|
6
|
+
export function setStyle(el, styles) {
|
|
7
|
+
for (var key in styles) {
|
|
8
|
+
el.style[key] = styles[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getStyle(el, name) {
|
|
13
|
+
|
|
14
|
+
// 获取结点的全部样式
|
|
15
|
+
var allStyle = document.defaultView && document.defaultView.getComputedStyle ?
|
|
16
|
+
document.defaultView.getComputedStyle(el, null) :
|
|
17
|
+
el.currentStyle;
|
|
18
|
+
|
|
19
|
+
// 如果没有指定属性名称,返回全部样式
|
|
20
|
+
return typeof name === 'string' ?
|
|
21
|
+
allStyle.getPropertyValue(name) :
|
|
22
|
+
allStyle;
|
|
23
|
+
|
|
24
24
|
}
|
package/web/throttle/index.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
export type throttleOpportunityType = "begin" | "end" | "wide"
|
|
2
|
-
|
|
3
|
-
export interface throttleOptionType {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 节流时长
|
|
7
|
-
*/
|
|
8
|
-
time?: number
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 是否持续节流
|
|
12
|
-
*/
|
|
13
|
-
keep?: boolean
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 执行时机
|
|
17
|
-
*
|
|
18
|
-
* begin(开始触发)、end(结束触发)、wide(第一次开始触发,其余结束触发)
|
|
19
|
-
*/
|
|
20
|
-
opportunity?: throttleOpportunityType
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 节流函数
|
|
26
|
-
*/
|
|
27
|
-
export interface throttleType {
|
|
28
|
-
(callback: Function, option?: throttleOptionType): Function
|
|
29
|
-
}
|
|
30
|
-
|
|
1
|
+
export type throttleOpportunityType = "begin" | "end" | "wide"
|
|
2
|
+
|
|
3
|
+
export interface throttleOptionType {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 节流时长
|
|
7
|
+
*/
|
|
8
|
+
time?: number
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 是否持续节流
|
|
12
|
+
*/
|
|
13
|
+
keep?: boolean
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 执行时机
|
|
17
|
+
*
|
|
18
|
+
* begin(开始触发)、end(结束触发)、wide(第一次开始触发,其余结束触发)
|
|
19
|
+
*/
|
|
20
|
+
opportunity?: throttleOpportunityType
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 节流函数
|
|
26
|
+
*/
|
|
27
|
+
export interface throttleType {
|
|
28
|
+
(callback: Function, option?: throttleOptionType): Function
|
|
29
|
+
}
|
|
30
|
+
|
|
31
31
|
export let throttle: throttleType
|
package/web/throttle/index.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* throttle of OIPage v1.
|
|
2
|
+
* throttle of OIPage v1.3.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export function throttle(callback, _option) {
|
|
7
|
-
|
|
8
|
-
// 缺省值
|
|
9
|
-
var option = {
|
|
10
|
-
time: 200,
|
|
11
|
-
keep: false,
|
|
12
|
-
opportunity: "end"
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// 校对
|
|
16
|
-
if (_option) {
|
|
17
|
-
for (var key in _option) {
|
|
18
|
-
option[key] = _option[key];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
var hadInterval = false, hadClick = false, oneClick = false, arg;
|
|
23
|
-
return function () {
|
|
24
|
-
const _this = this;
|
|
25
|
-
arg = arguments;
|
|
26
|
-
|
|
27
|
-
// 如果前置任务都完成了
|
|
28
|
-
if (!hadInterval) {
|
|
29
|
-
if (option.opportunity != 'end') {
|
|
30
|
-
callback.apply(_this, arg);
|
|
31
|
-
}
|
|
32
|
-
hadInterval = true;
|
|
33
|
-
|
|
34
|
-
var interval = setInterval(() => {
|
|
35
|
-
if (hadClick) {
|
|
36
|
-
if (!option.keep) {
|
|
37
|
-
callback.apply(_this, arg);
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
if (option.opportunity != 'begin') {
|
|
41
|
-
if (oneClick || option.opportunity == 'end') callback.apply(_this, arg);
|
|
42
|
-
}
|
|
43
|
-
hadInterval = false;
|
|
44
|
-
oneClick = false;
|
|
45
|
-
clearInterval(interval);
|
|
46
|
-
}
|
|
47
|
-
hadClick = false;
|
|
48
|
-
}, option.time);
|
|
49
|
-
} else {
|
|
50
|
-
hadClick = true;
|
|
51
|
-
oneClick = true;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
};
|
|
6
|
+
export function throttle(callback, _option) {
|
|
7
|
+
|
|
8
|
+
// 缺省值
|
|
9
|
+
var option = {
|
|
10
|
+
time: 200,
|
|
11
|
+
keep: false,
|
|
12
|
+
opportunity: "end"
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// 校对
|
|
16
|
+
if (_option) {
|
|
17
|
+
for (var key in _option) {
|
|
18
|
+
option[key] = _option[key];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var hadInterval = false, hadClick = false, oneClick = false, arg;
|
|
23
|
+
return function () {
|
|
24
|
+
const _this = this;
|
|
25
|
+
arg = arguments;
|
|
26
|
+
|
|
27
|
+
// 如果前置任务都完成了
|
|
28
|
+
if (!hadInterval) {
|
|
29
|
+
if (option.opportunity != 'end') {
|
|
30
|
+
callback.apply(_this, arg);
|
|
31
|
+
}
|
|
32
|
+
hadInterval = true;
|
|
33
|
+
|
|
34
|
+
var interval = setInterval(() => {
|
|
35
|
+
if (hadClick) {
|
|
36
|
+
if (!option.keep) {
|
|
37
|
+
callback.apply(_this, arg);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
if (option.opportunity != 'begin') {
|
|
41
|
+
if (oneClick || option.opportunity == 'end') callback.apply(_this, arg);
|
|
42
|
+
}
|
|
43
|
+
hadInterval = false;
|
|
44
|
+
oneClick = false;
|
|
45
|
+
clearInterval(interval);
|
|
46
|
+
}
|
|
47
|
+
hadClick = false;
|
|
48
|
+
}, option.time);
|
|
49
|
+
} else {
|
|
50
|
+
hadClick = true;
|
|
51
|
+
oneClick = true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
};
|
|
55
55
|
}
|