oipage 1.7.0 → 1.8.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/.github/FUNDING.yml +11 -11
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +9 -1
- package/LICENSE +20 -20
- package/README.md +1 -9
- package/bin/WebSocket/decodeWsFrame.js +43 -43
- package/bin/WebSocket/encodeWsFrame.js +28 -28
- package/bin/WebSocket/headersToJSON.js +26 -26
- package/bin/WebSocket/index.js +80 -80
- package/bin/data/mineTypes.json +104 -104
- package/bin/disk.js +42 -42
- package/bin/help.js +3 -0
- package/bin/intercept.js +15 -15
- package/bin/network.js +21 -21
- package/bin/run +5 -3
- package/bin/serve.d.ts +7 -0
- package/bin/serve.js +9 -1
- package/bin/template/404.html +186 -186
- package/bin/tools/deleteEmptyFolder.js +23 -23
- package/bin/tools/format.js +75 -75
- package/bin/tools/network.js +42 -42
- package/bin/tools/openBrowser.js +26 -0
- package/bin/tools/resolve404.js +83 -83
- package/bin/tools/resolveImport.js +88 -88
- package/bin/website-htmls/components/ui-select-file/index.html +7 -7
- package/bin/website-htmls/components/ui-select-file/index.js +37 -37
- package/bin/website-htmls/components/ui-select-file/index.scss +44 -44
- package/bin/website-htmls/dialogs/imageSize/index.html +54 -54
- package/bin/website-htmls/dialogs/imageSize/index.js +53 -53
- package/bin/website-htmls/dialogs/imageSize/index.scss +138 -138
- package/bin/website-htmls/dialogs/index.js +52 -52
- package/bin/website-htmls/images/addFile.svg +1 -1
- package/bin/website-htmls/images/img-to-pdf.svg +1 -1
- package/bin/website-htmls/index.html +17 -17
- package/bin/website-htmls/main.js +13 -13
- package/bin/website-htmls/pages/App/index.html +6 -6
- package/bin/website-htmls/pages/App/index.js +22 -22
- package/bin/website-htmls/pages/App/index.scss +43 -43
- package/bin/website-htmls/pages/appStore/index.html +5 -24
- package/bin/website-htmls/pages/appStore/index.js +19 -19
- package/bin/website-htmls/pages/appStore/index.scss +6 -4
- package/bin/website-htmls/pages/chart/index.html +8 -8
- package/bin/website-htmls/pages/chart/index.js +72 -72
- package/bin/website-htmls/pages/chart/index.scss +73 -72
- package/bin/website-htmls/pages/home/index.html +22 -0
- package/bin/website-htmls/pages/home/index.js +20 -0
- package/bin/website-htmls/pages/home/index.scss +29 -0
- package/bin/website-htmls/pages/image-editor/index.html +27 -27
- package/bin/website-htmls/pages/image-editor/index.js +106 -106
- package/bin/website-htmls/pages/image-editor/index.scss +47 -45
- package/bin/website-htmls/pages/img-to-pdf/index.html +3 -3
- package/bin/website-htmls/pages/img-to-pdf/index.js +44 -44
- package/bin/website-htmls/pages/img-to-pdf/index.scss +4 -4
- package/bin/website-htmls/router.config.js +26 -19
- package/bin/website-htmls/styles/normalize.css +94 -94
- package/bin/website-plugins/intercept/chart.js +33 -33
- package/bin/website-plugins/intercept/getPackage.js +17 -17
- package/bin/website-plugins/intercept/head.js +8 -8
- package/bin/website-plugins/intercept/index.js +8 -8
- package/bin/website-plugins/intercept/oipage-vislite-intercept.js +30 -30
- package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +36 -36
- package/bin/website-plugins/loader/index.js +11 -11
- package/bin/website-plugins/loader/oipage-html-loader.js +7 -7
- package/bin/website-plugins/loader/oipage-scss-loader.js +149 -149
- package/nodejs/animation/index.d.ts +19 -19
- package/nodejs/animation/index.js +120 -112
- package/nodejs/cmdlog/index.d.ts +20 -20
- package/nodejs/cmdlog/index.js +75 -75
- package/nodejs/disk/index.d.ts +47 -47
- package/nodejs/disk/index.js +165 -165
- package/nodejs/format/index.d.ts +29 -29
- package/nodejs/format/index.js +107 -107
- 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 +1 -1
- package/web/XMLHttpRequest/index.d.ts +17 -17
- package/web/XMLHttpRequest/index.js +60 -60
- package/web/animation/index.d.ts +19 -19
- package/web/animation/index.js +120 -112
- package/web/format/index.d.ts +29 -29
- package/web/format/index.js +107 -107
- 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/snipping/chart.png +0 -0
- package/snipping/image-editor.png +0 -0
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
// 参考:https://github.com/zxl20070701/zxl20070701.github.io/blob/master/bin/loader/scss.js
|
|
2
|
-
let toSelector = function (preSelectorArray, deep) {
|
|
3
|
-
let selectors = preSelectorArray[0], i, j, k;
|
|
4
|
-
for (i = 1; i < deep; i++) {
|
|
5
|
-
let temp = [];
|
|
6
|
-
for (j = 0; j < selectors.length; j++) {
|
|
7
|
-
for (k = 0; k < preSelectorArray[i].length; k++) {
|
|
8
|
-
temp.push(selectors[j] + preSelectorArray[i][k]);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
selectors = temp;
|
|
12
|
-
}
|
|
13
|
-
return "\n" + (selectors.join(',')) + "{\n";
|
|
14
|
-
};
|
|
15
|
-
let analyseBlock = function (source) {
|
|
16
|
-
let i = -1, currentChar = null;
|
|
17
|
-
let next = function () {
|
|
18
|
-
currentChar = i++ < source.length - 1 ? source[i] : null;
|
|
19
|
-
return currentChar;
|
|
20
|
-
}
|
|
21
|
-
let nextNValue = function (n) {
|
|
22
|
-
return source.substring(i, n + i > source.length ? source.length : n + i);
|
|
23
|
-
}
|
|
24
|
-
let blocks = [];
|
|
25
|
-
let currentBlock = "";
|
|
26
|
-
next();
|
|
27
|
-
while (true) {
|
|
28
|
-
while (new RegExp("[\\x20\\t\\r\\n\\f]").test(currentChar)) {
|
|
29
|
-
next();
|
|
30
|
-
}
|
|
31
|
-
if (currentChar == null) break;
|
|
32
|
-
if (nextNValue(2) == '/*') {
|
|
33
|
-
|
|
34
|
-
next();
|
|
35
|
-
next();
|
|
36
|
-
currentBlock = "/*";
|
|
37
|
-
|
|
38
|
-
while (nextNValue(2) != '*/' && currentChar != null) {
|
|
39
|
-
currentBlock += currentChar;
|
|
40
|
-
next();
|
|
41
|
-
}
|
|
42
|
-
if (currentChar == null) {
|
|
43
|
-
throw new Error('The comment is not closed.');
|
|
44
|
-
}
|
|
45
|
-
currentBlock += "*/";
|
|
46
|
-
next();
|
|
47
|
-
next();
|
|
48
|
-
blocks.push({
|
|
49
|
-
value: currentBlock,
|
|
50
|
-
type: "comment-double"
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
else if (nextNValue(2) == '//') {
|
|
54
|
-
currentBlock = '';
|
|
55
|
-
|
|
56
|
-
while (currentChar != '\n' && currentChar != null) {
|
|
57
|
-
currentBlock += currentChar;
|
|
58
|
-
next();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
blocks.push({
|
|
62
|
-
value: currentBlock,
|
|
63
|
-
type: "comment-single"
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
else if (currentChar == '}') {
|
|
68
|
-
|
|
69
|
-
blocks.push({
|
|
70
|
-
value: "}",
|
|
71
|
-
type: "end"
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
next();
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
|
|
79
|
-
currentBlock = '';
|
|
80
|
-
while (currentChar != '{' && currentChar != ';' && currentChar != null) {
|
|
81
|
-
currentBlock += currentChar;
|
|
82
|
-
next();
|
|
83
|
-
}
|
|
84
|
-
if (currentChar == null) {
|
|
85
|
-
throw new Error('Statement or code block missing closure.');
|
|
86
|
-
}
|
|
87
|
-
blocks.push({
|
|
88
|
-
value: currentBlock + currentChar,
|
|
89
|
-
type: {
|
|
90
|
-
'{': "begin",
|
|
91
|
-
';': 'statement'
|
|
92
|
-
}[currentChar]
|
|
93
|
-
});
|
|
94
|
-
next();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return blocks;
|
|
98
|
-
};
|
|
99
|
-
module.exports = function (source) {
|
|
100
|
-
this.setFileType("application/javascript");
|
|
101
|
-
let blocks = analyseBlock(source + "");
|
|
102
|
-
let i, j, cssCode = "", preSelectorArray = [], deep = 0;
|
|
103
|
-
for (i = 0; i < blocks.length; i++) {
|
|
104
|
-
if (blocks[i].type == 'comment-double') {
|
|
105
|
-
cssCode += blocks[i].value;
|
|
106
|
-
}
|
|
107
|
-
else if (blocks[i].type == 'comment-single') {
|
|
108
|
-
cssCode += "\n/* " + blocks[i].value + " */\n";
|
|
109
|
-
}
|
|
110
|
-
else if (blocks[i].type == 'begin') {
|
|
111
|
-
let preSplit = blocks[i].value.split(',');
|
|
112
|
-
let preSelect = [];
|
|
113
|
-
for (j = 0; j < preSplit.length; j++) {
|
|
114
|
-
preSelect[j] = preSplit[j].replace(/\{$/, '').trim();
|
|
115
|
-
if (/^&/.test(preSelect[j])) {
|
|
116
|
-
preSelect[j] = preSelect[j].replace(/^&/, '');
|
|
117
|
-
} else {
|
|
118
|
-
preSelect[j] = " " + preSelect[j];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
preSelectorArray[deep] = preSelect;
|
|
122
|
-
deep += 1;
|
|
123
|
-
}
|
|
124
|
-
else if (blocks[i].type == 'end') {
|
|
125
|
-
deep -= 1;
|
|
126
|
-
}
|
|
127
|
-
else if (blocks[i].type == 'statement') {
|
|
128
|
-
j = 1;
|
|
129
|
-
let preType = blocks[i - j].type;
|
|
130
|
-
while (['comment-double', 'comment-single'].indexOf(preType) > -1) {
|
|
131
|
-
j += 1;
|
|
132
|
-
preType = blocks[i - j].type;
|
|
133
|
-
}
|
|
134
|
-
if (['end', 'begin'].indexOf(preType) > -1) {
|
|
135
|
-
cssCode += toSelector(preSelectorArray, deep);
|
|
136
|
-
}
|
|
137
|
-
cssCode += "\n" + blocks[i].value + "\n";
|
|
138
|
-
j = 1;
|
|
139
|
-
let nextType = blocks[i + j].type;
|
|
140
|
-
while (['comment-double', 'comment-single'].indexOf(nextType) > -1) {
|
|
141
|
-
j += 1;
|
|
142
|
-
nextType = blocks[i + j].type;
|
|
143
|
-
}
|
|
144
|
-
if (['end', 'begin'].indexOf(nextType) > -1) {
|
|
145
|
-
cssCode += "\n}\n";
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return `export default ${JSON.stringify(cssCode)}`;
|
|
1
|
+
// 参考:https://github.com/zxl20070701/zxl20070701.github.io/blob/master/bin/loader/scss.js
|
|
2
|
+
let toSelector = function (preSelectorArray, deep) {
|
|
3
|
+
let selectors = preSelectorArray[0], i, j, k;
|
|
4
|
+
for (i = 1; i < deep; i++) {
|
|
5
|
+
let temp = [];
|
|
6
|
+
for (j = 0; j < selectors.length; j++) {
|
|
7
|
+
for (k = 0; k < preSelectorArray[i].length; k++) {
|
|
8
|
+
temp.push(selectors[j] + preSelectorArray[i][k]);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
selectors = temp;
|
|
12
|
+
}
|
|
13
|
+
return "\n" + (selectors.join(',')) + "{\n";
|
|
14
|
+
};
|
|
15
|
+
let analyseBlock = function (source) {
|
|
16
|
+
let i = -1, currentChar = null;
|
|
17
|
+
let next = function () {
|
|
18
|
+
currentChar = i++ < source.length - 1 ? source[i] : null;
|
|
19
|
+
return currentChar;
|
|
20
|
+
}
|
|
21
|
+
let nextNValue = function (n) {
|
|
22
|
+
return source.substring(i, n + i > source.length ? source.length : n + i);
|
|
23
|
+
}
|
|
24
|
+
let blocks = [];
|
|
25
|
+
let currentBlock = "";
|
|
26
|
+
next();
|
|
27
|
+
while (true) {
|
|
28
|
+
while (new RegExp("[\\x20\\t\\r\\n\\f]").test(currentChar)) {
|
|
29
|
+
next();
|
|
30
|
+
}
|
|
31
|
+
if (currentChar == null) break;
|
|
32
|
+
if (nextNValue(2) == '/*') {
|
|
33
|
+
|
|
34
|
+
next();
|
|
35
|
+
next();
|
|
36
|
+
currentBlock = "/*";
|
|
37
|
+
|
|
38
|
+
while (nextNValue(2) != '*/' && currentChar != null) {
|
|
39
|
+
currentBlock += currentChar;
|
|
40
|
+
next();
|
|
41
|
+
}
|
|
42
|
+
if (currentChar == null) {
|
|
43
|
+
throw new Error('The comment is not closed.');
|
|
44
|
+
}
|
|
45
|
+
currentBlock += "*/";
|
|
46
|
+
next();
|
|
47
|
+
next();
|
|
48
|
+
blocks.push({
|
|
49
|
+
value: currentBlock,
|
|
50
|
+
type: "comment-double"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else if (nextNValue(2) == '//') {
|
|
54
|
+
currentBlock = '';
|
|
55
|
+
|
|
56
|
+
while (currentChar != '\n' && currentChar != null) {
|
|
57
|
+
currentBlock += currentChar;
|
|
58
|
+
next();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
blocks.push({
|
|
62
|
+
value: currentBlock,
|
|
63
|
+
type: "comment-single"
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
else if (currentChar == '}') {
|
|
68
|
+
|
|
69
|
+
blocks.push({
|
|
70
|
+
value: "}",
|
|
71
|
+
type: "end"
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
next();
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
|
|
79
|
+
currentBlock = '';
|
|
80
|
+
while (currentChar != '{' && currentChar != ';' && currentChar != null) {
|
|
81
|
+
currentBlock += currentChar;
|
|
82
|
+
next();
|
|
83
|
+
}
|
|
84
|
+
if (currentChar == null) {
|
|
85
|
+
throw new Error('Statement or code block missing closure.');
|
|
86
|
+
}
|
|
87
|
+
blocks.push({
|
|
88
|
+
value: currentBlock + currentChar,
|
|
89
|
+
type: {
|
|
90
|
+
'{': "begin",
|
|
91
|
+
';': 'statement'
|
|
92
|
+
}[currentChar]
|
|
93
|
+
});
|
|
94
|
+
next();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return blocks;
|
|
98
|
+
};
|
|
99
|
+
module.exports = function (source) {
|
|
100
|
+
this.setFileType("application/javascript");
|
|
101
|
+
let blocks = analyseBlock(source + "");
|
|
102
|
+
let i, j, cssCode = "", preSelectorArray = [], deep = 0;
|
|
103
|
+
for (i = 0; i < blocks.length; i++) {
|
|
104
|
+
if (blocks[i].type == 'comment-double') {
|
|
105
|
+
cssCode += blocks[i].value;
|
|
106
|
+
}
|
|
107
|
+
else if (blocks[i].type == 'comment-single') {
|
|
108
|
+
cssCode += "\n/* " + blocks[i].value + " */\n";
|
|
109
|
+
}
|
|
110
|
+
else if (blocks[i].type == 'begin') {
|
|
111
|
+
let preSplit = blocks[i].value.split(',');
|
|
112
|
+
let preSelect = [];
|
|
113
|
+
for (j = 0; j < preSplit.length; j++) {
|
|
114
|
+
preSelect[j] = preSplit[j].replace(/\{$/, '').trim();
|
|
115
|
+
if (/^&/.test(preSelect[j])) {
|
|
116
|
+
preSelect[j] = preSelect[j].replace(/^&/, '');
|
|
117
|
+
} else {
|
|
118
|
+
preSelect[j] = " " + preSelect[j];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
preSelectorArray[deep] = preSelect;
|
|
122
|
+
deep += 1;
|
|
123
|
+
}
|
|
124
|
+
else if (blocks[i].type == 'end') {
|
|
125
|
+
deep -= 1;
|
|
126
|
+
}
|
|
127
|
+
else if (blocks[i].type == 'statement') {
|
|
128
|
+
j = 1;
|
|
129
|
+
let preType = blocks[i - j].type;
|
|
130
|
+
while (['comment-double', 'comment-single'].indexOf(preType) > -1) {
|
|
131
|
+
j += 1;
|
|
132
|
+
preType = blocks[i - j].type;
|
|
133
|
+
}
|
|
134
|
+
if (['end', 'begin'].indexOf(preType) > -1) {
|
|
135
|
+
cssCode += toSelector(preSelectorArray, deep);
|
|
136
|
+
}
|
|
137
|
+
cssCode += "\n" + blocks[i].value + "\n";
|
|
138
|
+
j = 1;
|
|
139
|
+
let nextType = blocks[i + j].type;
|
|
140
|
+
while (['comment-double', 'comment-single'].indexOf(nextType) > -1) {
|
|
141
|
+
j += 1;
|
|
142
|
+
nextType = blocks[i + j].type;
|
|
143
|
+
}
|
|
144
|
+
if (['end', 'begin'].indexOf(nextType) > -1) {
|
|
145
|
+
cssCode += "\n}\n";
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return `export default ${JSON.stringify(cssCode)}`;
|
|
150
150
|
};
|
|
@@ -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,118 +1,126 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* animation of OIPage v1.
|
|
2
|
+
* animation of OIPage v1.8.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 {object} 返回一个对象,包含一个stop方法,用于在动画结束前结束动画
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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 {object} 返回一个对象,包含一个stop方法,用于在动画结束前结束动画
|
|
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
|
+
try {
|
|
47
|
+
if (globalThis && globalThis.requestAnimationFrame) {
|
|
48
|
+
$timerId = globalThis.requestAnimationFrame(function step() {
|
|
49
|
+
clock.tick();
|
|
50
|
+
if ($timerId) $timerId = globalThis.requestAnimationFrame(step);
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
$timerId = setInterval(clock.tick, $interval);
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
$timerId = setInterval(clock.tick, $interval);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
//被定时器调用,遍历timers堆栈
|
|
62
|
+
"tick": function () {
|
|
63
|
+
var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
|
|
64
|
+
|
|
65
|
+
$timers = [];
|
|
66
|
+
$timers.length = 0;
|
|
67
|
+
|
|
68
|
+
for (flag = 0; flag < timers.length; flag++) {
|
|
69
|
+
//初始化数据
|
|
70
|
+
timer = timers[flag];
|
|
71
|
+
createTime = timer.createTime;
|
|
72
|
+
tick = timer.tick;
|
|
73
|
+
duration = timer.duration;
|
|
74
|
+
callback = timer.callback;
|
|
75
|
+
|
|
76
|
+
//执行
|
|
77
|
+
passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
|
|
78
|
+
passTime = passTime > 1 ? 1 : passTime;
|
|
79
|
+
tick(passTime);
|
|
80
|
+
if (passTime < 1 && timer.id) {
|
|
81
|
+
//动画没有结束再添加
|
|
82
|
+
$timers.push(timer);
|
|
83
|
+
} else {
|
|
84
|
+
callback(passTime);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if ($timers.length <= 0) {
|
|
88
|
+
clock.stop();
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
//停止定时器,重置timerId=null
|
|
93
|
+
"stop": function () {
|
|
94
|
+
if ($timerId) {
|
|
95
|
+
try {
|
|
96
|
+
if (globalThis && globalThis.requestAnimationFrame) globalThis.cancelAnimationFrame($timerId);
|
|
97
|
+
else clearInterval($timerId);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
clearInterval($timerId);
|
|
100
|
+
}
|
|
101
|
+
$timerId = null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var id = clock.timer(function (deep) {
|
|
107
|
+
//其中deep为0-1,表示改变的程度
|
|
108
|
+
doback(deep);
|
|
109
|
+
}, duration, callback);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
// 一个函数
|
|
113
|
+
// 用于在动画结束前结束动画
|
|
114
|
+
stop: function () {
|
|
115
|
+
var i;
|
|
116
|
+
for (i in $timers) {
|
|
117
|
+
if ($timers[i].id == id) {
|
|
118
|
+
$timers[i].id = void 0;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
117
125
|
}
|
|
118
126
|
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
|