sculp-js 1.8.2 → 1.8.4
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 +29 -5
- 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 +3 -2
- 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 +30 -6
- 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 +4 -3
- package/lib/es/watermark.js +1 -1
- package/lib/es/we-decode.js +1 -1
- package/lib/index.d.ts +32 -21
- package/lib/umd/index.js +262 -267
- package/package.json +1 -1
package/lib/cjs/object.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.8.
|
|
2
|
+
* sculp-js v1.8.4
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -60,7 +60,6 @@ function objectMap(obj, iterator) {
|
|
|
60
60
|
for (const key in obj) {
|
|
61
61
|
if (!type.objectHas(obj, key))
|
|
62
62
|
continue;
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
64
63
|
obj2[key] = iterator(obj[key], key);
|
|
65
64
|
}
|
|
66
65
|
return obj2;
|
|
@@ -75,7 +74,6 @@ function objectPick(obj, keys) {
|
|
|
75
74
|
const obj2 = {};
|
|
76
75
|
objectEach(obj, (v, k) => {
|
|
77
76
|
if (keys.includes(k)) {
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
79
77
|
// @ts-ignore
|
|
80
78
|
obj2[k] = v;
|
|
81
79
|
}
|
|
@@ -92,7 +90,6 @@ function objectOmit(obj, keys) {
|
|
|
92
90
|
const obj2 = {};
|
|
93
91
|
objectEach(obj, (v, k) => {
|
|
94
92
|
if (!keys.includes(k)) {
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
96
93
|
// @ts-ignore
|
|
97
94
|
obj2[k] = v;
|
|
98
95
|
}
|
|
@@ -145,7 +142,6 @@ function objectAssign(source, ...targets) {
|
|
|
145
142
|
const map = new Map();
|
|
146
143
|
for (let i = 0, len = targets.length; i < len; i++) {
|
|
147
144
|
const target = targets[i];
|
|
148
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
149
145
|
// @ts-ignore
|
|
150
146
|
source = merge(map, source, target);
|
|
151
147
|
}
|
|
@@ -203,237 +199,7 @@ function objectGet(obj, path, strict = false) {
|
|
|
203
199
|
v: tempObj ? tempObj[keyArr[i]] : undefined
|
|
204
200
|
};
|
|
205
201
|
}
|
|
206
|
-
/**
|
|
207
|
-
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
208
|
-
*
|
|
209
|
-
* 包含对null、原始值、对象循环引用的处理
|
|
210
|
-
*
|
|
211
|
-
* 对Map、Set、ArrayBuffer、Date、RegExp、Array、Object及原型链属性方法执行深拷贝
|
|
212
|
-
* @param {T} source
|
|
213
|
-
* @param {WeakMap} map
|
|
214
|
-
* @returns {T}
|
|
215
|
-
*/
|
|
216
|
-
function cloneDeep(source, map = new WeakMap()) {
|
|
217
|
-
// 处理原始类型和 null/undefined
|
|
218
|
-
if (source === null || typeof source !== 'object') {
|
|
219
|
-
return source;
|
|
220
|
-
}
|
|
221
|
-
// 处理循环引用
|
|
222
|
-
if (map.has(source)) {
|
|
223
|
-
return map.get(source);
|
|
224
|
-
}
|
|
225
|
-
// 处理 ArrayBuffer
|
|
226
|
-
if (source instanceof ArrayBuffer) {
|
|
227
|
-
const copy = new ArrayBuffer(source.byteLength);
|
|
228
|
-
new Uint8Array(copy).set(new Uint8Array(source));
|
|
229
|
-
map.set(source, copy);
|
|
230
|
-
return copy;
|
|
231
|
-
}
|
|
232
|
-
// 处理 DataView 和 TypedArray (Uint8Array 等)
|
|
233
|
-
if (ArrayBuffer.isView(source)) {
|
|
234
|
-
const constructor = source.constructor;
|
|
235
|
-
const bufferCopy = cloneDeep(source.buffer, map);
|
|
236
|
-
return new constructor(bufferCopy, source.byteOffset, source.length);
|
|
237
|
-
}
|
|
238
|
-
// 处理 Date 对象
|
|
239
|
-
if (source instanceof Date) {
|
|
240
|
-
const copy = new Date(source.getTime());
|
|
241
|
-
map.set(source, copy);
|
|
242
|
-
return copy;
|
|
243
|
-
}
|
|
244
|
-
// 处理 RegExp 对象
|
|
245
|
-
if (source instanceof RegExp) {
|
|
246
|
-
const copy = new RegExp(source.source, source.flags);
|
|
247
|
-
copy.lastIndex = source.lastIndex; // 保留匹配状态
|
|
248
|
-
map.set(source, copy);
|
|
249
|
-
return copy;
|
|
250
|
-
}
|
|
251
|
-
// 处理 Map
|
|
252
|
-
if (source instanceof Map) {
|
|
253
|
-
const copy = new Map();
|
|
254
|
-
map.set(source, copy);
|
|
255
|
-
source.forEach((value, key) => {
|
|
256
|
-
copy.set(cloneDeep(key, map), cloneDeep(value, map));
|
|
257
|
-
});
|
|
258
|
-
return copy;
|
|
259
|
-
}
|
|
260
|
-
// 处理 Set
|
|
261
|
-
if (source instanceof Set) {
|
|
262
|
-
const copy = new Set();
|
|
263
|
-
map.set(source, copy);
|
|
264
|
-
source.forEach(value => {
|
|
265
|
-
copy.add(cloneDeep(value, map));
|
|
266
|
-
});
|
|
267
|
-
return copy;
|
|
268
|
-
}
|
|
269
|
-
// 处理数组 (包含稀疏数组)
|
|
270
|
-
if (Array.isArray(source)) {
|
|
271
|
-
const copy = new Array(source.length);
|
|
272
|
-
map.set(source, copy);
|
|
273
|
-
// 克隆所有有效索引
|
|
274
|
-
for (let i = 0, len = source.length; i < len; i++) {
|
|
275
|
-
if (i in source) {
|
|
276
|
-
// 保留空位
|
|
277
|
-
copy[i] = cloneDeep(source[i], map);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
// 克隆数组的自定义属性
|
|
281
|
-
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
282
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
283
|
-
Object.defineProperty(copy, key, {
|
|
284
|
-
...descriptors[key],
|
|
285
|
-
value: cloneDeep(descriptors[key].value, map)
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
return copy;
|
|
289
|
-
}
|
|
290
|
-
// 处理普通对象和类实例
|
|
291
|
-
const copy = Object.create(Object.getPrototypeOf(source));
|
|
292
|
-
map.set(source, copy);
|
|
293
|
-
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
294
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
295
|
-
const descriptor = descriptors[key];
|
|
296
|
-
if ('value' in descriptor) {
|
|
297
|
-
// 克隆数据属性
|
|
298
|
-
descriptor.value = cloneDeep(descriptor.value, map);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
// 处理访问器属性 (getter/setter)
|
|
302
|
-
if (descriptor.get) {
|
|
303
|
-
descriptor.get = cloneDeep(descriptor.get, map);
|
|
304
|
-
}
|
|
305
|
-
if (descriptor.set) {
|
|
306
|
-
descriptor.set = cloneDeep(descriptor.set, map);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
Object.defineProperty(copy, key, descriptor);
|
|
310
|
-
}
|
|
311
|
-
return copy;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* 比较两值是否相等,适用所有数据类型
|
|
315
|
-
* @param {Comparable} a
|
|
316
|
-
* @param {Comparable} b
|
|
317
|
-
* @returns {boolean}
|
|
318
|
-
*/
|
|
319
|
-
function isEqual(a, b) {
|
|
320
|
-
return deepEqual(a, b);
|
|
321
|
-
}
|
|
322
|
-
function deepEqual(a, b, compared = new WeakMap()) {
|
|
323
|
-
// 相同值快速返回
|
|
324
|
-
if (Object.is(a, b))
|
|
325
|
-
return true;
|
|
326
|
-
// 类型不同直接返回false
|
|
327
|
-
const typeA = Object.prototype.toString.call(a);
|
|
328
|
-
const typeB = Object.prototype.toString.call(b);
|
|
329
|
-
if (typeA !== typeB)
|
|
330
|
-
return false;
|
|
331
|
-
// 只缓存对象类型
|
|
332
|
-
if (type.isObject(a) && type.isObject(b)) {
|
|
333
|
-
if (compared.has(a))
|
|
334
|
-
return compared.get(a) === b;
|
|
335
|
-
compared.set(a, b);
|
|
336
|
-
compared.set(b, a);
|
|
337
|
-
}
|
|
338
|
-
// 处理特殊对象类型
|
|
339
|
-
switch (typeA) {
|
|
340
|
-
case '[object Date]':
|
|
341
|
-
return a.getTime() === b.getTime();
|
|
342
|
-
case '[object RegExp]':
|
|
343
|
-
return a.toString() === b.toString();
|
|
344
|
-
case '[object Map]':
|
|
345
|
-
return compareMap(a, b, compared);
|
|
346
|
-
case '[object Set]':
|
|
347
|
-
return compareSet(a, b, compared);
|
|
348
|
-
case '[object ArrayBuffer]':
|
|
349
|
-
return compareArrayBuffer(a, b);
|
|
350
|
-
case '[object DataView]':
|
|
351
|
-
return compareDataView(a, b, compared);
|
|
352
|
-
case '[object Int8Array]':
|
|
353
|
-
case '[object Uint8Array]':
|
|
354
|
-
case '[object Uint8ClampedArray]':
|
|
355
|
-
case '[object Int16Array]':
|
|
356
|
-
case '[object Uint16Array]':
|
|
357
|
-
case '[object Int32Array]':
|
|
358
|
-
case '[object Uint32Array]':
|
|
359
|
-
case '[object Float32Array]':
|
|
360
|
-
case '[object Float64Array]':
|
|
361
|
-
return compareTypedArray(a, b, compared);
|
|
362
|
-
case '[object Object]':
|
|
363
|
-
return compareObjects(a, b, compared);
|
|
364
|
-
case '[object Array]':
|
|
365
|
-
return compareArrays(a, b, compared);
|
|
366
|
-
}
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
// 辅助比较函数
|
|
370
|
-
function compareMap(a, b, compared) {
|
|
371
|
-
if (a.size !== b.size)
|
|
372
|
-
return false;
|
|
373
|
-
for (const [key, value] of a) {
|
|
374
|
-
if (!b.has(key) || !deepEqual(value, b.get(key), compared))
|
|
375
|
-
return false;
|
|
376
|
-
}
|
|
377
|
-
return true;
|
|
378
|
-
}
|
|
379
|
-
function compareSet(a, b, compared) {
|
|
380
|
-
if (a.size !== b.size)
|
|
381
|
-
return false;
|
|
382
|
-
for (const value of a) {
|
|
383
|
-
let found = false;
|
|
384
|
-
for (const bValue of b) {
|
|
385
|
-
if (deepEqual(value, bValue, compared)) {
|
|
386
|
-
found = true;
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (!found)
|
|
391
|
-
return false;
|
|
392
|
-
}
|
|
393
|
-
return true;
|
|
394
|
-
}
|
|
395
|
-
function compareArrayBuffer(a, b) {
|
|
396
|
-
if (a.byteLength !== b.byteLength)
|
|
397
|
-
return false;
|
|
398
|
-
return new DataView(a).getInt32(0) === new DataView(b).getInt32(0);
|
|
399
|
-
}
|
|
400
|
-
function compareDataView(a, b, compared) {
|
|
401
|
-
return a.byteLength === b.byteLength && deepEqual(new Uint8Array(a.buffer), new Uint8Array(b.buffer), compared);
|
|
402
|
-
}
|
|
403
|
-
function compareTypedArray(a, b, compared) {
|
|
404
|
-
return a.byteLength === b.byteLength && deepEqual(Array.from(a), Array.from(b), compared);
|
|
405
|
-
}
|
|
406
|
-
function compareObjects(a, b, compared) {
|
|
407
|
-
const keysA = Reflect.ownKeys(a);
|
|
408
|
-
const keysB = Reflect.ownKeys(b);
|
|
409
|
-
if (keysA.length !== keysB.length)
|
|
410
|
-
return false;
|
|
411
|
-
for (const key of keysA) {
|
|
412
|
-
if (!keysB.includes(key))
|
|
413
|
-
return false;
|
|
414
|
-
if (!deepEqual(a[key], b[key], compared))
|
|
415
|
-
return false;
|
|
416
|
-
}
|
|
417
|
-
// 原型链比较
|
|
418
|
-
return Object.getPrototypeOf(a) === Object.getPrototypeOf(b);
|
|
419
|
-
}
|
|
420
|
-
function compareArrays(a, b, compared) {
|
|
421
|
-
// 增加有效索引检查
|
|
422
|
-
const keysA = Object.keys(a).map(Number);
|
|
423
|
-
const keysB = Object.keys(b).map(Number);
|
|
424
|
-
if (keysA.length !== keysB.length)
|
|
425
|
-
return false;
|
|
426
|
-
// 递归比较每个元素
|
|
427
|
-
for (let i = 0, len = a.length; i < len; i++) {
|
|
428
|
-
if (!deepEqual(a[i], b[i], compared))
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
// 比较数组对象的其他属性
|
|
432
|
-
return compareObjects(a, b, compared);
|
|
433
|
-
}
|
|
434
202
|
|
|
435
|
-
exports.cloneDeep = cloneDeep;
|
|
436
|
-
exports.isEqual = isEqual;
|
|
437
203
|
exports.isPlainObject = isPlainObject;
|
|
438
204
|
exports.objectAssign = objectAssign;
|
|
439
205
|
exports.objectEach = objectEach;
|
package/lib/cjs/path.js
CHANGED
package/lib/cjs/qs.js
CHANGED
package/lib/cjs/random.js
CHANGED
package/lib/cjs/string.js
CHANGED
package/lib/cjs/tooltip.js
CHANGED
package/lib/cjs/tree.js
CHANGED
package/lib/cjs/type.js
CHANGED
package/lib/cjs/unique.js
CHANGED
package/lib/cjs/url.js
CHANGED
package/lib/cjs/validator.js
CHANGED
package/lib/cjs/variable.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.8.
|
|
2
|
+
* sculp-js v1.8.4
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -49,7 +49,8 @@ function parseVariableRegExp(leftMatchSymbol, rightMatchSymbol) {
|
|
|
49
49
|
* default match symbol {} same as /{\s*([^{}\s]*)\s*}/g
|
|
50
50
|
*/
|
|
51
51
|
function parseVarFromString(str, leftMatchSymbol = '{', rightMatchSymbol = '}') {
|
|
52
|
-
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
return Array.from(str.matchAll(parseVariableRegExp(leftMatchSymbol, rightMatchSymbol))).map(el => type.isNullOrUnDef(el) ? void 0 : el[1]);
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* 替换字符串中的插值变量
|
package/lib/cjs/watermark.js
CHANGED
package/lib/cjs/we-decode.js
CHANGED
package/lib/es/array.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.8.
|
|
2
|
+
* sculp-js v1.8.4
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -66,7 +66,6 @@ async function arrayEachAsync(array, iterator, reverse = false) {
|
|
|
66
66
|
function arrayInsertBefore(array, start, to) {
|
|
67
67
|
if (start === to || start + 1 === to)
|
|
68
68
|
return;
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
70
69
|
const [source] = array.splice(start, 1);
|
|
71
70
|
const insertIndex = to < start ? to : to - 1;
|
|
72
71
|
array.splice(insertIndex, 0, source);
|
|
@@ -86,7 +85,7 @@ function arrayRemove(array, expect) {
|
|
|
86
85
|
if (_expect(val, idx))
|
|
87
86
|
indexes.push(idx);
|
|
88
87
|
});
|
|
89
|
-
|
|
88
|
+
indexes.forEach((val, idx) => {
|
|
90
89
|
array.splice(val - idx, 1);
|
|
91
90
|
});
|
|
92
91
|
return array;
|
package/lib/es/async.js
CHANGED
package/lib/es/base64.js
CHANGED
package/lib/es/clipboard.js
CHANGED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* sculp-js v1.8.4
|
|
3
|
+
* (c) 2023-present chandq
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
9
|
+
*
|
|
10
|
+
* 包含对null、原始值、对象循环引用的处理
|
|
11
|
+
*
|
|
12
|
+
* 对Map、Set、ArrayBuffer、Date、RegExp、Array、Object及原型链属性方法执行深拷贝
|
|
13
|
+
* @param {T} source
|
|
14
|
+
* @param {WeakMap} map
|
|
15
|
+
* @returns {T}
|
|
16
|
+
*/
|
|
17
|
+
function cloneDeep(source, map = new WeakMap()) {
|
|
18
|
+
// 处理原始类型和 null/undefined
|
|
19
|
+
if (source === null || typeof source !== 'object') {
|
|
20
|
+
return source;
|
|
21
|
+
}
|
|
22
|
+
// 处理循环引用
|
|
23
|
+
if (map.has(source)) {
|
|
24
|
+
return map.get(source);
|
|
25
|
+
}
|
|
26
|
+
// 处理 ArrayBuffer
|
|
27
|
+
if (source instanceof ArrayBuffer) {
|
|
28
|
+
const copy = new ArrayBuffer(source.byteLength);
|
|
29
|
+
new Uint8Array(copy).set(new Uint8Array(source));
|
|
30
|
+
map.set(source, copy);
|
|
31
|
+
return copy;
|
|
32
|
+
}
|
|
33
|
+
// 处理 DataView 和 TypedArray (Uint8Array 等)
|
|
34
|
+
if (ArrayBuffer.isView(source)) {
|
|
35
|
+
const constructor = source.constructor;
|
|
36
|
+
const bufferCopy = cloneDeep(source.buffer, map);
|
|
37
|
+
return new constructor(bufferCopy, source.byteOffset, source.length);
|
|
38
|
+
}
|
|
39
|
+
// 处理 Date 对象
|
|
40
|
+
if (source instanceof Date) {
|
|
41
|
+
const copy = new Date(source.getTime());
|
|
42
|
+
map.set(source, copy);
|
|
43
|
+
return copy;
|
|
44
|
+
}
|
|
45
|
+
// 处理 RegExp 对象
|
|
46
|
+
if (source instanceof RegExp) {
|
|
47
|
+
const copy = new RegExp(source.source, source.flags);
|
|
48
|
+
copy.lastIndex = source.lastIndex; // 保留匹配状态
|
|
49
|
+
map.set(source, copy);
|
|
50
|
+
return copy;
|
|
51
|
+
}
|
|
52
|
+
// 处理 Map
|
|
53
|
+
if (source instanceof Map) {
|
|
54
|
+
const copy = new Map();
|
|
55
|
+
map.set(source, copy);
|
|
56
|
+
source.forEach((value, key) => {
|
|
57
|
+
copy.set(cloneDeep(key, map), cloneDeep(value, map));
|
|
58
|
+
});
|
|
59
|
+
return copy;
|
|
60
|
+
}
|
|
61
|
+
// 处理 Set
|
|
62
|
+
if (source instanceof Set) {
|
|
63
|
+
const copy = new Set();
|
|
64
|
+
map.set(source, copy);
|
|
65
|
+
source.forEach(value => {
|
|
66
|
+
copy.add(cloneDeep(value, map));
|
|
67
|
+
});
|
|
68
|
+
return copy;
|
|
69
|
+
}
|
|
70
|
+
// 处理数组 (包含稀疏数组)
|
|
71
|
+
if (Array.isArray(source)) {
|
|
72
|
+
const copy = new Array(source.length);
|
|
73
|
+
map.set(source, copy);
|
|
74
|
+
// 克隆所有有效索引
|
|
75
|
+
for (let i = 0, len = source.length; i < len; i++) {
|
|
76
|
+
if (i in source) {
|
|
77
|
+
// 保留空位
|
|
78
|
+
copy[i] = cloneDeep(source[i], map);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// 克隆数组的自定义属性
|
|
82
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
83
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
84
|
+
Object.defineProperty(copy, key, {
|
|
85
|
+
...descriptors[key],
|
|
86
|
+
value: cloneDeep(descriptors[key].value, map)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return copy;
|
|
90
|
+
}
|
|
91
|
+
// 处理普通对象和类实例
|
|
92
|
+
const copy = Object.create(Object.getPrototypeOf(source));
|
|
93
|
+
map.set(source, copy);
|
|
94
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
95
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
96
|
+
const descriptor = descriptors[key];
|
|
97
|
+
if ('value' in descriptor) {
|
|
98
|
+
// 克隆数据属性
|
|
99
|
+
descriptor.value = cloneDeep(descriptor.value, map);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// 处理访问器属性 (getter/setter)
|
|
103
|
+
if (descriptor.get) {
|
|
104
|
+
descriptor.get = cloneDeep(descriptor.get, map);
|
|
105
|
+
}
|
|
106
|
+
if (descriptor.set) {
|
|
107
|
+
descriptor.set = cloneDeep(descriptor.set, map);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
Object.defineProperty(copy, key, descriptor);
|
|
111
|
+
}
|
|
112
|
+
return copy;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { cloneDeep };
|
package/lib/es/cookie.js
CHANGED
package/lib/es/date.js
CHANGED
package/lib/es/dom.js
CHANGED
package/lib/es/download.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.8.
|
|
2
|
+
* sculp-js v1.8.4
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { isFunction } from './type.js';
|
|
7
|
+
import { isFunction, isString, isNullOrUnDef } from './type.js';
|
|
8
8
|
import { urlSetParams } from './url.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -53,17 +53,41 @@ function downloadBlob(blob, filename, callback) {
|
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* 根据URL下载文件(解决跨域a.download不生效问题)
|
|
56
|
+
*
|
|
57
|
+
* 可定制下载成功的状态码status(浏览器原生状态码)
|
|
58
|
+
*
|
|
59
|
+
* 支持下载操作成功、失败后的回调
|
|
56
60
|
* @param {string} url
|
|
57
61
|
* @param {string} filename
|
|
58
|
-
* @param {
|
|
62
|
+
* @param {CrossOriginDownloadParams} options
|
|
59
63
|
*/
|
|
60
|
-
function crossOriginDownload(url, filename,
|
|
64
|
+
function crossOriginDownload(url, filename, options) {
|
|
65
|
+
const { successCode = 200, successCallback, failCallback } = isNullOrUnDef(options) ? { successCode: 200, successCallback: void 0, failCallback: void 0 } : options;
|
|
61
66
|
const xhr = new XMLHttpRequest();
|
|
62
67
|
xhr.open('GET', url, true);
|
|
63
68
|
xhr.responseType = 'blob';
|
|
64
69
|
xhr.onload = function () {
|
|
65
|
-
if (xhr.status ===
|
|
66
|
-
downloadBlob(xhr.response, filename,
|
|
70
|
+
if (xhr.status === successCode)
|
|
71
|
+
downloadBlob(xhr.response, filename, successCallback);
|
|
72
|
+
else if (isFunction(failCallback)) {
|
|
73
|
+
const status = xhr.status;
|
|
74
|
+
const responseType = xhr.getResponseHeader('Content-Type');
|
|
75
|
+
if (isString(responseType) && responseType.includes('application/json')) {
|
|
76
|
+
const reader = new FileReader();
|
|
77
|
+
reader.onload = () => {
|
|
78
|
+
failCallback({ status, response: reader.result });
|
|
79
|
+
};
|
|
80
|
+
reader.readAsText(xhr.response);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
failCallback(xhr);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
xhr.onerror = e => {
|
|
88
|
+
if (isFunction(failCallback)) {
|
|
89
|
+
failCallback({ status: 0, code: 'ERROR_CONNECTION_REFUSED' });
|
|
90
|
+
}
|
|
67
91
|
};
|
|
68
92
|
xhr.send();
|
|
69
93
|
}
|
package/lib/es/easing.js
CHANGED
package/lib/es/file.js
CHANGED