oipage 0.1.0-alpha.1 → 0.1.0-alpha.2

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.
Files changed (45) hide show
  1. package/CHANGELOG +38 -0
  2. package/README.md +103 -4
  3. package/bin/options.js +45 -11
  4. package/bin/run +165 -20
  5. package/browserjs/getStyle/index.d.ts +11 -0
  6. package/browserjs/getStyle/index.js +13 -0
  7. package/browserjs/index.d.ts +10 -0
  8. package/browserjs/index.js +7 -0
  9. package/browserjs/onReady/index.d.ts +8 -0
  10. package/browserjs/onReady/index.js +8 -0
  11. package/corejs/animation/index.d.ts +12 -0
  12. package/corejs/animation/index.js +102 -0
  13. package/corejs/index.d.ts +10 -0
  14. package/corejs/index.js +7 -0
  15. package/corejs/throttle/index.d.ts +31 -0
  16. package/corejs/throttle/index.js +50 -0
  17. package/nodejs/core/file.js +128 -0
  18. package/nodejs/core/image.js +5 -0
  19. package/nodejs/core/log.js +82 -0
  20. package/nodejs/core/network.js +40 -0
  21. package/nodejs/core/options.js +49 -0
  22. package/nodejs/core/remote.js +60 -0
  23. package/nodejs/core/responseFileList.js +28 -0
  24. package/nodejs/core/server.js +163 -0
  25. package/nodejs/data/404.js +52 -0
  26. package/nodejs/data/images/file.js +1 -0
  27. package/nodejs/data/images/folder.js +1 -0
  28. package/nodejs/data/mime.types.js +112 -0
  29. package/nodejs/index.js +48 -0
  30. package/nodejs/loader/simpleScss.js +248 -0
  31. package/nodejs/loader/xhtml.js +521 -0
  32. package/package.json +16 -20
  33. package/stylecss/index.css +3 -0
  34. package/stylecss/normalize.css +94 -0
  35. package/stylecss/rasterize.css +318 -0
  36. package/stylecss/skeleton.css +16 -0
  37. package/types/get-options.d.ts +6 -0
  38. package/types/index.d.ts +187 -0
  39. package/public/index.html +0 -14
  40. package/script/command/build.js +0 -22
  41. package/script/command/dev.js +0 -38
  42. package/script/config/alignment.js +0 -15
  43. package/script/config/webpack.js +0 -60
  44. package/src/platforms/h5/index.js +0 -0
  45. package/src/runtime/index.js +0 -0
package/CHANGELOG CHANGED
@@ -0,0 +1,38 @@
1
+ v0.1.0:
2
+ date:
3
+ changes:
4
+ - 初始化版本
5
+ 1、命令
6
+ * --help, -h 获得帮助
7
+ * --server, -s 启动服务器
8
+ * --version, -v 查看版本
9
+ * --config, -c 启动配置文件
10
+ * --delete 删除文件或文件夹
11
+ * --copy 复制文件或文件夹
12
+ * --pick 提取文件夹文件到指定位置
13
+ * --move 移动文件或文件夹
14
+ * --network 查看网络信息
15
+ * --get 发送get请求
16
+ * --post 发送post请求
17
+ * --cat 查看文本内容
18
+ * --run 多进程运行任务
19
+ 2、corejs
20
+ * animation 动画
21
+ * throttle 节流函数
22
+ 3、browserjs
23
+ * getStyle 获取节点样式
24
+ * onReady 解析完执行
25
+ 4、nodejs
26
+ * server 服务器
27
+ * options 命令行参数解析
28
+ * file 文件相关操作
29
+ * console 控制台打印
30
+ * ajax 网络请求
31
+ * network 网络信息等
32
+ * data 资源数据
33
+ * image 图片相关操作
34
+ * loader 文件解析
35
+ 5、stylecss
36
+ * 统一浏览器样式 normalize.css
37
+ * 十二栅格化 rasterize.css
38
+ * 架屏动画 skeleton.css
package/README.md CHANGED
@@ -1,20 +1,119 @@
1
1
  # [OIPage](https://github.com/oi-contrib/OIPage)
2
- 📰跨端前端框架,支持H5+各种小程序等,并支持扩展前端开发框架(比如使用Vue或React语法开发)
2
+ OI页面快速开发辅助库
3
3
 
4
4
  <p>
5
5
  <a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=oipage&interval=7">
6
6
  <img src="https://img.shields.io/npm/dm/oipage.svg" alt="downloads">
7
7
  </a>
8
8
  <a href="https://www.npmjs.com/package/oipage">
9
- <img src="https://img.shields.io/npm/v/oipage.svg" alt="Version">
9
+ <img src="https://img.shields.io/npm/v/oipage.svg" alt="npm">
10
10
  </a>
11
- <a href="https://github.com/zxl20070701/OIPage" target='_blank'>
12
- <img alt="GitHub repo stars" src="https://img.shields.io/github/stars/zxl20070701/OIPage?style=social">
11
+ <a href="https://github.com/oi-contrib/OIPage" target='_blank'>
12
+ <img alt="GitHub repo stars" src="https://img.shields.io/github/stars/oi-contrib/OIPage?style=social">
13
13
  </a>
14
14
  </p>
15
15
 
16
16
  <img src="https://nodei.co/npm/oipage.png?downloads=true&amp;downloadRank=true&amp;stars=true" alt="NPM">
17
17
 
18
+ ## 使用方式
19
+
20
+ 你可以作为一个命令行使用,那么你需要全局安装:
21
+
22
+ ```shell
23
+ npm install -g oipage
24
+ ```
25
+
26
+ 也可以作为项目开发中的一个功能加强,在 package.json 中配置命令或nodejs文件中引入需要的模块使用,那么就在项目中执行安装命令:
27
+
28
+ ```shell
29
+ npm install oipage --save
30
+ ```
31
+
32
+ 全局安装后,就可以直接作为命令行使用了。你可以打印帮助查看:
33
+
34
+ ```shell
35
+ oipage-cli -h
36
+ ```
37
+
38
+ 比如会出现下列内容:
39
+
40
+ ```
41
+ Usage: oipage-cli <command>
42
+
43
+ where <command> is one of:
44
+ --help, -h, --server, -s, --version, -v, --config, -c, --delete, --copy, --pick, --move, --network, --get, --post, --cat, --run
45
+
46
+ oipage-cli --help|-h <term> search for help on <term>
47
+ oipage-cli --help|-h involved overview
48
+ ```
49
+
50
+ 比如--server或-s命令如何查看具体使用说明?只需要:
51
+
52
+ ```shell
53
+ oipage-cli -h s
54
+ ```
55
+
56
+ 然后看见打印提示:
57
+
58
+ ```
59
+ oipage-cli --server|-s [port|20000] [2]render source server.
60
+ ```
61
+
62
+ 根据提示我们知道,这是一个快速启动一个本地资源服务器的命令,使用的时候可以设置服务器端口号,端口号缺省是20000。
63
+
64
+ 比如我们启动端口为8080的服务器:
65
+
66
+ ```shell
67
+ oipage-cli -s 8080
68
+ ```
69
+
70
+ 对于更复杂的业务,我们推荐使用配置文件的方式。比如我们准备了配置文件 oipage.config.js ,那么就可以:
71
+
72
+ ```shell
73
+ devby -c ./oipage.config.js
74
+ ```
75
+
76
+ 配置文件的内容如下:
77
+
78
+ ```js
79
+ module.exports = {
80
+ devServer: {
81
+ // 可配置参数和“服务器”一致
82
+ }
83
+ };
84
+ ```
85
+
86
+ 如果你需要在项目中更灵活的使用,我们也提供了一些有用的API,具体如下:
87
+
88
+ ### 核心包
89
+
90
+ - [animation 动画](./docs/corejs/animation.md)
91
+ - [throttle 节流函数](./docs/corejs/throttle.md)
92
+
93
+ ### Nodejs
94
+
95
+ - [服务器](./docs/nodejs/server.md)
96
+ - [命令行参数解析](./docs/nodejs/options.md)
97
+ - [文件相关操作](./docs/nodejs/file.md)
98
+ - [控制台打印](./docs/nodejs/console.md)
99
+ - [网络请求(ajax)](./docs/nodejs/ajax.md)
100
+ - [网络信息等](./docs/nodejs/network.md)
101
+ - [资源数据](./docs/nodejs/data.md)
102
+ - [图片相关操作](./docs/nodejs/image.md)
103
+ - [文件解析Loader](./docs/nodejs/loader.md)
104
+
105
+ ### 浏览器
106
+
107
+ - [getStyle 获取节点样式](./docs/browserjs/getStyle.md)
108
+ - [onReady 解析完执行](./docs/browserjs/onReady.md)
109
+
110
+ ### 样式文件
111
+
112
+ > 统一浏览器样式 `normalize.css` 直接: `import 'oipage/stylecss/normalize.css'` 即可!
113
+
114
+ - [rasterize 十二栅格化](./docs/stylecss/rasterize.md)
115
+ - [skeleton 骨架屏动画](./docs/stylecss/skeleton.md)
116
+
18
117
  ## 版权
19
118
 
20
119
  MIT License
package/bin/options.js CHANGED
@@ -12,17 +12,51 @@ module.exports = {
12
12
  info: '[1]Display this help text.',
13
13
  demo: 'oipage-cli --help|-h <term>'
14
14
  },
15
- root: {
16
- info: '[2]Set project root directory.',
17
- demo: 'oipage-cli --root ./'
15
+ server: {
16
+ short: 's',
17
+ info: '[2]Render source server.',
18
+ demo: 'oipage-cli --server|-s [port|20000] [basePath|./]'
18
19
  },
19
- dev: {
20
- info: '[3]Development mode running project.',
21
- demo: 'oipage-cli --dev h5|mp-weixin'
20
+ config: {
21
+ short: 'c',
22
+ info: '[3]Specify a configuration file.',
23
+ demo: 'oipage-cli --config|-c ./OIPage.config.js'
22
24
  },
23
- build: {
24
- info: '[4]Package the current project.',
25
- demo: 'oipage-cli --build h5|mp-weixin'
25
+ delete: {
26
+ info: '[4]Delete file or folder.',
27
+ demo: 'oipage-cli --delete targetPath'
28
+ },
29
+ copy: {
30
+ info: '[5]Copy file or folder.',
31
+ demo: 'oipage-cli --copy sourcePath targetPath'
32
+ },
33
+ pick: {
34
+ info: '[6]Copy all files in the folder to the specified location.',
35
+ demo: 'oipage-cli --pick sourcePath targetPath'
36
+ },
37
+ move: {
38
+ info: '[7]Move file or folder.',
39
+ demo: 'oipage-cli --move sourcePath targetPath'
40
+ },
41
+ network: {
42
+ info: '[8]Display network information.',
43
+ demo: 'oipage-cli --network'
44
+ },
45
+ get: {
46
+ info: '[9]HTTP GET.',
47
+ demo: 'oipage-cli --get url'
48
+ },
49
+ post: {
50
+ info: '[10]HTTP POST.',
51
+ demo: 'oipage-cli --post url'
52
+ },
53
+ cat: {
54
+ info: '[11]Show file.',
55
+ demo: 'oipage-cli --cat path'
56
+ },
57
+ run: {
58
+ info: '[12]Run multiple commands.',
59
+ demo: 'oipage-cli --run \"commands1\" \"commands2\" \"commands3\"'
26
60
  }
27
61
  },
28
62
 
@@ -31,10 +65,10 @@ module.exports = {
31
65
  Usage: oipage-cli <command>
32
66
 
33
67
  Where <command> is one of:
34
- --help, -h, --version, -v, --root, --dev, --build
68
+ --help, -h, --server, -s, --version, -v, --config, -c, --delete, --copy, --pick, --move, --network, --get, --post, --cat
35
69
 
36
70
  oipage-cli --help|-h <term> search for help on <term>
37
71
  oipage-cli --help|-h involved overview
38
- `
72
+ `
39
73
 
40
74
  };
package/bin/run CHANGED
@@ -2,14 +2,19 @@
2
2
 
3
3
  'use strict';
4
4
 
5
- process.title = 'oipage-cli';
5
+ process.title = 'OIPage';
6
6
 
7
- const devby = require("devby");
7
+ const server = require('../nodejs/core/server');
8
8
  const { options, help } = require('./options');
9
- const pkg = require("../package.json");
10
- const runDev = require("../script/command/dev");
11
- const runBuild = require("../script/command/build");
12
- const alignment = require("../script/config/alignment");
9
+ const path = require('path');
10
+ const { log, error } = require('../nodejs/core/log');
11
+ const { deleteSync, copySync, moveSync, listFileSync, fullPathSync } = require("../nodejs/core/file");
12
+ const network = require("../nodejs/core/network");
13
+ const { get, post } = require("../nodejs/core/remote");
14
+ const fs = require("fs");
15
+ const { exec } = require('child_process');
16
+
17
+ const jsonfile = require("../package.json");
13
18
 
14
19
  // 组装好缩写和全写的映射
15
20
  let shortHands = {};
@@ -18,16 +23,17 @@ for (let key in options) {
18
23
  }
19
24
 
20
25
  // 命令行传递的参数
21
- const parsed = devby.options(shortHands, process.argv);
26
+ const parsed = require("../nodejs/core/options")(shortHands, process.argv);
22
27
 
23
28
  (() => {
24
29
  // 打印版本
25
30
  if (Array.isArray(parsed.version)) {
26
- devby.log("\nOIPage@v" + pkg.version + "\n");
31
+ log("\nOIPage@v" + jsonfile.version + "\n");
27
32
  }
28
33
 
29
34
  // 判断是否需要帮助
30
35
  else if (Array.isArray(parsed.help)) {
36
+
31
37
  // 打印具体的配置提示
32
38
  if (parsed.help.length > 0) {
33
39
  let help0 = parsed.help[0];
@@ -43,9 +49,9 @@ const parsed = devby.options(shortHands, process.argv);
43
49
  // 根据需要帮助的命令获取对应的信息
44
50
  const help0Option = options[help0];
45
51
  if (help0Option) {
46
- devby.log(`
47
- ` + help0Option.demo + ` ` + help0Option.info + `
48
- `);
52
+ log(`
53
+ ` + help0Option.demo + ` ` + help0Option.info + `
54
+ `);
49
55
 
50
56
  return;
51
57
  }
@@ -53,21 +59,160 @@ const parsed = devby.options(shortHands, process.argv);
53
59
  }
54
60
  }
55
61
 
56
- devby.log(help);
62
+ log(help);
57
63
  }
58
64
 
59
- // 开发
60
- else if (Array.isArray(parsed.dev)) {
61
- runDev(alignment.command(parsed));
65
+ // 基于配置文件运行
66
+ else if (Array.isArray(parsed.config)) {
67
+ if (parsed.config.length < 1) parsed.config[0] = './oipage.config.js';
68
+
69
+ // 读取配置
70
+ let configFile = require(path.join(process.cwd(), parsed.config[0]));
71
+
72
+ // 如果配置了服务器
73
+ if ("devServer" in configFile) {
74
+ server(configFile.devServer);
75
+ }
62
76
  }
63
77
 
64
- // 打包
65
- else if (Array.isArray(parsed.build)) {
66
- runBuild(alignment.command(parsed));
78
+ // 删除
79
+ else if (Array.isArray(parsed.delete)) {
80
+
81
+ // 获取绝对路径
82
+ let targetPath = fullPathSync(parsed.delete[0]);
83
+
84
+ deleteSync(targetPath);
85
+ log(`> delete ${targetPath.replace(process.cwd(), '.')}`);
86
+ }
87
+
88
+ // 复制
89
+ else if (Array.isArray(parsed.copy)) {
90
+
91
+ // 获取绝对路径
92
+ let sourcePath = fullPathSync(parsed.copy[0]);
93
+ let targetPath = fullPathSync(parsed.copy[1]);
94
+
95
+ // 如果存在
96
+ copySync(sourcePath, targetPath);
97
+ log(`> copy ${sourcePath.replace(process.cwd(), '.')} ➔ ${targetPath.replace(process.cwd(), '.')}`);
67
98
  }
68
99
 
69
- // 默认
100
+ // 复制文件(一级展开)
101
+ else if (Array.isArray(parsed.pick)) {
102
+
103
+ // 如果目标文件夹不存在,创建
104
+ if (!fs.existsSync(parsed.pick[1])) {
105
+ fs.mkdirSync(parsed.pick[1], { recursive: true });
106
+ }
107
+
108
+ listFileSync(parsed.pick[0], fileInfo => {
109
+
110
+ // 获取路径
111
+ let sourcePath = fullPathSync(fileInfo.path);
112
+ let targetPath = fullPathSync(path.join(parsed.pick[1], fileInfo.name));
113
+
114
+ let index = 1;
115
+ while (fs.existsSync(targetPath)) {
116
+ targetPath = fullPathSync(path.join(parsed.pick[1], "【" + index + "】" + fileInfo.name));
117
+ index += 1;
118
+ }
119
+
120
+ log(`> copy ${sourcePath.replace(process.cwd(), '.')} ➔ ${targetPath.replace(process.cwd(), '.')}`);
121
+ copySync(sourcePath, targetPath);
122
+ });
123
+ }
124
+
125
+ // 移动
126
+ else if (Array.isArray(parsed.move)) {
127
+
128
+ // 获取绝对路径
129
+ let sourcePath = fullPathSync(parsed.move[0]);
130
+ let targetPath = fullPathSync(parsed.move[1]);
131
+
132
+ // 如果存在
133
+ moveSync(sourcePath, targetPath);
134
+ log(`> move ${sourcePath.replace(process.cwd(), '.')} ➔ ${targetPath.replace(process.cwd(), '.')}`);
135
+ }
136
+
137
+ // 网络信息
138
+ else if (Array.isArray(parsed.network)) {
139
+ log(JSON.stringify(network(), null, 4));
140
+ }
141
+
142
+ // GET请求
143
+ else if (Array.isArray(parsed.get)) {
144
+ get(parsed.get[0]).then(data => {
145
+ log(data);
146
+ }).catch(e => {
147
+ error(e);
148
+ });
149
+ }
150
+
151
+ // PSOT请求
152
+ else if (Array.isArray(parsed.post)) {
153
+ post(parsed.post[0]).then(data => {
154
+ log(data);
155
+ }).catch(e => {
156
+ error(e);
157
+ });
158
+ }
159
+
160
+ // 查看文件
161
+ else if (Array.isArray(parsed.cat)) {
162
+ try {
163
+ let filepath = fullPathSync(parsed.cat[0])
164
+
165
+ log(fs.readFileSync(filepath, {
166
+ encoding: "utf8"
167
+ }));
168
+ } catch (e) {
169
+ error(e);
170
+ }
171
+ }
172
+
173
+ // 运行多命令
174
+ else if (Array.isArray(parsed.run)) {
175
+ for (let index = 0; index < parsed.run.length; index++) {
176
+ const child = exec(parsed.run[index]);
177
+
178
+ // 监听子线程的stdout
179
+ child.stdout.on('data', (data) => {
180
+ console.log(`[${index + 1}] log:${data}`);
181
+ });
182
+
183
+ // 监听子线程的stderr
184
+ child.stderr.on('data', (data) => {
185
+ console.error(`[${index + 1}] error:${data}`);
186
+ });
187
+
188
+ // 子线程结束处理
189
+ child.on('close', (code) => {
190
+ console.log(`[${index + 1}] 子线程结束,退出码 ${code}`);
191
+ });
192
+
193
+ // 子线程出错处理
194
+ child.on('error', (error) => {
195
+ console.error(`[${index + 1}] 子线程错误: ${error.message}`);
196
+ });
197
+ }
198
+ }
199
+
200
+ // 否则就是启动服务器
70
201
  else {
71
- devby.log(help);
202
+
203
+ let port, basePath;
204
+
205
+ if (Array.isArray(parsed.server)) {
206
+ port = parsed.server[0];
207
+ basePath = parsed.server[1];
208
+ } else {
209
+ port = parsed.__terminal__[0];
210
+ basePath = parsed.__terminal__[1];
211
+ }
212
+
213
+ server({
214
+ port,
215
+ basePath
216
+ });
72
217
  }
73
218
  })();
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 获取节点样式
3
+ */
4
+ export interface getStyleType {
5
+ (el: HTMLElement, name: string): string
6
+ (el: HTMLElement): {
7
+ [key: string]: string
8
+ }
9
+ }
10
+
11
+ export let getStyle: getStyleType
@@ -0,0 +1,13 @@
1
+ export function getStyle(el, name) {
2
+
3
+ // 获取结点的全部样式
4
+ var allStyle = document.defaultView && document.defaultView.getComputedStyle ?
5
+ document.defaultView.getComputedStyle(el, null) :
6
+ el.currentStyle;
7
+
8
+ // 如果没有指定属性名称,返回全部样式
9
+ return typeof name === 'string' ?
10
+ allStyle.getPropertyValue(name) :
11
+ allStyle;
12
+
13
+ };
@@ -0,0 +1,10 @@
1
+ import { getStyleType } from "./getStyle"
2
+ import { onReadyType } from "./onReady"
3
+
4
+ export default class Corejs {
5
+ static getStyle: getStyleType
6
+ static onReady: onReadyType
7
+ }
8
+
9
+ export let getStyle: getStyleType
10
+ export let onReady: onReadyType
@@ -0,0 +1,7 @@
1
+ import { getStyle } from "./getStyle/index.js";
2
+ import { onReady } from "./onReady/index.js";
3
+
4
+ export default {
5
+ getStyle: getStyle,
6
+ onReady: onReady
7
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 等待DOM加载完毕执行
3
+ */
4
+ export interface onReadyType {
5
+ (callback: Function): void
6
+ }
7
+
8
+ export let onReady: onReadyType
@@ -0,0 +1,8 @@
1
+ export function onReady(callback) {
2
+ var readyState = document.readyState;
3
+ if (readyState === 'interactive' || readyState === 'complete') {
4
+ callback();
5
+ } else {
6
+ window.addEventListener("DOMContentLoaded", callback);
7
+ }
8
+ };
@@ -0,0 +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
+
12
+ export let animation: animationType
@@ -0,0 +1,102 @@
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
+ };
@@ -0,0 +1,10 @@
1
+ import { animationType } from "./animation"
2
+ import { throttleType } from "./throttle"
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
@@ -0,0 +1,7 @@
1
+ import { animation } from "./animation/index.js";
2
+ import { throttle } from "./throttle/index.js";
3
+
4
+ export default {
5
+ animation: animation,
6
+ throttle: throttle
7
+ };