ddan-js 2.0.8 → 2.0.9
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/bin/ddan-js.esm.js +1 -1
- package/bin/ddan-js.js +1 -1
- package/bin/lib/class/event.js +19 -19
- package/bin/lib/class/icon.js +5 -5
- package/bin/lib/class/pipeTask.js +4 -4
- package/bin/lib/class/pipeline.js +20 -20
- package/bin/lib/class/pipeparallel.js +4 -4
- package/bin/lib/class/store.js +1 -1
- package/bin/lib/class/task.js +5 -5
- package/bin/lib/class/tracker.js +16 -16
- package/bin/lib/modules/hook/mutex.js +3 -3
- package/bin/lib/modules/html.js +27 -9
- package/bin/types/class/event.d.ts +3 -3
- package/bin/types/class/icon.d.ts +2 -2
- package/bin/types/class/pipeTask.d.ts +1 -1
- package/bin/types/class/pipeline.d.ts +3 -3
- package/bin/types/class/pipeparallel.d.ts +1 -1
- package/bin/types/class/task.d.ts +1 -1
- package/bin/types/class/tracker.d.ts +2 -2
- package/bin/types/index.d.ts +2 -1
- package/bin/types/modules/html.d.ts +2 -1
- package/package.json +1 -1
package/bin/lib/class/store.js
CHANGED
|
@@ -40,7 +40,7 @@ class DStore extends event_1.default {
|
|
|
40
40
|
result = obj_1.default.copy(val);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
const [, data] = await hook_1.default.exec(() => this.dispatch(key), `${this.
|
|
43
|
+
const [, data] = await hook_1.default.exec(() => this.dispatch(key), `${this.__eventId}_${key}`);
|
|
44
44
|
result = data;
|
|
45
45
|
}
|
|
46
46
|
return result;
|
package/bin/lib/class/task.js
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const is_1 = require("../util/is");
|
|
4
4
|
class DTask {
|
|
5
|
-
|
|
5
|
+
__source;
|
|
6
6
|
constructor(source) {
|
|
7
|
-
this.
|
|
7
|
+
this.__source = source;
|
|
8
8
|
}
|
|
9
9
|
run() {
|
|
10
10
|
let promise;
|
|
11
11
|
try {
|
|
12
12
|
let temp;
|
|
13
|
-
if (is_1.default.isFunction(this.
|
|
14
|
-
temp = this.
|
|
13
|
+
if (is_1.default.isFunction(this.__source)) {
|
|
14
|
+
temp = this.__source();
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
temp = this.
|
|
17
|
+
temp = this.__source;
|
|
18
18
|
}
|
|
19
19
|
promise = is_1.default.isPromise(temp) ? temp : Promise.resolve(temp);
|
|
20
20
|
return promise.then(data => [null, data]).catch(err => [err, undefined]);
|
package/bin/lib/class/tracker.js
CHANGED
|
@@ -48,12 +48,12 @@ class DTrack {
|
|
|
48
48
|
}
|
|
49
49
|
exports.DTrack = DTrack;
|
|
50
50
|
class DTracker {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
__map = new Map();
|
|
52
|
+
__trackList = [];
|
|
53
53
|
can = true;
|
|
54
54
|
clear() {
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
55
|
+
this.__map.clear();
|
|
56
|
+
this.__trackList = [];
|
|
57
57
|
return this;
|
|
58
58
|
}
|
|
59
59
|
add(name, { desc = "", type = "" } = {}) {
|
|
@@ -63,13 +63,13 @@ class DTracker {
|
|
|
63
63
|
_track.name = name;
|
|
64
64
|
_track.type = type;
|
|
65
65
|
_track.desc = desc;
|
|
66
|
-
this.
|
|
66
|
+
this.__trackList.push(_track);
|
|
67
67
|
return _track.id;
|
|
68
68
|
}
|
|
69
69
|
done(id) {
|
|
70
70
|
if (!id || !this.can)
|
|
71
71
|
return;
|
|
72
|
-
const _track = this.
|
|
72
|
+
const _track = this.__trackList.find(e => e.id === id);
|
|
73
73
|
if (!_track || _track.isDone)
|
|
74
74
|
return;
|
|
75
75
|
_track.done();
|
|
@@ -77,38 +77,38 @@ class DTracker {
|
|
|
77
77
|
endTrack.id = this._endId(id);
|
|
78
78
|
endTrack.flag = 1;
|
|
79
79
|
endTrack.desc = `${_track.desc} | end`;
|
|
80
|
-
this.
|
|
80
|
+
this.__trackList.push(endTrack);
|
|
81
81
|
}
|
|
82
82
|
getTrack(id) {
|
|
83
|
-
return this.
|
|
83
|
+
return this.__trackList.find(e => e.id === id);
|
|
84
84
|
}
|
|
85
85
|
getLine(id) {
|
|
86
86
|
if (!id || id.endsWith("-end"))
|
|
87
87
|
return [];
|
|
88
|
-
const idx_s = this.
|
|
88
|
+
const idx_s = this.__trackList.findIndex(e => e.id === id);
|
|
89
89
|
if (idx_s < 0)
|
|
90
90
|
return [];
|
|
91
91
|
const endid = this._endId(id);
|
|
92
|
-
const idx_e = this.
|
|
93
|
-
const count = idx_e < 0 ? this.
|
|
94
|
-
return list_1.default.take(this.
|
|
92
|
+
const idx_e = this.__trackList.findIndex(e => e.id === endid);
|
|
93
|
+
const count = idx_e < 0 ? this.__trackList.length - idx_s : idx_e - idx_s + 1;
|
|
94
|
+
return list_1.default.take(this.__trackList, count, idx_s);
|
|
95
95
|
}
|
|
96
96
|
getListByName(name, id = "") {
|
|
97
97
|
if (!name)
|
|
98
98
|
return [];
|
|
99
|
-
const _nameList = this.
|
|
99
|
+
const _nameList = this.__trackList.filter(e => e.name === name);
|
|
100
100
|
if (_nameList.length <= 0)
|
|
101
101
|
return [];
|
|
102
102
|
if (!id)
|
|
103
103
|
return _nameList;
|
|
104
104
|
const endid = this._endId(id);
|
|
105
|
-
return this.
|
|
105
|
+
return this.__trackList.filter(e => e.id === id || e.id === endid);
|
|
106
106
|
}
|
|
107
107
|
getList() {
|
|
108
|
-
return this.
|
|
108
|
+
return this.__trackList;
|
|
109
109
|
}
|
|
110
110
|
size() {
|
|
111
|
-
return this.
|
|
111
|
+
return this.__trackList.length;
|
|
112
112
|
}
|
|
113
113
|
_endId = (id) => `${id}-end`;
|
|
114
114
|
}
|
|
@@ -4,9 +4,9 @@ function mutex(func) {
|
|
|
4
4
|
var lastThis = null;
|
|
5
5
|
async function mutexed(...args) {
|
|
6
6
|
lastThis = this || lastThis || {};
|
|
7
|
-
if (lastThis.
|
|
7
|
+
if (lastThis.__ddMutex)
|
|
8
8
|
return false;
|
|
9
|
-
lastThis.
|
|
9
|
+
lastThis.__ddMutex = true;
|
|
10
10
|
try {
|
|
11
11
|
func && (await Promise.resolve(func.apply(this, args)));
|
|
12
12
|
}
|
|
@@ -14,7 +14,7 @@ function mutex(func) {
|
|
|
14
14
|
console.log(err);
|
|
15
15
|
}
|
|
16
16
|
finally {
|
|
17
|
-
lastThis.
|
|
17
|
+
lastThis.__ddMutex = false;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
return mutexed;
|
package/bin/lib/modules/html.js
CHANGED
|
@@ -36,11 +36,29 @@ const readAsDataURL = (file, cb) => {
|
|
|
36
36
|
cb && cb(e.target?.result);
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
const downloadUrl = (filename, url) => {
|
|
40
|
+
try {
|
|
41
|
+
const a = document.createElement("a");
|
|
42
|
+
a.href = url;
|
|
43
|
+
a.download = filename;
|
|
44
|
+
a.click();
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
console.warn(`[ddan] downloadUrl`, err);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const download = (filename, obj) => {
|
|
51
|
+
if (!obj)
|
|
52
|
+
return;
|
|
53
|
+
if (typeof obj === "string") {
|
|
54
|
+
downloadUrl(filename, obj);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const href = URL?.createObjectURL(obj);
|
|
58
|
+
if (!href)
|
|
59
|
+
return;
|
|
60
|
+
downloadUrl(filename, href);
|
|
61
|
+
URL?.revokeObjectURL(href);
|
|
44
62
|
};
|
|
45
63
|
const downloadImage = (url) => {
|
|
46
64
|
try {
|
|
@@ -56,13 +74,13 @@ const downloadImage = (url) => {
|
|
|
56
74
|
let context = canvas.getContext("2d");
|
|
57
75
|
context && context.drawImage(img, 0, 0, img.width, img.height);
|
|
58
76
|
let base64 = canvas.toDataURL(); //得到图片的base64编码数据
|
|
59
|
-
|
|
77
|
+
downloadUrl(name, base64);
|
|
60
78
|
};
|
|
61
79
|
img.src = url; // 将canvas对象转换为图片的data url
|
|
62
80
|
img.setAttribute("crossOrigin", "Anonymous");
|
|
63
81
|
}
|
|
64
82
|
catch (err) {
|
|
65
|
-
console.
|
|
83
|
+
console.warn(`[ddan] downloadImage`, err);
|
|
66
84
|
}
|
|
67
85
|
return Promise.resolve();
|
|
68
86
|
};
|
|
@@ -85,8 +103,8 @@ const watermark = (text, { width = 400, height = 300, angle = 0, fillStyle = "rg
|
|
|
85
103
|
return `url(${canvas.toDataURL()})`; // "image/png" 默认
|
|
86
104
|
}
|
|
87
105
|
catch (err) {
|
|
88
|
-
console.
|
|
106
|
+
console.warn(`[ddan] watermark`, err);
|
|
89
107
|
return "";
|
|
90
108
|
}
|
|
91
109
|
};
|
|
92
|
-
exports.default = { dataURLtoFile, dataURLtoBlob, blobToFile, readAsDataURL,
|
|
110
|
+
exports.default = { dataURLtoFile, dataURLtoBlob, blobToFile, readAsDataURL, downloadUrl, download, downloadImage, watermark };
|
|
@@ -4,9 +4,9 @@ export interface IDEvent {
|
|
|
4
4
|
tag: string;
|
|
5
5
|
}
|
|
6
6
|
export default class DEvent {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
__map: Map<string, Set<Function | any>>;
|
|
8
|
+
__tagList: IDEvent[];
|
|
9
|
+
__eventId: string;
|
|
10
10
|
constructor();
|
|
11
11
|
clear(): this;
|
|
12
12
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type TSVG = "back" | "right" | "home" | "close" | "close_circle" | "close_circle_fill" | "warning" | "play" | "lock" | "lock_fill" | "plus" | "plus_circle" | "plus_circle_fill" | "star" | "star_fill" | "share" | "love" | "love_fill";
|
|
2
2
|
export declare class DIcon {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
__defStyle: string;
|
|
4
|
+
__map: Record<TSVG, string>;
|
|
5
5
|
getBase64: (svgType: TSVG) => string;
|
|
6
6
|
getSVG: (svgType: TSVG) => {
|
|
7
7
|
url: string;
|
|
@@ -25,8 +25,8 @@ export declare class DTrack {
|
|
|
25
25
|
done: (t?: number) => void;
|
|
26
26
|
}
|
|
27
27
|
export declare class DTracker {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
__map: Map<string, DTrack>;
|
|
29
|
+
__trackList: DTrack[];
|
|
30
30
|
can: boolean;
|
|
31
31
|
clear(): this;
|
|
32
32
|
add(name: string, { desc, type }?: {
|
package/bin/types/index.d.ts
CHANGED
|
@@ -224,7 +224,8 @@ declare const _default: {
|
|
|
224
224
|
dataURLtoBlob: (dataurl: any) => Blob;
|
|
225
225
|
blobToFile: (theBlob: any, fileName: any) => any;
|
|
226
226
|
readAsDataURL: (file: any, cb: any) => void;
|
|
227
|
-
|
|
227
|
+
downloadUrl: (filename: string, url: string) => void;
|
|
228
|
+
download: (filename: string, obj: string | Blob | MediaSource) => void;
|
|
228
229
|
downloadImage: (url: string) => Promise<void> | undefined;
|
|
229
230
|
watermark: (text: string, { width, height, angle, fillStyle, font, textAlign, textBaseline }?: {
|
|
230
231
|
width?: number | undefined;
|
|
@@ -3,7 +3,8 @@ declare const _default: {
|
|
|
3
3
|
dataURLtoBlob: (dataurl: any) => Blob;
|
|
4
4
|
blobToFile: (theBlob: any, fileName: any) => any;
|
|
5
5
|
readAsDataURL: (file: any, cb: any) => void;
|
|
6
|
-
|
|
6
|
+
downloadUrl: (filename: string, url: string) => void;
|
|
7
|
+
download: (filename: string, obj: string | Blob | MediaSource) => void;
|
|
7
8
|
downloadImage: (url: string) => Promise<void> | undefined;
|
|
8
9
|
watermark: (text: string, { width, height, angle, fillStyle, font, textAlign, textBaseline }?: {
|
|
9
10
|
width?: number | undefined;
|