ddan-js 2.0.7 → 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/css.js +8 -3
- package/bin/lib/modules/hook/mutex.js +3 -3
- package/bin/lib/modules/html.js +49 -8
- package/bin/lib/modules/obj/index.js +1 -1
- 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 +15 -2
- package/bin/types/modules/css.d.ts +4 -1
- package/bin/types/modules/html.d.ts +11 -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
|
}
|
package/bin/lib/modules/css.js
CHANGED
|
@@ -17,7 +17,7 @@ const stringify = (styleObj) => {
|
|
|
17
17
|
});
|
|
18
18
|
return result;
|
|
19
19
|
};
|
|
20
|
-
const parse = (styleStr, camel = false) => {
|
|
20
|
+
const parse = (styleStr, { camel = false, pure = true } = {}) => {
|
|
21
21
|
if (!styleStr.trim())
|
|
22
22
|
return undefined;
|
|
23
23
|
const ret = qs_1.default.parse(styleStr, { sep: ';', eq: ':', uri: false });
|
|
@@ -25,7 +25,7 @@ const parse = (styleStr, camel = false) => {
|
|
|
25
25
|
util_1.default.forof(ret, (k, v) => {
|
|
26
26
|
if (!v)
|
|
27
27
|
return;
|
|
28
|
-
const _k = camel ? string_1.default.camelCase(k) : k;
|
|
28
|
+
const _k = camel ? ((pure && k.startsWith("_")) ? k : string_1.default.camelCase(k)) : k;
|
|
29
29
|
if (rule_1.default.isFloat(v)) {
|
|
30
30
|
result[_k] = +v;
|
|
31
31
|
}
|
|
@@ -68,6 +68,10 @@ const commonFields = [
|
|
|
68
68
|
"borderColor",
|
|
69
69
|
"borderRadius",
|
|
70
70
|
"background",
|
|
71
|
+
"backgroundImage",
|
|
72
|
+
"backgroundRepeat",
|
|
73
|
+
"backgroundSize",
|
|
74
|
+
"backgroundPosition",
|
|
71
75
|
"color",
|
|
72
76
|
"overflow",
|
|
73
77
|
"opacity",
|
|
@@ -80,7 +84,8 @@ const commonFields = [
|
|
|
80
84
|
"flex",
|
|
81
85
|
"flexBasis",
|
|
82
86
|
"flexFlow",
|
|
83
|
-
"flexShrink"
|
|
87
|
+
"flexShrink",
|
|
88
|
+
"pointerEvents",
|
|
84
89
|
];
|
|
85
90
|
const fixFields = [
|
|
86
91
|
"top",
|
|
@@ -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,14 +74,37 @@ 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
|
};
|
|
69
|
-
|
|
87
|
+
const watermark = (text, { width = 400, height = 300, angle = 0, fillStyle = "rgba(0, 0, 0, 0.2)", font = "16px Arial", textAlign = "left", textBaseline = "middle" } = {}) => {
|
|
88
|
+
try {
|
|
89
|
+
if (!text)
|
|
90
|
+
return "";
|
|
91
|
+
const canvas = document.createElement("canvas");
|
|
92
|
+
canvas.width = width;
|
|
93
|
+
canvas.height = height;
|
|
94
|
+
const ctx = canvas.getContext("2d");
|
|
95
|
+
if (!ctx)
|
|
96
|
+
return "";
|
|
97
|
+
angle && ctx.rotate((angle * Math.PI) / 180);
|
|
98
|
+
fillStyle && (ctx.fillStyle = fillStyle);
|
|
99
|
+
font && (ctx.font = font);
|
|
100
|
+
textAlign && (ctx.textAlign = textAlign);
|
|
101
|
+
textBaseline && (ctx.textBaseline = textBaseline);
|
|
102
|
+
ctx.fillText(text, canvas.width / 10, canvas.height / 2);
|
|
103
|
+
return `url(${canvas.toDataURL()})`; // "image/png" 默认
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
console.warn(`[ddan] watermark`, err);
|
|
107
|
+
return "";
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
exports.default = { dataURLtoFile, dataURLtoBlob, blobToFile, readAsDataURL, downloadUrl, download, downloadImage, watermark };
|
|
@@ -9,7 +9,7 @@ const copy = (source, options = {}) => {
|
|
|
9
9
|
return newData;
|
|
10
10
|
if (Array.isArray(newData))
|
|
11
11
|
return newData;
|
|
12
|
-
const { fields = [], camel = false, pure =
|
|
12
|
+
const { fields = [], camel = false, pure = true } = options;
|
|
13
13
|
if ((!fields || fields.length <= 0) && !camel)
|
|
14
14
|
return newData;
|
|
15
15
|
const result = {};
|
|
@@ -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
|
@@ -195,7 +195,10 @@ declare const _default: {
|
|
|
195
195
|
};
|
|
196
196
|
css: {
|
|
197
197
|
stringify: (styleObj: Record<string, string | number>) => string;
|
|
198
|
-
parse: (styleStr: string, camel
|
|
198
|
+
parse: (styleStr: string, { camel, pure }?: {
|
|
199
|
+
camel?: boolean | undefined;
|
|
200
|
+
pure?: boolean | undefined;
|
|
201
|
+
}) => {} | undefined;
|
|
199
202
|
fixValue: (value: string | number, unit?: string) => string | number;
|
|
200
203
|
style: (cssKV: Record<string, any>, unit?: string) => string;
|
|
201
204
|
commonFields: string[];
|
|
@@ -221,8 +224,18 @@ declare const _default: {
|
|
|
221
224
|
dataURLtoBlob: (dataurl: any) => Blob;
|
|
222
225
|
blobToFile: (theBlob: any, fileName: any) => any;
|
|
223
226
|
readAsDataURL: (file: any, cb: any) => void;
|
|
224
|
-
|
|
227
|
+
downloadUrl: (filename: string, url: string) => void;
|
|
228
|
+
download: (filename: string, obj: string | Blob | MediaSource) => void;
|
|
225
229
|
downloadImage: (url: string) => Promise<void> | undefined;
|
|
230
|
+
watermark: (text: string, { width, height, angle, fillStyle, font, textAlign, textBaseline }?: {
|
|
231
|
+
width?: number | undefined;
|
|
232
|
+
height?: number | undefined;
|
|
233
|
+
angle?: number | undefined;
|
|
234
|
+
fillStyle?: string | undefined;
|
|
235
|
+
font?: string | undefined;
|
|
236
|
+
textAlign?: "center" | "end" | "left" | "right" | "start" | undefined;
|
|
237
|
+
textBaseline?: "alphabetic" | "bottom" | "hanging" | "ideographic" | "middle" | "top" | undefined;
|
|
238
|
+
}) => string;
|
|
226
239
|
};
|
|
227
240
|
icon: import("./class/icon").DIcon;
|
|
228
241
|
rule: {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
stringify: (styleObj: Record<string, string | number>) => string;
|
|
3
|
-
parse: (styleStr: string, camel
|
|
3
|
+
parse: (styleStr: string, { camel, pure }?: {
|
|
4
|
+
camel?: boolean | undefined;
|
|
5
|
+
pure?: boolean | undefined;
|
|
6
|
+
}) => {} | undefined;
|
|
4
7
|
fixValue: (value: string | number, unit?: string) => string | number;
|
|
5
8
|
style: (cssKV: Record<string, any>, unit?: string) => string;
|
|
6
9
|
commonFields: string[];
|
|
@@ -3,7 +3,17 @@ 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;
|
|
9
|
+
watermark: (text: string, { width, height, angle, fillStyle, font, textAlign, textBaseline }?: {
|
|
10
|
+
width?: number | undefined;
|
|
11
|
+
height?: number | undefined;
|
|
12
|
+
angle?: number | undefined;
|
|
13
|
+
fillStyle?: string | undefined;
|
|
14
|
+
font?: string | undefined;
|
|
15
|
+
textAlign?: "center" | "end" | "left" | "right" | "start" | undefined;
|
|
16
|
+
textBaseline?: "alphabetic" | "bottom" | "hanging" | "ideographic" | "middle" | "top" | undefined;
|
|
17
|
+
}) => string;
|
|
8
18
|
};
|
|
9
19
|
export default _default;
|