@oipage/core.js 0.1.0-alpha.1 → 1.0.0-alpha.0
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/.github/FUNDING.yml +12 -0
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +4 -6
- package/LICENSE +20 -20
- package/README.md +33 -76
- package/dist/core.js +21 -0
- package/dist/core.min.js +5 -0
- package/package.json +29 -32
- package/src/Timer/index.js +7 -0
- package/src/index.js +1 -7
- package/types/Timer.d.ts +8 -0
- package/types/index.d.ts +3 -10
- package/dist/corejs.js +0 -172
- package/dist/corejs.min.js +0 -5
- package/src/animation/index.d.ts +0 -12
- package/src/animation/index.js +0 -102
- package/src/throttle/index.d.ts +0 -31
- package/src/throttle/index.js +0 -50
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# These are supported funding model platforms
|
|
2
|
+
|
|
3
|
+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
4
|
+
patreon: # Replace with a single Patreon username
|
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
+
otechie: # Replace with a single Otechie username
|
|
12
|
+
custom: ['https://zxl20070701.github.io/notebook/home.html']
|
package/AUTHORS.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Authors ordered by first contribution.
|
|
2
|
-
|
|
3
|
-
zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
|
|
4
|
-
|
|
5
|
-
-----------------------------------------------------
|
|
6
|
-
We thank all of them for their contributions!
|
|
1
|
+
Authors ordered by first contribution.
|
|
2
|
+
|
|
3
|
+
zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
|
|
4
|
+
|
|
5
|
+
-----------------------------------------------------
|
|
6
|
+
We thank all of them for their contributions!
|
package/CHANGELOG
CHANGED
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) zxl20070701 走一步,再走一步
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
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
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) zxl20070701 走一步,再走一步
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
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
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,77 +1,34 @@
|
|
|
1
|
-
# [core.js](https://github.com/oi-contrib/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
<p>
|
|
5
|
-
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@oipage/core.js&interval=7">
|
|
6
|
-
<img src="https://img.shields.io/npm/dm/@oipage/core.js.svg" alt="downloads">
|
|
7
|
-
</a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/@oipage/core.js">
|
|
9
|
-
<img src="https://img.shields.io/npm/v/@oipage/core.js.svg" alt="
|
|
10
|
-
</a>
|
|
11
|
-
<a href="https://github.com/oi-contrib/
|
|
12
|
-
<img
|
|
13
|
-
</a>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
当然,也可以单独引入:
|
|
37
|
-
|
|
38
|
-
```js
|
|
39
|
-
import { animation } from "@oipage/core.js/src/animation/index"
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
> 支持Typescript环境。
|
|
43
|
-
|
|
44
|
-
### Nodejs环境下
|
|
45
|
-
|
|
46
|
-
直接使用require语法即可:
|
|
47
|
-
|
|
48
|
-
```js
|
|
49
|
-
const { animation } = require("@oipage/core.js");
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 使用CDN方式
|
|
53
|
-
|
|
54
|
-
此外,在浏览器端,如果你不想使用npm管理,或者是老项目,也支持CDN的方式:
|
|
55
|
-
|
|
56
|
-
```html
|
|
57
|
-
<script src="https://cdn.jsdelivr.net/npm/@oipage/core.js"></script>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
然后直接:
|
|
61
|
-
|
|
62
|
-
```js
|
|
63
|
-
Corejs.animation(function(){
|
|
64
|
-
// todo
|
|
65
|
-
});
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
具体的API细节(使用import语法说明,其余方式类似),如下:
|
|
69
|
-
|
|
70
|
-
- [animation 动画](./docs/animation.md)
|
|
71
|
-
- [throttle 节流函数](./docs/throttle.md)
|
|
72
|
-
|
|
73
|
-
## 版权
|
|
74
|
-
|
|
75
|
-
MIT License
|
|
76
|
-
|
|
1
|
+
# [@oipage/core.js](https://github.com/oi-contrib/oipage-corejs)
|
|
2
|
+
包括日期、时间、浮点运算等常用的一些业务API
|
|
3
|
+
|
|
4
|
+
<p>
|
|
5
|
+
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@oipage/core.js&interval=7">
|
|
6
|
+
<img src="https://img.shields.io/npm/dm/@oipage/core.js.svg" alt="downloads">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@oipage/core.js">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@oipage/core.js.svg" alt="npm">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/oi-contrib/oipage-corejs/issues">
|
|
12
|
+
<img src="https://img.shields.io/github/issues/oi-contrib/oipage-corejs" alt="issue">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/oi-contrib/oipage-corejs" target='_blank'>
|
|
15
|
+
<img alt="GitHub repo stars" src="https://img.shields.io/github/stars/oi-contrib/oipage-corejs?style=social">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://github.com/oi-contrib/oipage-corejs">
|
|
18
|
+
<img src="https://img.shields.io/github/forks/oi-contrib/oipage-corejs" alt="forks">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://gitee.com/oi-contrib/oipage-corejs" target='_blank'>
|
|
21
|
+
<img alt="Gitee repo stars" src="https://gitee.com/oi-contrib/oipage-corejs/badge/star.svg">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://gitee.com/oi-contrib/oipage-corejs">
|
|
24
|
+
<img src="https://gitee.com/oi-contrib/oipage-corejs/badge/fork.svg" alt="forks">
|
|
25
|
+
</a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<img src="https://nodei.co/npm/@oipage/core.js.png?downloads=true&downloadRank=true&stars=true" alt="NPM">
|
|
29
|
+
|
|
30
|
+
## 版权
|
|
31
|
+
|
|
32
|
+
MIT License
|
|
33
|
+
|
|
77
34
|
Copyright (c) [zxl20070701](https://zxl20070701.github.io/notebook/home.html) 走一步,再走一步
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @oipage/corejs v1.0.0-alpha.0
|
|
3
|
+
* git+https://github.com/oi-contrib/oipage-corejs.git
|
|
4
|
+
*/
|
|
5
|
+
(function (global, factory) {
|
|
6
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
7
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
8
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.corejs = {}));
|
|
9
|
+
})(this, (function (exports) { 'use strict';
|
|
10
|
+
|
|
11
|
+
function Timer() {
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Timer.prototype.now = function () {
|
|
16
|
+
console.log("设置时间为当前时间");
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.Timer = Timer;
|
|
20
|
+
|
|
21
|
+
}));
|
package/dist/core.min.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @oipage/corejs v1.0.0-alpha.0
|
|
3
|
+
* git+https://github.com/oi-contrib/oipage-corejs.git
|
|
4
|
+
*/
|
|
5
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).corejs={})}(this,function(e){"use strict";function o(){}o.prototype.now=function(){console.log("设置时间为当前时间")},e.Timer=o});
|
package/package.json
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@oipage/core.js",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"typings": "./types/index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"rollup": "^4.6.1",
|
|
31
|
-
"terser": "^5.17.1"
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@oipage/core.js",
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
|
+
"description": "包括日期、时间、浮点运算等常用的一些业务API",
|
|
5
|
+
"main": "./dist/core.js",
|
|
6
|
+
"typings": "./types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "npm install && npm run dev",
|
|
9
|
+
"dev": "oipage-cli run \"rollup --config ./rollup.config.js -w\" \"oipage-cli serve -p 20000\"",
|
|
10
|
+
"build": "rollup --config ./rollup.config.js && terser ./dist/core.js --compress --mangle --output ./dist/core.min.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/oi-contrib/oipage-corejs.git"
|
|
15
|
+
},
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "zxl20070701",
|
|
18
|
+
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"oipage",
|
|
22
|
+
"core",
|
|
23
|
+
"javascript"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"rollup": "^4.6.1",
|
|
28
|
+
"terser": "^5.17.1"
|
|
29
|
+
}
|
|
33
30
|
}
|
package/src/index.js
CHANGED
package/types/Timer.d.ts
ADDED
package/types/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export default class Corejs {
|
|
5
|
-
static animation: animationType
|
|
6
|
-
static throttle: throttleType
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export let animation: animationType
|
|
10
|
-
export let throttle: throttleType
|
|
1
|
+
import TimerType from "./Timer"
|
|
2
|
+
|
|
3
|
+
export let Timer: TimerType
|
package/dist/corejs.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @oipage/core.js v0.1.0-alpha.1
|
|
3
|
-
* git+https://github.com/oi-contrib/core.js.git
|
|
4
|
-
*/
|
|
5
|
-
(function (global, factory) {
|
|
6
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
7
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
8
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Corejs = factory());
|
|
9
|
-
})(this, (function () { 'use strict';
|
|
10
|
-
|
|
11
|
-
//当前正在运动的动画的tick函数堆栈
|
|
12
|
-
var $timers = [];
|
|
13
|
-
//唯一定时器的定时间隔
|
|
14
|
-
var $interval = 13;
|
|
15
|
-
//定时器ID
|
|
16
|
-
var $timerId;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 动画轮播
|
|
20
|
-
* @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
|
|
21
|
-
* @param {number} duration 动画时长,可选
|
|
22
|
-
* @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
|
|
23
|
-
*
|
|
24
|
-
* @returns {function} 返回一个函数,调用该函数,可以提前结束动画
|
|
25
|
-
*/
|
|
26
|
-
function animation(doback, duration, callback) {
|
|
27
|
-
if (arguments.length < 2) duration = 400;
|
|
28
|
-
if (arguments.length < 3) callback = function () { };
|
|
29
|
-
|
|
30
|
-
var clock = {
|
|
31
|
-
//把tick函数推入堆栈
|
|
32
|
-
"timer": function (tick, duration, callback) {
|
|
33
|
-
if (!tick) {
|
|
34
|
-
throw new Error('Tick is required!');
|
|
35
|
-
}
|
|
36
|
-
var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
|
|
37
|
-
$timers.push({
|
|
38
|
-
"id": id,
|
|
39
|
-
"createTime": new Date(),
|
|
40
|
-
"tick": tick,
|
|
41
|
-
"duration": duration,
|
|
42
|
-
"callback": callback
|
|
43
|
-
});
|
|
44
|
-
clock.start();
|
|
45
|
-
return id;
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
//开启唯一的定时器timerId
|
|
49
|
-
"start": function () {
|
|
50
|
-
if (!$timerId) {
|
|
51
|
-
$timerId = setInterval(clock.tick, $interval);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
//被定时器调用,遍历timers堆栈
|
|
56
|
-
"tick": function () {
|
|
57
|
-
var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
|
|
58
|
-
|
|
59
|
-
$timers = [];
|
|
60
|
-
$timers.length = 0;
|
|
61
|
-
|
|
62
|
-
for (flag = 0; flag < timers.length; flag++) {
|
|
63
|
-
//初始化数据
|
|
64
|
-
timer = timers[flag];
|
|
65
|
-
createTime = timer.createTime;
|
|
66
|
-
tick = timer.tick;
|
|
67
|
-
duration = timer.duration;
|
|
68
|
-
callback = timer.callback;
|
|
69
|
-
|
|
70
|
-
//执行
|
|
71
|
-
passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
|
|
72
|
-
passTime = passTime > 1 ? 1 : passTime;
|
|
73
|
-
tick(passTime);
|
|
74
|
-
if (passTime < 1 && timer.id) {
|
|
75
|
-
//动画没有结束再添加
|
|
76
|
-
$timers.push(timer);
|
|
77
|
-
} else {
|
|
78
|
-
callback(passTime);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if ($timers.length <= 0) {
|
|
82
|
-
clock.stop();
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
//停止定时器,重置timerId=null
|
|
87
|
-
"stop": function () {
|
|
88
|
-
if ($timerId) {
|
|
89
|
-
clearInterval($timerId);
|
|
90
|
-
$timerId = null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
var id = clock.timer(function (deep) {
|
|
96
|
-
//其中deep为0-1,表示改变的程度
|
|
97
|
-
doback(deep);
|
|
98
|
-
}, duration, callback);
|
|
99
|
-
|
|
100
|
-
// 返回一个函数
|
|
101
|
-
// 用于在动画结束前结束动画
|
|
102
|
-
return function () {
|
|
103
|
-
var i;
|
|
104
|
-
for (i in $timers) {
|
|
105
|
-
if ($timers[i].id == id) {
|
|
106
|
-
$timers[i].id = void 0;
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function throttle(callback, _option) {
|
|
115
|
-
|
|
116
|
-
// 缺省值
|
|
117
|
-
var option = {
|
|
118
|
-
time: 200,
|
|
119
|
-
keep: false,
|
|
120
|
-
opportunity: "end"
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// 校对
|
|
124
|
-
if (_option) {
|
|
125
|
-
for (var key in _option) {
|
|
126
|
-
option[key] = _option[key];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
var hadInterval = false, hadClick = false, oneClick = false, arg;
|
|
131
|
-
return function () {
|
|
132
|
-
const _this = this;
|
|
133
|
-
arg = arguments;
|
|
134
|
-
|
|
135
|
-
// 如果前置任务都完成了
|
|
136
|
-
if (!hadInterval) {
|
|
137
|
-
if (option.opportunity != 'end') {
|
|
138
|
-
callback.apply(_this, arg);
|
|
139
|
-
}
|
|
140
|
-
hadInterval = true;
|
|
141
|
-
|
|
142
|
-
var interval = setInterval(() => {
|
|
143
|
-
if (hadClick) {
|
|
144
|
-
if (!option.keep) {
|
|
145
|
-
callback.apply(_this, arg);
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
if (option.opportunity != 'begin') {
|
|
149
|
-
if (oneClick || option.opportunity == 'end') callback.apply(_this, arg);
|
|
150
|
-
}
|
|
151
|
-
hadInterval = false;
|
|
152
|
-
oneClick = false;
|
|
153
|
-
clearInterval(interval);
|
|
154
|
-
}
|
|
155
|
-
hadClick = false;
|
|
156
|
-
}, option.time);
|
|
157
|
-
} else {
|
|
158
|
-
hadClick = true;
|
|
159
|
-
oneClick = true;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
var index = {
|
|
166
|
-
animation: animation,
|
|
167
|
-
throttle: throttle
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
return index;
|
|
171
|
-
|
|
172
|
-
}));
|
package/dist/corejs.min.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @oipage/core.js v0.1.0-alpha.1
|
|
3
|
-
* git+https://github.com/oi-contrib/core.js.git
|
|
4
|
-
*/
|
|
5
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Corejs=e()}(this,(function(){"use strict";var t,e=[];var n={animation:function(n,i,r){arguments.length<2&&(i=400),arguments.length<3&&(r=function(){});var o={timer:function(t,n,i){if(!t)throw new Error("Tick is required!");var r=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return e.push({id:r,createTime:new Date,tick:t,duration:n,callback:i}),o.start(),r},start:function(){t||(t=setInterval(o.tick,13))},tick:function(){var t,n,i,r,a,u,f,l=e;for((e=[]).length=0,n=0;n<l.length;n++)t=(a=l[n]).createTime,i=a.tick,u=a.duration,r=a.callback,i(f=(f=(+(new Date).valueOf()-t.valueOf())/u)>1?1:f),f<1&&a.id?e.push(a):r(f);e.length<=0&&o.stop()},stop:function(){t&&(clearInterval(t),t=null)}},a=o.timer((function(t){n(t)}),i,r);return function(){var t;for(t in e)if(e[t].id==a)return void(e[t].id=void 0)}},throttle:function(t,e){var n={time:200,keep:!1,opportunity:"end"};if(e)for(var i in e)n[i]=e[i];var r,o=!1,a=!1,u=!1;return function(){const e=this;if(r=arguments,o)a=!0,u=!0;else{"end"!=n.opportunity&&t.apply(e,r),o=!0;var i=setInterval((()=>{a?n.keep||t.apply(e,r):("begin"!=n.opportunity&&(u||"end"==n.opportunity)&&t.apply(e,r),o=!1,u=!1,clearInterval(i)),a=!1}),n.time)}}}};return n}));
|
package/src/animation/index.d.ts
DELETED
package/src/animation/index.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//当前正在运动的动画的tick函数堆栈
|
|
2
|
-
var $timers = [];
|
|
3
|
-
//唯一定时器的定时间隔
|
|
4
|
-
var $interval = 13;
|
|
5
|
-
//定时器ID
|
|
6
|
-
var $timerId;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 动画轮播
|
|
10
|
-
* @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
|
|
11
|
-
* @param {number} duration 动画时长,可选
|
|
12
|
-
* @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
|
|
13
|
-
*
|
|
14
|
-
* @returns {function} 返回一个函数,调用该函数,可以提前结束动画
|
|
15
|
-
*/
|
|
16
|
-
export function animation(doback, duration, callback) {
|
|
17
|
-
if (arguments.length < 2) duration = 400;
|
|
18
|
-
if (arguments.length < 3) callback = function () { };
|
|
19
|
-
|
|
20
|
-
var clock = {
|
|
21
|
-
//把tick函数推入堆栈
|
|
22
|
-
"timer": function (tick, duration, callback) {
|
|
23
|
-
if (!tick) {
|
|
24
|
-
throw new Error('Tick is required!');
|
|
25
|
-
}
|
|
26
|
-
var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
|
|
27
|
-
$timers.push({
|
|
28
|
-
"id": id,
|
|
29
|
-
"createTime": new Date(),
|
|
30
|
-
"tick": tick,
|
|
31
|
-
"duration": duration,
|
|
32
|
-
"callback": callback
|
|
33
|
-
});
|
|
34
|
-
clock.start();
|
|
35
|
-
return id;
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
//开启唯一的定时器timerId
|
|
39
|
-
"start": function () {
|
|
40
|
-
if (!$timerId) {
|
|
41
|
-
$timerId = setInterval(clock.tick, $interval);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
//被定时器调用,遍历timers堆栈
|
|
46
|
-
"tick": function () {
|
|
47
|
-
var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
|
|
48
|
-
|
|
49
|
-
$timers = [];
|
|
50
|
-
$timers.length = 0;
|
|
51
|
-
|
|
52
|
-
for (flag = 0; flag < timers.length; flag++) {
|
|
53
|
-
//初始化数据
|
|
54
|
-
timer = timers[flag];
|
|
55
|
-
createTime = timer.createTime;
|
|
56
|
-
tick = timer.tick;
|
|
57
|
-
duration = timer.duration;
|
|
58
|
-
callback = timer.callback;
|
|
59
|
-
|
|
60
|
-
//执行
|
|
61
|
-
passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
|
|
62
|
-
passTime = passTime > 1 ? 1 : passTime;
|
|
63
|
-
tick(passTime);
|
|
64
|
-
if (passTime < 1 && timer.id) {
|
|
65
|
-
//动画没有结束再添加
|
|
66
|
-
$timers.push(timer);
|
|
67
|
-
} else {
|
|
68
|
-
callback(passTime);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if ($timers.length <= 0) {
|
|
72
|
-
clock.stop();
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
//停止定时器,重置timerId=null
|
|
77
|
-
"stop": function () {
|
|
78
|
-
if ($timerId) {
|
|
79
|
-
clearInterval($timerId);
|
|
80
|
-
$timerId = null;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
var id = clock.timer(function (deep) {
|
|
86
|
-
//其中deep为0-1,表示改变的程度
|
|
87
|
-
doback(deep);
|
|
88
|
-
}, duration, callback);
|
|
89
|
-
|
|
90
|
-
// 返回一个函数
|
|
91
|
-
// 用于在动画结束前结束动画
|
|
92
|
-
return function () {
|
|
93
|
-
var i;
|
|
94
|
-
for (i in $timers) {
|
|
95
|
-
if ($timers[i].id == id) {
|
|
96
|
-
$timers[i].id = void 0;
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
};
|
package/src/throttle/index.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
export let throttle: throttleType
|
package/src/throttle/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export function throttle(callback, _option) {
|
|
2
|
-
|
|
3
|
-
// 缺省值
|
|
4
|
-
var option = {
|
|
5
|
-
time: 200,
|
|
6
|
-
keep: false,
|
|
7
|
-
opportunity: "end"
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// 校对
|
|
11
|
-
if (_option) {
|
|
12
|
-
for (var key in _option) {
|
|
13
|
-
option[key] = _option[key];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
var hadInterval = false, hadClick = false, oneClick = false, arg;
|
|
18
|
-
return function () {
|
|
19
|
-
const _this = this;
|
|
20
|
-
arg = arguments;
|
|
21
|
-
|
|
22
|
-
// 如果前置任务都完成了
|
|
23
|
-
if (!hadInterval) {
|
|
24
|
-
if (option.opportunity != 'end') {
|
|
25
|
-
callback.apply(_this, arg);
|
|
26
|
-
}
|
|
27
|
-
hadInterval = true;
|
|
28
|
-
|
|
29
|
-
var interval = setInterval(() => {
|
|
30
|
-
if (hadClick) {
|
|
31
|
-
if (!option.keep) {
|
|
32
|
-
callback.apply(_this, arg);
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
if (option.opportunity != 'begin') {
|
|
36
|
-
if (oneClick || option.opportunity == 'end') callback.apply(_this, arg);
|
|
37
|
-
}
|
|
38
|
-
hadInterval = false;
|
|
39
|
-
oneClick = false;
|
|
40
|
-
clearInterval(interval);
|
|
41
|
-
}
|
|
42
|
-
hadClick = false;
|
|
43
|
-
}, option.time);
|
|
44
|
-
} else {
|
|
45
|
-
hadClick = true;
|
|
46
|
-
oneClick = true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
};
|