oipage 1.3.1-alpha.0 → 1.3.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/.github/FUNDING.yml +11 -11
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +76 -75
- package/LICENSE +20 -20
- 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 +15 -15
- package/bin/run +96 -96
- package/bin/serve.js +128 -128
- package/bin/template/404.html +171 -171
- package/bin/tools/format.js +75 -75
- package/bin/tools/network.js +42 -42
- package/bin/tools/resolve404.js +83 -83
- package/bin/tools/resolveImport.js +88 -88
- package/nodejs/animation/index.d.ts +19 -19
- 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/json/index.d.ts +9 -9
- package/nodejs/json/index.js +206 -206
- package/nodejs/logform/index.d.ts +18 -18
- package/nodejs/logform/index.js +94 -94
- package/nodejs/reader/index.d.ts +32 -32
- package/nodejs/reader/index.js +20 -20
- 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 +19 -19
- package/web/animation/index.js +104 -104
- package/web/json/index.d.ts +9 -9
- package/web/json/index.js +206 -206
- package/web/onReady/index.d.ts +7 -7
- package/web/onReady/index.js +8 -8
- package/web/performChunk/index.d.ts +4 -4
- package/web/performChunk/index.js +19 -19
- package/web/reader/index.d.ts +32 -32
- package/web/reader/index.js +20 -20
- 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/bin/tools/resolve404.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
const { readdirSync, lstatSync, readFileSync, statSync } = require("fs");
|
|
2
|
-
const { join } = require("path");
|
|
3
|
-
const { formatByte, formatTime } = require("./format");
|
|
4
|
-
const mineTypes = require("../data/mineTypes.json");
|
|
5
|
-
|
|
6
|
-
const img_folder = "data:image/png;base64," + readFileSync(join(__dirname, "../images/folder.png")).toString('base64');
|
|
7
|
-
const img_file = "data:image/png;base64," + readFileSync(join(__dirname, "../images/file.png")).toString('base64');
|
|
8
|
-
|
|
9
|
-
const template_404 = readFileSync(join(__dirname, "../template/404.html"), {
|
|
10
|
-
encoding: "utf8"
|
|
11
|
-
})
|
|
12
|
-
.replace("${img_folder}", img_folder)
|
|
13
|
-
.replace("${img_file}", img_file);
|
|
14
|
-
|
|
15
|
-
module.exports = function (filePath, url) {
|
|
16
|
-
|
|
17
|
-
let subItems = [];
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
subItems = readdirSync(filePath);
|
|
21
|
-
console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read Folder: " + url + '\x1b[0m ' + new Date().toLocaleString());
|
|
22
|
-
} catch (e) {
|
|
23
|
-
console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read " + (/\/$/.test(url) ? "Folder" : "File") + ": \x1b[35m" + url + ' 404 Not Found\x1b[0m ' + new Date().toLocaleString());
|
|
24
|
-
try {
|
|
25
|
-
if (!/\/$/.test(url) || url === "/") {
|
|
26
|
-
filePath = join(filePath, "../");
|
|
27
|
-
subItems = readdirSync(filePath);
|
|
28
|
-
}
|
|
29
|
-
} catch (e) { }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let template = "";
|
|
33
|
-
for (let i in subItems) {
|
|
34
|
-
let isDirectory = lstatSync(join(filePath, subItems[i])).isDirectory();
|
|
35
|
-
let statObj = statSync(join(filePath, subItems[i]));
|
|
36
|
-
|
|
37
|
-
// 文件夹
|
|
38
|
-
if (isDirectory) {
|
|
39
|
-
template += `<tr class="folder">
|
|
40
|
-
<th class="name">
|
|
41
|
-
<a href='./${subItems[i]}/'>${subItems[i]}</a>
|
|
42
|
-
</th>
|
|
43
|
-
<th>
|
|
44
|
-
${formatTime(statObj.mtime)}
|
|
45
|
-
</th>
|
|
46
|
-
<th>
|
|
47
|
-
文件夹
|
|
48
|
-
</th>
|
|
49
|
-
<th>
|
|
50
|
-
-
|
|
51
|
-
</th>
|
|
52
|
-
<th>
|
|
53
|
-
<a href='./${subItems[i]}/' class="btn">打开</a>
|
|
54
|
-
</th>
|
|
55
|
-
</tr>`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 文件
|
|
59
|
-
else {
|
|
60
|
-
let dotName = /\./.test(subItems[i]) ? subItems[i].match(/\.([^.]+)$/)[1] : "";
|
|
61
|
-
|
|
62
|
-
template += `<tr class="file">
|
|
63
|
-
<th class="name">
|
|
64
|
-
<a href='./${subItems[i]}'>${subItems[i]}</a>
|
|
65
|
-
</th>
|
|
66
|
-
<th>
|
|
67
|
-
${formatTime(statObj.mtime)}
|
|
68
|
-
</th>
|
|
69
|
-
<th>
|
|
70
|
-
${mineTypes[dotName] || "text/plain"}
|
|
71
|
-
</th>
|
|
72
|
-
<th>
|
|
73
|
-
${formatByte(statObj.size)}
|
|
74
|
-
</th>
|
|
75
|
-
<th>
|
|
76
|
-
<a href='./${subItems[i]}' class="btn">访问</a>
|
|
77
|
-
<a href='./${subItems[i]}?download' class="btn" download='${subItems[i]}'>下载</a>
|
|
78
|
-
</th>
|
|
79
|
-
</tr>`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return template_404.replace("${current}", filePath).replace("${template}", template);
|
|
1
|
+
const { readdirSync, lstatSync, readFileSync, statSync } = require("fs");
|
|
2
|
+
const { join } = require("path");
|
|
3
|
+
const { formatByte, formatTime } = require("./format");
|
|
4
|
+
const mineTypes = require("../data/mineTypes.json");
|
|
5
|
+
|
|
6
|
+
const img_folder = "data:image/png;base64," + readFileSync(join(__dirname, "../images/folder.png")).toString('base64');
|
|
7
|
+
const img_file = "data:image/png;base64," + readFileSync(join(__dirname, "../images/file.png")).toString('base64');
|
|
8
|
+
|
|
9
|
+
const template_404 = readFileSync(join(__dirname, "../template/404.html"), {
|
|
10
|
+
encoding: "utf8"
|
|
11
|
+
})
|
|
12
|
+
.replace("${img_folder}", img_folder)
|
|
13
|
+
.replace("${img_file}", img_file);
|
|
14
|
+
|
|
15
|
+
module.exports = function (filePath, url) {
|
|
16
|
+
|
|
17
|
+
let subItems = [];
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
subItems = readdirSync(filePath);
|
|
21
|
+
console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read Folder: " + url + '\x1b[0m ' + new Date().toLocaleString());
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read " + (/\/$/.test(url) ? "Folder" : "File") + ": \x1b[35m" + url + ' 404 Not Found\x1b[0m ' + new Date().toLocaleString());
|
|
24
|
+
try {
|
|
25
|
+
if (!/\/$/.test(url) || url === "/") {
|
|
26
|
+
filePath = join(filePath, "../");
|
|
27
|
+
subItems = readdirSync(filePath);
|
|
28
|
+
}
|
|
29
|
+
} catch (e) { }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let template = "";
|
|
33
|
+
for (let i in subItems) {
|
|
34
|
+
let isDirectory = lstatSync(join(filePath, subItems[i])).isDirectory();
|
|
35
|
+
let statObj = statSync(join(filePath, subItems[i]));
|
|
36
|
+
|
|
37
|
+
// 文件夹
|
|
38
|
+
if (isDirectory) {
|
|
39
|
+
template += `<tr class="folder">
|
|
40
|
+
<th class="name">
|
|
41
|
+
<a href='./${subItems[i]}/'>${subItems[i]}</a>
|
|
42
|
+
</th>
|
|
43
|
+
<th>
|
|
44
|
+
${formatTime(statObj.mtime)}
|
|
45
|
+
</th>
|
|
46
|
+
<th>
|
|
47
|
+
文件夹
|
|
48
|
+
</th>
|
|
49
|
+
<th>
|
|
50
|
+
-
|
|
51
|
+
</th>
|
|
52
|
+
<th>
|
|
53
|
+
<a href='./${subItems[i]}/' class="btn">打开</a>
|
|
54
|
+
</th>
|
|
55
|
+
</tr>`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 文件
|
|
59
|
+
else {
|
|
60
|
+
let dotName = /\./.test(subItems[i]) ? subItems[i].match(/\.([^.]+)$/)[1] : "";
|
|
61
|
+
|
|
62
|
+
template += `<tr class="file">
|
|
63
|
+
<th class="name">
|
|
64
|
+
<a href='./${subItems[i]}'>${subItems[i]}</a>
|
|
65
|
+
</th>
|
|
66
|
+
<th>
|
|
67
|
+
${formatTime(statObj.mtime)}
|
|
68
|
+
</th>
|
|
69
|
+
<th>
|
|
70
|
+
${mineTypes[dotName] || "text/plain"}
|
|
71
|
+
</th>
|
|
72
|
+
<th>
|
|
73
|
+
${formatByte(statObj.size)}
|
|
74
|
+
</th>
|
|
75
|
+
<th>
|
|
76
|
+
<a href='./${subItems[i]}' class="btn">访问</a>
|
|
77
|
+
<a href='./${subItems[i]}?download' class="btn" download='${subItems[i]}'>下载</a>
|
|
78
|
+
</th>
|
|
79
|
+
</tr>`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return template_404.replace("${current}", filePath).replace("${template}", template);
|
|
84
84
|
};
|
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
const { readFileSync, existsSync, lstatSync } = require("fs");
|
|
2
|
-
const { join } = require("path");
|
|
3
|
-
const { testIntercept } = require("../intercept.js");
|
|
4
|
-
|
|
5
|
-
module.exports = function (basePath, filePath, entry, intercept, isDownload) {
|
|
6
|
-
basePath = join(basePath, "./");
|
|
7
|
-
|
|
8
|
-
let source = readFileSync(filePath);
|
|
9
|
-
let resolveImport = content => content;
|
|
10
|
-
|
|
11
|
-
let __resolveImport = function (content) {
|
|
12
|
-
return content.replace(/import [^'"]* from (['"])([^'"]*)['"]/sg, function (_importCode, _, _importUrl) {
|
|
13
|
-
if (/^[./]/.test(_importUrl)) {
|
|
14
|
-
return _importCode;
|
|
15
|
-
} else {
|
|
16
|
-
return _importCode.replace(_importUrl, _importUrl.replace(/([^/])+/s, function (npmName) {
|
|
17
|
-
|
|
18
|
-
if (testIntercept(npmName, intercept)) {
|
|
19
|
-
return "/@modules/" + npmName;
|
|
20
|
-
} else {
|
|
21
|
-
|
|
22
|
-
let node_modulesRootPath = join(filePath, "../");
|
|
23
|
-
let prePath = "";
|
|
24
|
-
while (true) {
|
|
25
|
-
let npmBundlePath = join(node_modulesRootPath, "./node_modules/", npmName);
|
|
26
|
-
|
|
27
|
-
// 如果存在
|
|
28
|
-
if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
|
|
29
|
-
let npmNameValue = npmName;
|
|
30
|
-
|
|
31
|
-
// 对于类似 import VISLite from "vislite"
|
|
32
|
-
// 需要把包名解析成具体的文件
|
|
33
|
-
if (!/\//.test(_importUrl)) {
|
|
34
|
-
let bundlePackage = require(join(npmBundlePath, "./package.json"));
|
|
35
|
-
npmNameValue = npmName + "/" + bundlePackage.main;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return (prePath ? prePath : "./") + "node_modules/" + npmNameValue;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (node_modulesRootPath === basePath) {
|
|
42
|
-
|
|
43
|
-
// 如果命令行根目录是一个项目
|
|
44
|
-
let packagePath = join(basePath, "./package.json");
|
|
45
|
-
if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
|
|
46
|
-
let bundlePackage = require(packagePath);
|
|
47
|
-
if (!/\//.test(_importUrl)) {
|
|
48
|
-
return "/" + bundlePackage.main;
|
|
49
|
-
} else {
|
|
50
|
-
return "/"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return npmName;
|
|
55
|
-
} else {
|
|
56
|
-
node_modulesRootPath = join(node_modulesRootPath, "../");
|
|
57
|
-
prePath = "../" + prePath;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// 如果是下载
|
|
68
|
-
if (isDownload) {
|
|
69
|
-
// todo
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 如果不是直接访问的
|
|
73
|
-
else if (!entry) {
|
|
74
|
-
source += "";
|
|
75
|
-
resolveImport = (content, notResolve) => notResolve ? content : __resolveImport(content);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 如果是.html或.htm结尾
|
|
79
|
-
else if (/\.html{0,1}$/.test(filePath)) {
|
|
80
|
-
source = (source + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
|
|
81
|
-
return `<script type="module">${__resolveImport(_matchCode)}</script>`;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
source,
|
|
87
|
-
resolveImport
|
|
88
|
-
};
|
|
1
|
+
const { readFileSync, existsSync, lstatSync } = require("fs");
|
|
2
|
+
const { join } = require("path");
|
|
3
|
+
const { testIntercept } = require("../intercept.js");
|
|
4
|
+
|
|
5
|
+
module.exports = function (basePath, filePath, entry, intercept, isDownload) {
|
|
6
|
+
basePath = join(basePath, "./");
|
|
7
|
+
|
|
8
|
+
let source = readFileSync(filePath);
|
|
9
|
+
let resolveImport = content => content;
|
|
10
|
+
|
|
11
|
+
let __resolveImport = function (content) {
|
|
12
|
+
return content.replace(/import [^'"]* from (['"])([^'"]*)['"]/sg, function (_importCode, _, _importUrl) {
|
|
13
|
+
if (/^[./]/.test(_importUrl)) {
|
|
14
|
+
return _importCode;
|
|
15
|
+
} else {
|
|
16
|
+
return _importCode.replace(_importUrl, _importUrl.replace(/([^/])+/s, function (npmName) {
|
|
17
|
+
|
|
18
|
+
if (testIntercept(npmName, intercept)) {
|
|
19
|
+
return "/@modules/" + npmName;
|
|
20
|
+
} else {
|
|
21
|
+
|
|
22
|
+
let node_modulesRootPath = join(filePath, "../");
|
|
23
|
+
let prePath = "";
|
|
24
|
+
while (true) {
|
|
25
|
+
let npmBundlePath = join(node_modulesRootPath, "./node_modules/", npmName);
|
|
26
|
+
|
|
27
|
+
// 如果存在
|
|
28
|
+
if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
|
|
29
|
+
let npmNameValue = npmName;
|
|
30
|
+
|
|
31
|
+
// 对于类似 import VISLite from "vislite"
|
|
32
|
+
// 需要把包名解析成具体的文件
|
|
33
|
+
if (!/\//.test(_importUrl)) {
|
|
34
|
+
let bundlePackage = require(join(npmBundlePath, "./package.json"));
|
|
35
|
+
npmNameValue = npmName + "/" + bundlePackage.main;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (prePath ? prePath : "./") + "node_modules/" + npmNameValue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (node_modulesRootPath === basePath) {
|
|
42
|
+
|
|
43
|
+
// 如果命令行根目录是一个项目
|
|
44
|
+
let packagePath = join(basePath, "./package.json");
|
|
45
|
+
if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
|
|
46
|
+
let bundlePackage = require(packagePath);
|
|
47
|
+
if (!/\//.test(_importUrl)) {
|
|
48
|
+
return "/" + bundlePackage.main;
|
|
49
|
+
} else {
|
|
50
|
+
return "/"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return npmName;
|
|
55
|
+
} else {
|
|
56
|
+
node_modulesRootPath = join(node_modulesRootPath, "../");
|
|
57
|
+
prePath = "../" + prePath;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// 如果是下载
|
|
68
|
+
if (isDownload) {
|
|
69
|
+
// todo
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 如果不是直接访问的
|
|
73
|
+
else if (!entry) {
|
|
74
|
+
source += "";
|
|
75
|
+
resolveImport = (content, notResolve) => notResolve ? content : __resolveImport(content);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 如果是.html或.htm结尾
|
|
79
|
+
else if (/\.html{0,1}$/.test(filePath)) {
|
|
80
|
+
source = (source + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
|
|
81
|
+
return `<script type="module">${__resolveImport(_matchCode)}</script>`;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
source,
|
|
87
|
+
resolveImport
|
|
88
|
+
};
|
|
89
89
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
interface animationResult {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 一个函数,调用该函数,可以提前结束动画
|
|
5
|
-
*/
|
|
6
|
-
stop(): void
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface animationFun {
|
|
10
|
-
(deep: number): void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 轮询动画
|
|
15
|
-
*/
|
|
16
|
-
export interface animationType {
|
|
17
|
-
(doback: animationFun, duration?: number, callback?: animationFun): animationResult
|
|
18
|
-
}
|
|
19
|
-
|
|
1
|
+
interface animationResult {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 一个函数,调用该函数,可以提前结束动画
|
|
5
|
+
*/
|
|
6
|
+
stop(): void
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface animationFun {
|
|
10
|
+
(deep: number): void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 轮询动画
|
|
15
|
+
*/
|
|
16
|
+
export interface animationType {
|
|
17
|
+
(doback: animationFun, duration?: number, callback?: animationFun): animationResult
|
|
18
|
+
}
|
|
19
|
+
|
|
20
20
|
export let animation: animationType
|
|
@@ -1,110 +1,110 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* animation of OIPage v1.3.1
|
|
2
|
+
* animation of OIPage v1.3.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
|
-
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
|
+
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
|
}
|
|
110
110
|
exports.animation = animation;
|
package/nodejs/cmdlog/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 单行打印
|
|
3
|
-
* @param stream 打印的内容
|
|
4
|
-
*/
|
|
5
|
-
export interface linelogType {
|
|
6
|
-
(stream: string): void
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export let linelog: linelogType
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 进度打印
|
|
13
|
-
* @param percentum 进度0-100
|
|
14
|
-
* @param stream 说明文字,可选
|
|
15
|
-
*/
|
|
16
|
-
export interface deeplogType {
|
|
17
|
-
(percentum: number, stream?: string): void
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export let deeplog: deeplogType
|
|
1
|
+
/**
|
|
2
|
+
* 单行打印
|
|
3
|
+
* @param stream 打印的内容
|
|
4
|
+
*/
|
|
5
|
+
export interface linelogType {
|
|
6
|
+
(stream: string): void
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export let linelog: linelogType
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 进度打印
|
|
13
|
+
* @param percentum 进度0-100
|
|
14
|
+
* @param stream 说明文字,可选
|
|
15
|
+
*/
|
|
16
|
+
export interface deeplogType {
|
|
17
|
+
(percentum: number, stream?: string): void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export let deeplog: deeplogType
|