sculp-js 1.8.1 → 1.8.3
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/lib/cjs/array.js +2 -3
- package/lib/cjs/async.js +1 -1
- package/lib/cjs/base64.js +1 -1
- package/lib/cjs/clipboard.js +1 -1
- package/lib/cjs/cloneDeep.js +117 -0
- package/lib/cjs/cookie.js +1 -1
- package/lib/cjs/date.js +1 -1
- package/lib/cjs/dom.js +1 -1
- package/lib/cjs/download.js +1 -1
- package/lib/cjs/easing.js +1 -1
- package/lib/cjs/file.js +1 -1
- package/lib/cjs/func.js +1 -28
- package/lib/cjs/index.js +5 -3
- package/lib/cjs/isEqual.js +133 -0
- package/lib/cjs/math.js +1 -1
- package/lib/cjs/number.js +1 -1
- package/lib/cjs/object.js +1 -235
- package/lib/cjs/path.js +1 -1
- package/lib/cjs/qs.js +1 -1
- package/lib/cjs/random.js +1 -1
- package/lib/cjs/string.js +1 -1
- package/lib/cjs/tooltip.js +1 -1
- package/lib/cjs/tree.js +1 -1
- package/lib/cjs/type.js +1 -1
- package/lib/cjs/unique.js +1 -1
- package/lib/cjs/url.js +1 -1
- package/lib/cjs/validator.js +1 -1
- package/lib/cjs/variable.js +1 -1
- package/lib/cjs/watermark.js +1 -1
- package/lib/cjs/we-decode.js +1 -1
- package/lib/es/array.js +2 -3
- package/lib/es/async.js +1 -1
- package/lib/es/base64.js +1 -1
- package/lib/es/clipboard.js +1 -1
- package/lib/es/cloneDeep.js +115 -0
- package/lib/es/cookie.js +1 -1
- package/lib/es/date.js +1 -1
- package/lib/es/dom.js +1 -1
- package/lib/es/download.js +1 -1
- package/lib/es/easing.js +1 -1
- package/lib/es/file.js +1 -1
- package/lib/es/func.js +1 -28
- package/lib/es/index.js +4 -2
- package/lib/es/isEqual.js +131 -0
- package/lib/es/math.js +1 -1
- package/lib/es/number.js +1 -1
- package/lib/es/object.js +2 -234
- package/lib/es/path.js +1 -1
- package/lib/es/qs.js +1 -1
- package/lib/es/random.js +1 -1
- package/lib/es/string.js +1 -1
- package/lib/es/tooltip.js +1 -1
- package/lib/es/tree.js +1 -1
- package/lib/es/type.js +1 -1
- package/lib/es/unique.js +1 -1
- package/lib/es/url.js +1 -1
- package/lib/es/validator.js +1 -1
- package/lib/es/variable.js +1 -1
- package/lib/es/watermark.js +1 -1
- package/lib/es/we-decode.js +1 -1
- package/lib/index.d.ts +21 -19
- package/lib/umd/index.js +232 -262
- package/package.json +1 -1
package/lib/cjs/array.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.8.
|
|
2
|
+
* sculp-js v1.8.3
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -68,7 +68,6 @@ async function arrayEachAsync(array, iterator, reverse = false) {
|
|
|
68
68
|
function arrayInsertBefore(array, start, to) {
|
|
69
69
|
if (start === to || start + 1 === to)
|
|
70
70
|
return;
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
72
71
|
const [source] = array.splice(start, 1);
|
|
73
72
|
const insertIndex = to < start ? to : to - 1;
|
|
74
73
|
array.splice(insertIndex, 0, source);
|
|
@@ -88,7 +87,7 @@ function arrayRemove(array, expect) {
|
|
|
88
87
|
if (_expect(val, idx))
|
|
89
88
|
indexes.push(idx);
|
|
90
89
|
});
|
|
91
|
-
|
|
90
|
+
indexes.forEach((val, idx) => {
|
|
92
91
|
array.splice(val - idx, 1);
|
|
93
92
|
});
|
|
94
93
|
return array;
|
package/lib/cjs/async.js
CHANGED
package/lib/cjs/base64.js
CHANGED
package/lib/cjs/clipboard.js
CHANGED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* sculp-js v1.8.3
|
|
3
|
+
* (c) 2023-present chandq
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
11
|
+
*
|
|
12
|
+
* 包含对null、原始值、对象循环引用的处理
|
|
13
|
+
*
|
|
14
|
+
* 对Map、Set、ArrayBuffer、Date、RegExp、Array、Object及原型链属性方法执行深拷贝
|
|
15
|
+
* @param {T} source
|
|
16
|
+
* @param {WeakMap} map
|
|
17
|
+
* @returns {T}
|
|
18
|
+
*/
|
|
19
|
+
function cloneDeep(source, map = new WeakMap()) {
|
|
20
|
+
// 处理原始类型和 null/undefined
|
|
21
|
+
if (source === null || typeof source !== 'object') {
|
|
22
|
+
return source;
|
|
23
|
+
}
|
|
24
|
+
// 处理循环引用
|
|
25
|
+
if (map.has(source)) {
|
|
26
|
+
return map.get(source);
|
|
27
|
+
}
|
|
28
|
+
// 处理 ArrayBuffer
|
|
29
|
+
if (source instanceof ArrayBuffer) {
|
|
30
|
+
const copy = new ArrayBuffer(source.byteLength);
|
|
31
|
+
new Uint8Array(copy).set(new Uint8Array(source));
|
|
32
|
+
map.set(source, copy);
|
|
33
|
+
return copy;
|
|
34
|
+
}
|
|
35
|
+
// 处理 DataView 和 TypedArray (Uint8Array 等)
|
|
36
|
+
if (ArrayBuffer.isView(source)) {
|
|
37
|
+
const constructor = source.constructor;
|
|
38
|
+
const bufferCopy = cloneDeep(source.buffer, map);
|
|
39
|
+
return new constructor(bufferCopy, source.byteOffset, source.length);
|
|
40
|
+
}
|
|
41
|
+
// 处理 Date 对象
|
|
42
|
+
if (source instanceof Date) {
|
|
43
|
+
const copy = new Date(source.getTime());
|
|
44
|
+
map.set(source, copy);
|
|
45
|
+
return copy;
|
|
46
|
+
}
|
|
47
|
+
// 处理 RegExp 对象
|
|
48
|
+
if (source instanceof RegExp) {
|
|
49
|
+
const copy = new RegExp(source.source, source.flags);
|
|
50
|
+
copy.lastIndex = source.lastIndex; // 保留匹配状态
|
|
51
|
+
map.set(source, copy);
|
|
52
|
+
return copy;
|
|
53
|
+
}
|
|
54
|
+
// 处理 Map
|
|
55
|
+
if (source instanceof Map) {
|
|
56
|
+
const copy = new Map();
|
|
57
|
+
map.set(source, copy);
|
|
58
|
+
source.forEach((value, key) => {
|
|
59
|
+
copy.set(cloneDeep(key, map), cloneDeep(value, map));
|
|
60
|
+
});
|
|
61
|
+
return copy;
|
|
62
|
+
}
|
|
63
|
+
// 处理 Set
|
|
64
|
+
if (source instanceof Set) {
|
|
65
|
+
const copy = new Set();
|
|
66
|
+
map.set(source, copy);
|
|
67
|
+
source.forEach(value => {
|
|
68
|
+
copy.add(cloneDeep(value, map));
|
|
69
|
+
});
|
|
70
|
+
return copy;
|
|
71
|
+
}
|
|
72
|
+
// 处理数组 (包含稀疏数组)
|
|
73
|
+
if (Array.isArray(source)) {
|
|
74
|
+
const copy = new Array(source.length);
|
|
75
|
+
map.set(source, copy);
|
|
76
|
+
// 克隆所有有效索引
|
|
77
|
+
for (let i = 0, len = source.length; i < len; i++) {
|
|
78
|
+
if (i in source) {
|
|
79
|
+
// 保留空位
|
|
80
|
+
copy[i] = cloneDeep(source[i], map);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// 克隆数组的自定义属性
|
|
84
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
85
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
86
|
+
Object.defineProperty(copy, key, {
|
|
87
|
+
...descriptors[key],
|
|
88
|
+
value: cloneDeep(descriptors[key].value, map)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return copy;
|
|
92
|
+
}
|
|
93
|
+
// 处理普通对象和类实例
|
|
94
|
+
const copy = Object.create(Object.getPrototypeOf(source));
|
|
95
|
+
map.set(source, copy);
|
|
96
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
97
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
98
|
+
const descriptor = descriptors[key];
|
|
99
|
+
if ('value' in descriptor) {
|
|
100
|
+
// 克隆数据属性
|
|
101
|
+
descriptor.value = cloneDeep(descriptor.value, map);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// 处理访问器属性 (getter/setter)
|
|
105
|
+
if (descriptor.get) {
|
|
106
|
+
descriptor.get = cloneDeep(descriptor.get, map);
|
|
107
|
+
}
|
|
108
|
+
if (descriptor.set) {
|
|
109
|
+
descriptor.set = cloneDeep(descriptor.set, map);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
Object.defineProperty(copy, key, descriptor);
|
|
113
|
+
}
|
|
114
|
+
return copy;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
exports.cloneDeep = cloneDeep;
|
package/lib/cjs/cookie.js
CHANGED
package/lib/cjs/date.js
CHANGED
package/lib/cjs/dom.js
CHANGED
package/lib/cjs/download.js
CHANGED
package/lib/cjs/easing.js
CHANGED
package/lib/cjs/file.js
CHANGED
package/lib/cjs/func.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.8.
|
|
2
|
+
* sculp-js v1.8.3
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -86,13 +86,10 @@ const once = (func) => {
|
|
|
86
86
|
let called = false;
|
|
87
87
|
let result;
|
|
88
88
|
return function (...args) {
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
90
89
|
if (called)
|
|
91
90
|
return result;
|
|
92
91
|
called = true;
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
94
92
|
result = func.call(this, ...args);
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
96
93
|
return result;
|
|
97
94
|
};
|
|
98
95
|
};
|
|
@@ -102,24 +99,12 @@ const once = (func) => {
|
|
|
102
99
|
* @param val
|
|
103
100
|
*/
|
|
104
101
|
function setGlobal(key, val) {
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
108
102
|
if (typeof globalThis !== 'undefined')
|
|
109
103
|
globalThis[key] = val;
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
111
|
-
// @ts-ignore
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
113
104
|
else if (typeof window !== 'undefined')
|
|
114
105
|
window[key] = val;
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
118
106
|
else if (typeof global !== 'undefined')
|
|
119
107
|
global[key] = val;
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
123
108
|
else if (typeof self !== 'undefined')
|
|
124
109
|
self[key] = val;
|
|
125
110
|
else
|
|
@@ -131,24 +116,12 @@ function setGlobal(key, val) {
|
|
|
131
116
|
* @param val
|
|
132
117
|
*/
|
|
133
118
|
function getGlobal(key) {
|
|
134
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
137
119
|
if (typeof globalThis !== 'undefined')
|
|
138
120
|
return globalThis[key];
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
140
|
-
// @ts-ignore
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
142
121
|
else if (typeof window !== 'undefined')
|
|
143
122
|
return window[key];
|
|
144
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
145
|
-
// @ts-ignore
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
147
123
|
else if (typeof global !== 'undefined')
|
|
148
124
|
return global[key];
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
150
|
-
// @ts-ignore
|
|
151
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
152
125
|
else if (typeof self !== 'undefined')
|
|
153
126
|
return self[key];
|
|
154
127
|
}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.8.
|
|
2
|
+
* sculp-js v1.8.3
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -32,6 +32,8 @@ var weDecode = require('./we-decode.js');
|
|
|
32
32
|
var base64 = require('./base64.js');
|
|
33
33
|
var validator = require('./validator.js');
|
|
34
34
|
var variable = require('./variable.js');
|
|
35
|
+
var cloneDeep = require('./cloneDeep.js');
|
|
36
|
+
var isEqual = require('./isEqual.js');
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
|
|
@@ -63,8 +65,6 @@ exports.downloadBlob = download.downloadBlob;
|
|
|
63
65
|
exports.downloadData = download.downloadData;
|
|
64
66
|
exports.downloadHref = download.downloadHref;
|
|
65
67
|
exports.downloadURL = download.downloadURL;
|
|
66
|
-
exports.cloneDeep = object.cloneDeep;
|
|
67
|
-
exports.isEqual = object.isEqual;
|
|
68
68
|
exports.isPlainObject = object.isPlainObject;
|
|
69
69
|
exports.objectAssign = object.objectAssign;
|
|
70
70
|
exports.objectEach = object.objectEach;
|
|
@@ -174,3 +174,5 @@ exports.executeInScope = variable.executeInScope;
|
|
|
174
174
|
exports.parseVarFromString = variable.parseVarFromString;
|
|
175
175
|
exports.replaceVarFromString = variable.replaceVarFromString;
|
|
176
176
|
exports.uniqueSymbol = variable.uniqueSymbol;
|
|
177
|
+
exports.cloneDeep = cloneDeep.cloneDeep;
|
|
178
|
+
exports.isEqual = isEqual.isEqual;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* sculp-js v1.8.3
|
|
3
|
+
* (c) 2023-present chandq
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var type = require('./type.js');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 比较两值是否相等,适用所有数据类型
|
|
13
|
+
* @param {Comparable} a
|
|
14
|
+
* @param {Comparable} b
|
|
15
|
+
* @returns {boolean}
|
|
16
|
+
*/
|
|
17
|
+
function isEqual(a, b) {
|
|
18
|
+
return deepEqual(a, b);
|
|
19
|
+
}
|
|
20
|
+
function deepEqual(a, b, compared = new WeakMap()) {
|
|
21
|
+
// 相同值快速返回
|
|
22
|
+
if (Object.is(a, b))
|
|
23
|
+
return true;
|
|
24
|
+
// 类型不同直接返回false
|
|
25
|
+
const typeA = Object.prototype.toString.call(a);
|
|
26
|
+
const typeB = Object.prototype.toString.call(b);
|
|
27
|
+
if (typeA !== typeB)
|
|
28
|
+
return false;
|
|
29
|
+
// 只缓存对象类型
|
|
30
|
+
if (type.isObject(a) && type.isObject(b)) {
|
|
31
|
+
if (compared.has(a))
|
|
32
|
+
return compared.get(a) === b;
|
|
33
|
+
compared.set(a, b);
|
|
34
|
+
compared.set(b, a);
|
|
35
|
+
}
|
|
36
|
+
// 处理特殊对象类型
|
|
37
|
+
switch (typeA) {
|
|
38
|
+
case '[object Date]':
|
|
39
|
+
return a.getTime() === b.getTime();
|
|
40
|
+
case '[object RegExp]':
|
|
41
|
+
return a.toString() === b.toString();
|
|
42
|
+
case '[object Map]':
|
|
43
|
+
return compareMap(a, b, compared);
|
|
44
|
+
case '[object Set]':
|
|
45
|
+
return compareSet(a, b, compared);
|
|
46
|
+
case '[object ArrayBuffer]':
|
|
47
|
+
return compareArrayBuffer(a, b);
|
|
48
|
+
case '[object DataView]':
|
|
49
|
+
return compareDataView(a, b, compared);
|
|
50
|
+
case '[object Int8Array]':
|
|
51
|
+
case '[object Uint8Array]':
|
|
52
|
+
case '[object Uint8ClampedArray]':
|
|
53
|
+
case '[object Int16Array]':
|
|
54
|
+
case '[object Uint16Array]':
|
|
55
|
+
case '[object Int32Array]':
|
|
56
|
+
case '[object Uint32Array]':
|
|
57
|
+
case '[object Float32Array]':
|
|
58
|
+
case '[object Float64Array]':
|
|
59
|
+
return compareTypedArray(a, b, compared);
|
|
60
|
+
case '[object Object]':
|
|
61
|
+
return compareObjects(a, b, compared);
|
|
62
|
+
case '[object Array]':
|
|
63
|
+
return compareArrays(a, b, compared);
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
// 辅助比较函数
|
|
68
|
+
function compareMap(a, b, compared) {
|
|
69
|
+
if (a.size !== b.size)
|
|
70
|
+
return false;
|
|
71
|
+
for (const [key, value] of a) {
|
|
72
|
+
if (!b.has(key) || !deepEqual(value, b.get(key), compared))
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
function compareSet(a, b, compared) {
|
|
78
|
+
if (a.size !== b.size)
|
|
79
|
+
return false;
|
|
80
|
+
for (const value of a) {
|
|
81
|
+
let found = false;
|
|
82
|
+
for (const bValue of b) {
|
|
83
|
+
if (deepEqual(value, bValue, compared)) {
|
|
84
|
+
found = true;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!found)
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
function compareArrayBuffer(a, b) {
|
|
94
|
+
if (a.byteLength !== b.byteLength)
|
|
95
|
+
return false;
|
|
96
|
+
return new DataView(a).getInt32(0) === new DataView(b).getInt32(0);
|
|
97
|
+
}
|
|
98
|
+
function compareDataView(a, b, compared) {
|
|
99
|
+
return a.byteLength === b.byteLength && deepEqual(new Uint8Array(a.buffer), new Uint8Array(b.buffer), compared);
|
|
100
|
+
}
|
|
101
|
+
function compareTypedArray(a, b, compared) {
|
|
102
|
+
return a.byteLength === b.byteLength && deepEqual(Array.from(a), Array.from(b), compared);
|
|
103
|
+
}
|
|
104
|
+
function compareObjects(a, b, compared) {
|
|
105
|
+
const keysA = Reflect.ownKeys(a);
|
|
106
|
+
const keysB = Reflect.ownKeys(b);
|
|
107
|
+
if (keysA.length !== keysB.length)
|
|
108
|
+
return false;
|
|
109
|
+
for (const key of keysA) {
|
|
110
|
+
if (!keysB.includes(key))
|
|
111
|
+
return false;
|
|
112
|
+
if (!deepEqual(a[key], b[key], compared))
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
// 原型链比较
|
|
116
|
+
return Object.getPrototypeOf(a) === Object.getPrototypeOf(b);
|
|
117
|
+
}
|
|
118
|
+
function compareArrays(a, b, compared) {
|
|
119
|
+
// 增加有效索引检查
|
|
120
|
+
const keysA = Object.keys(a).map(Number);
|
|
121
|
+
const keysB = Object.keys(b).map(Number);
|
|
122
|
+
if (keysA.length !== keysB.length)
|
|
123
|
+
return false;
|
|
124
|
+
// 递归比较每个元素
|
|
125
|
+
for (let i = 0, len = a.length; i < len; i++) {
|
|
126
|
+
if (!deepEqual(a[i], b[i], compared))
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
// 比较数组对象的其他属性
|
|
130
|
+
return compareObjects(a, b, compared);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
exports.isEqual = isEqual;
|
package/lib/cjs/math.js
CHANGED
package/lib/cjs/number.js
CHANGED