@visactor/vutils-extension 1.10.3 → 1.10.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/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/spec/clone-deep.d.ts +1 -0
- package/cjs/spec/clone-deep.js +27 -0
- package/cjs/spec/clone-deep.js.map +1 -0
- package/cjs/spec/common.d.ts +3 -0
- package/cjs/spec/common.js +23 -0
- package/cjs/spec/common.js.map +1 -0
- package/cjs/spec/index.d.ts +3 -0
- package/cjs/spec/index.js +22 -0
- package/cjs/spec/index.js.map +1 -0
- package/cjs/spec/merge-spec.d.ts +5 -0
- package/cjs/spec/merge-spec.js +69 -0
- package/cjs/spec/merge-spec.js.map +1 -0
- package/cjs/transform/tick-data/discrete/linear.js +1 -2
- package/es/index.d.ts +1 -0
- package/es/index.js +3 -1
- package/es/index.js.map +1 -1
- package/es/spec/clone-deep.d.ts +1 -0
- package/es/spec/clone-deep.js +20 -0
- package/es/spec/clone-deep.js.map +1 -0
- package/es/spec/common.d.ts +3 -0
- package/es/spec/common.js +15 -0
- package/es/spec/common.js.map +1 -0
- package/es/spec/index.d.ts +3 -0
- package/es/spec/index.js +6 -0
- package/es/spec/index.js.map +1 -0
- package/es/spec/merge-spec.d.ts +5 -0
- package/es/spec/merge-spec.js +57 -0
- package/es/spec/merge-spec.js.map +1 -0
- package/es/transform/tick-data/discrete/linear.js +1 -2
- package/package.json +4 -3
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -18,4 +18,4 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", {
|
|
19
19
|
value: !0
|
|
20
20
|
}), __exportStar(require("./transform/tick-data"), exports), __exportStar(require("./utils"), exports),
|
|
21
|
-
__exportStar(require("./algorithm"), exports);
|
|
21
|
+
__exportStar(require("./algorithm"), exports), __exportStar(require("./spec"), exports);
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,0CAAwB;AACxB,8CAA4B","file":"index.js","sourcesContent":["export * from './transform/tick-data';\nexport * from './utils';\nexport * from './algorithm';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,0CAAwB;AACxB,8CAA4B;AAC5B,yCAAuB","file":"index.js","sourcesContent":["export * from './transform/tick-data';\nexport * from './utils';\nexport * from './algorithm';\nexport * from './spec';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cloneDeepSpec(spec: any, excludeKeys?: string[]): any;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.cloneDeepSpec = void 0;
|
|
6
|
+
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), common_1 = require("./common");
|
|
8
|
+
|
|
9
|
+
function cloneDeepSpec(spec, excludeKeys = [ "data" ]) {
|
|
10
|
+
const value = spec;
|
|
11
|
+
let result;
|
|
12
|
+
if (!(0, vutils_1.isValid)(value) || "object" != typeof value) return value;
|
|
13
|
+
if ((0, common_1.isDataView)(value) || (0, common_1.isHTMLElement)(value)) return value;
|
|
14
|
+
const isArr = (0, vutils_1.isArray)(value), length = value.length;
|
|
15
|
+
result = isArr ? new Array(length) : "object" == typeof value ? {} : (0, vutils_1.isBoolean)(value) || (0,
|
|
16
|
+
vutils_1.isNumber)(value) || (0, vutils_1.isString)(value) ? value : (0, vutils_1.isDate)(value) ? new Date(+value) : void 0;
|
|
17
|
+
const props = isArr ? void 0 : Object.keys(Object(value));
|
|
18
|
+
let index = -1;
|
|
19
|
+
if (result) for (;++index < (props || value).length; ) {
|
|
20
|
+
const key = props ? props[index] : index, subValue = value[key];
|
|
21
|
+
(null == excludeKeys ? void 0 : excludeKeys.includes(key.toString())) ? result[key] = subValue : result[key] = cloneDeepSpec(subValue, excludeKeys);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.cloneDeepSpec = cloneDeepSpec;
|
|
27
|
+
//# sourceMappingURL=clone-deep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec/clone-deep.ts"],"names":[],"mappings":";;;AAAA,6CAA2F;AAC3F,qCAAqD;AAMrD,SAAgB,aAAa,CAAC,IAAS,EAAE,cAAwB,CAAC,MAAM,CAAC;IACvE,MAAM,KAAK,GAAG,IAAI,CAAC;IAEnB,IAAI,MAAM,CAAC;IACX,IAAI,CAAC,IAAA,gBAAO,EAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAChD,OAAO,KAAK,CAAC;KACd;IAGD,IAAI,IAAA,mBAAU,EAAC,KAAK,CAAC,IAAI,IAAA,sBAAa,EAAC,KAAK,CAAC,EAAE;QAC7C,OAAO,KAAK,CAAC;KACd;IAED,MAAM,KAAK,GAAG,IAAA,gBAAO,EAAC,KAAK,CAAC,CAAC;IAC7B,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAE5B,IAAI,KAAK,EAAE;QACT,MAAM,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;KAC5B;SAEI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAClC,MAAM,GAAG,EAAE,CAAC;KACb;SAEI,IAAI,IAAA,kBAAS,EAAC,KAAK,CAAC,IAAI,IAAA,iBAAQ,EAAC,KAAK,CAAC,IAAI,IAAA,iBAAQ,EAAC,KAAK,CAAC,EAAE;QAC/D,MAAM,GAAG,KAAK,CAAC;KAChB;SAAM,IAAI,IAAA,eAAM,EAAC,KAAK,CAAC,EAAE;QACxB,MAAM,GAAG,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;KAC3B;SAEI;QACH,MAAM,GAAG,SAAS,CAAC;KACpB;IAKD,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAE7D,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,IAAI,MAAM,EAAE;QACV,OAAO,EAAE,KAAK,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,MAAM,EAAE;YACxC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,EAAE;gBACzC,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;aACxB;iBAAM;gBACL,MAAM,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;aACpD;SACF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AArDD,sCAqDC","file":"clone-deep.js","sourcesContent":["import { isArray, isBoolean, isDate, isNumber, isString, isValid } from '@visactor/vutils';\nimport { isDataView, isHTMLElement } from './common';\n\n/**\n * 深拷贝 spec,为避免循环引用,DataView 维持原有引用\n * @param spec 原spec\n */\nexport function cloneDeepSpec(spec: any, excludeKeys: string[] = ['data']) {\n const value = spec;\n\n let result;\n if (!isValid(value) || typeof value !== 'object') {\n return value;\n }\n\n // 判断是不是不能深拷贝的对象\n if (isDataView(value) || isHTMLElement(value)) {\n return value;\n }\n\n const isArr = isArray(value);\n const length = value.length;\n // 不考虑特殊数组的额外处理\n if (isArr) {\n result = new Array(length);\n }\n // 不考虑 buffer / arguments 类型的处理以及 prototype 的额外处理\n else if (typeof value === 'object') {\n result = {};\n }\n // 不建议使用作为 Boolean / Number / String 作为构造器\n else if (isBoolean(value) || isNumber(value) || isString(value)) {\n result = value;\n } else if (isDate(value)) {\n result = new Date(+value);\n }\n // 不考虑 ArrayBuffer / DataView / TypedArray / map / set / regexp / symbol 类型\n else {\n result = undefined;\n }\n\n // 不考虑 map / set / TypedArray 类型的赋值\n\n // 不考虑对象的 symbol 属性\n const props = isArr ? undefined : Object.keys(Object(value));\n\n let index = -1;\n if (result) {\n while (++index < (props || value).length) {\n const key = props ? props[index] : index;\n const subValue = value[key];\n if (excludeKeys?.includes(key.toString())) {\n result[key] = subValue;\n } else {\n result[key] = cloneDeepSpec(subValue, excludeKeys);\n }\n }\n }\n\n return result;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.isHTMLElement = exports.isDataView = void 0;
|
|
6
|
+
|
|
7
|
+
const vdataset_1 = require("@visactor/vdataset");
|
|
8
|
+
|
|
9
|
+
function isDataView(obj) {
|
|
10
|
+
return obj instanceof vdataset_1.DataView;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isHTMLElement(obj) {
|
|
14
|
+
try {
|
|
15
|
+
return obj instanceof Element;
|
|
16
|
+
} catch (_a) {
|
|
17
|
+
const htmlElementKeys = [ "children", "innerHTML", "classList", "setAttribute", "tagName", "getBoundingClientRect" ], keys = Object.keys(obj);
|
|
18
|
+
return htmlElementKeys.every((key => keys.includes(key)));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.isDataView = isDataView, exports.isHTMLElement = isHTMLElement;
|
|
23
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec/common.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C,SAAgB,UAAU,CAAC,GAAQ;IACjC,OAAO,GAAG,YAAY,mBAAQ,CAAC;AACjC,CAAC;AAFD,gCAEC;AAED,SAAgB,aAAa,CAAC,GAAQ;IACpC,IAAI;QACF,OAAO,GAAG,YAAY,OAAO,CAAC;KAC/B;IAAC,WAAM;QAEN,MAAM,eAAe,GAAsB;YACzC,UAAU;YACV,WAAW;YACX,WAAW;YACX,cAAc;YACd,SAAS;YACT,uBAAuB;SACxB,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;KACzD;AACH,CAAC;AAhBD,sCAgBC","file":"common.js","sourcesContent":["import { DataView } from '@visactor/vdataset';\n\nexport function isDataView(obj: any): obj is DataView {\n return obj instanceof DataView;\n}\n\nexport function isHTMLElement(obj: any): obj is Element {\n try {\n return obj instanceof Element;\n } catch {\n // 跨端 plan B\n const htmlElementKeys: (keyof Element)[] = [\n 'children',\n 'innerHTML',\n 'classList',\n 'setAttribute',\n 'tagName',\n 'getBoundingClientRect'\n ];\n const keys = Object.keys(obj);\n return htmlElementKeys.every(key => keys.includes(key));\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4
|
+
void 0 === k2 && (k2 = k);
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
get: function() {
|
|
9
|
+
return m[k];
|
|
10
|
+
}
|
|
11
|
+
}), Object.defineProperty(o, k2, desc);
|
|
12
|
+
} : function(o, m, k, k2) {
|
|
13
|
+
void 0 === k2 && (k2 = k), o[k2] = m[k];
|
|
14
|
+
}), __exportStar = this && this.__exportStar || function(m, exports) {
|
|
15
|
+
for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(exports, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), __exportStar(require("./clone-deep"), exports), __exportStar(require("./common"), exports),
|
|
21
|
+
__exportStar(require("./merge-spec"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,2CAAyB;AACzB,+CAA6B","file":"index.js","sourcesContent":["export * from './clone-deep';\nexport * from './common';\nexport * from './merge-spec';\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.mergeSpecWithFilter = exports.mergeSpec = void 0;
|
|
6
|
+
|
|
7
|
+
const vutils_1 = require("@visactor/vutils");
|
|
8
|
+
|
|
9
|
+
function baseMerge(target, source, shallowArray = !1) {
|
|
10
|
+
if (source) {
|
|
11
|
+
if (target === source) return;
|
|
12
|
+
if ((0, vutils_1.isValid)(source) && "object" == typeof source) {
|
|
13
|
+
const iterable = Object(source), props = [];
|
|
14
|
+
for (const key in iterable) props.push(key);
|
|
15
|
+
let {length: length} = props, propIndex = -1;
|
|
16
|
+
for (;length--; ) {
|
|
17
|
+
const key = props[++propIndex];
|
|
18
|
+
(0, vutils_1.isValid)(iterable[key]) && "object" == typeof iterable[key] && !(0,
|
|
19
|
+
vutils_1.isArray)(target[key]) ? baseMergeDeep(target, source, key, shallowArray) : assignMergeValue(target, key, iterable[key]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function baseMergeDeep(target, source, key, shallowArray = !1) {
|
|
26
|
+
const objValue = target[key], srcValue = source[key];
|
|
27
|
+
let newValue = source[key], isCommon = !0;
|
|
28
|
+
if ((0, vutils_1.isArray)(srcValue)) {
|
|
29
|
+
if (shallowArray) newValue = []; else if ((0, vutils_1.isArray)(objValue)) newValue = objValue; else if ((0,
|
|
30
|
+
vutils_1.isArrayLike)(objValue)) {
|
|
31
|
+
newValue = new Array(objValue.length);
|
|
32
|
+
let index = -1;
|
|
33
|
+
const length = objValue.length;
|
|
34
|
+
for (;++index < length; ) newValue[index] = objValue[index];
|
|
35
|
+
}
|
|
36
|
+
} else (0, vutils_1.isPlainObject)(srcValue) ? (newValue = null != objValue ? objValue : {},
|
|
37
|
+
"function" != typeof objValue && "object" == typeof objValue || (newValue = {})) : isCommon = !1;
|
|
38
|
+
isCommon && baseMerge(newValue, srcValue, shallowArray), assignMergeValue(target, key, newValue);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function assignMergeValue(target, key, value) {
|
|
42
|
+
(void 0 !== value && !eq(target[key], value) || void 0 === value && !(key in target)) && (target[key] = value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function eq(value, other) {
|
|
46
|
+
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function mergeSpec(target, ...sources) {
|
|
50
|
+
let sourceIndex = -1;
|
|
51
|
+
const length = sources.length;
|
|
52
|
+
for (;++sourceIndex < length; ) {
|
|
53
|
+
baseMerge(target, sources[sourceIndex], !0);
|
|
54
|
+
}
|
|
55
|
+
return target;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function mergeSpecWithFilter(target, filter, spec, forceMerge) {
|
|
59
|
+
Object.keys(target).forEach((k => {
|
|
60
|
+
if ((0, vutils_1.isObject)(filter)) filter.type === k && ((0, vutils_1.isArray)(target[k]) ? target[k].length >= filter.index && (target[k][filter.index] = forceMerge ? mergeSpec({}, target[k][filter.index], spec) : spec) : target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec); else if ((0,
|
|
61
|
+
vutils_1.isArray)(target[k])) {
|
|
62
|
+
const index = target[k].findIndex((_s => _s.id === filter));
|
|
63
|
+
index >= 0 && (target[k][index] = forceMerge ? mergeSpec({}, target[k][index], spec) : spec);
|
|
64
|
+
} else target.id === filter && (target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec);
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.mergeSpec = mergeSpec, exports.mergeSpecWithFilter = mergeSpecWithFilter;
|
|
69
|
+
//# sourceMappingURL=merge-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec/merge-spec.ts"],"names":[],"mappings":";;;AAAA,6CAA0F;AAE1F,SAAS,SAAS,CAAC,MAAW,EAAE,MAAW,EAAE,YAAY,GAAG,KAAK;IAC/D,IAAI,MAAM,EAAE;QACV,IAAI,MAAM,KAAK,MAAM,EAAE;YACrB,OAAO;SACR;QACD,IAAI,IAAA,gBAAO,EAAC,MAAM,CAAC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAEjD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAChC,MAAM,KAAK,GAAG,EAAE,CAAC;YAEjB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;gBAC1B,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACjB;YACD,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;YACvB,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,MAAM,EAAE,EAAE;gBACf,MAAM,GAAG,GAAG,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC/B,IACE,IAAA,gBAAO,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AAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;iBAC9E;aACF;iBAAM,IAAI,MAAM,CAAC,EAAE,KAAK,MAAM,EAAE;gBAC/B,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;aAChE;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AA7BD,kDA6BC","file":"merge-spec.js","sourcesContent":["import { isArray, isArrayLike, isObject, isPlainObject, isValid } from '@visactor/vutils';\n\nfunction baseMerge(target: any, source: any, shallowArray = false) {\n if (source) {\n if (target === source) {\n return;\n }\n if (isValid(source) && typeof source === 'object') {\n // baseFor\n const iterable = Object(source);\n const props = [];\n // keysIn\n for (const key in iterable) {\n props.push(key);\n }\n let { length } = props;\n let propIndex = -1;\n while (length--) {\n const key = props[++propIndex];\n if (\n isValid(iterable[key]) &&\n typeof iterable[key] === 'object' &&\n !isArray(target[key]) // VChart 特有逻辑\n ) {\n baseMergeDeep(target, source, key, shallowArray);\n } else {\n assignMergeValue(target, key, iterable[key]);\n }\n }\n }\n }\n}\n\n// 由于目前 VChart 内部对 spec 会先执行一次深拷贝,merge 暂时不考虑 source 中有环的问题\nfunction baseMergeDeep(target: object, source: object, key: string, shallowArray = false) {\n const objValue = target[key];\n const srcValue = source[key];\n let newValue = source[key];\n let isCommon = true;\n // 不考虑 buffer / typedArray 类型\n if (isArray(srcValue)) {\n if (shallowArray) {\n // 依据参数对数组做浅拷贝\n newValue = [];\n } else if (isArray(objValue)) {\n newValue = objValue;\n } else if (isArrayLike(objValue)) {\n // 如果 source 为数组,则 target 的 arrayLike 对象也视作为数组处理\n newValue = new Array(objValue.length);\n let index = -1;\n const length = objValue.length;\n while (++index < length) {\n newValue[index] = objValue[index];\n }\n }\n }\n // else if (isArray(srcValue) && shallowArray) {\n // newValue = [];\n // }\n // 不考虑 argument 类型\n else if (isPlainObject(srcValue)) {\n newValue = objValue ?? {};\n // 不考虑 prototype 的额外处理\n if (typeof objValue === 'function' || typeof objValue !== 'object') {\n newValue = {};\n }\n } else {\n isCommon = false;\n }\n // 对 class 等复杂对象或者浅拷贝的 array 不做拷贝处理\n if (isCommon) {\n baseMerge(newValue, srcValue, shallowArray);\n }\n assignMergeValue(target, key, newValue);\n}\n\nfunction assignMergeValue(target: object, key: string, value: any) {\n if ((value !== undefined && !eq(target[key], value)) || (value === undefined && !(key in target))) {\n // 不考虑 __proto__ 的赋值处理\n target[key] = value;\n }\n}\n\nfunction eq(value: any, other: any) {\n return value === other || (Number.isNaN(value) && Number.isNaN(other));\n}\n\n/* 与原生的 lodash merge 差异在于对数组是否应用最后一个 source 的结果\n * 以及对一些特殊情况的处理,比如对数组类型 padding 和对象类型的 padding 的 merge\n */\nexport function mergeSpec(target: any, ...sources: any[]): any {\n let sourceIndex = -1;\n const length = sources.length;\n while (++sourceIndex < length) {\n const source = sources[sourceIndex];\n baseMerge(target, source, true);\n }\n return target;\n}\n\nexport function mergeSpecWithFilter(\n target: any,\n filter: string | { type: string; index: number },\n spec: any,\n forceMerge: boolean\n) {\n Object.keys(target).forEach(k => {\n if (isObject(filter)) {\n if (filter.type === k) {\n if (isArray(target[k])) {\n if (target[k].length >= filter.index) {\n target[k][filter.index] = forceMerge ? mergeSpec({}, target[k][filter.index], spec) : spec;\n }\n } else {\n target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec;\n }\n }\n } else {\n // filter === user id\n if (isArray(target[k])) {\n const index = target[k].findIndex((_s: { id: string | number }) => _s.id === filter);\n if (index >= 0) {\n target[k][index] = forceMerge ? mergeSpec({}, target[k][index], spec) : spec;\n }\n } else if (target.id === filter) {\n target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec;\n }\n }\n });\n}\n"]}
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC","file":"index.js","sourcesContent":["export * from './transform/tick-data';\nexport * from './utils';\nexport * from './algorithm';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC","file":"index.js","sourcesContent":["export * from './transform/tick-data';\nexport * from './utils';\nexport * from './algorithm';\nexport * from './spec';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cloneDeepSpec(spec: any, excludeKeys?: string[]): any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isArray, isBoolean, isDate, isNumber, isString, isValid } from "@visactor/vutils";
|
|
2
|
+
|
|
3
|
+
import { isDataView, isHTMLElement } from "./common";
|
|
4
|
+
|
|
5
|
+
export function cloneDeepSpec(spec, excludeKeys = [ "data" ]) {
|
|
6
|
+
const value = spec;
|
|
7
|
+
let result;
|
|
8
|
+
if (!isValid(value) || "object" != typeof value) return value;
|
|
9
|
+
if (isDataView(value) || isHTMLElement(value)) return value;
|
|
10
|
+
const isArr = isArray(value), length = value.length;
|
|
11
|
+
result = isArr ? new Array(length) : "object" == typeof value ? {} : isBoolean(value) || isNumber(value) || isString(value) ? value : isDate(value) ? new Date(+value) : void 0;
|
|
12
|
+
const props = isArr ? void 0 : Object.keys(Object(value));
|
|
13
|
+
let index = -1;
|
|
14
|
+
if (result) for (;++index < (props || value).length; ) {
|
|
15
|
+
const key = props ? props[index] : index, subValue = value[key];
|
|
16
|
+
(null == excludeKeys ? void 0 : excludeKeys.includes(key.toString())) ? result[key] = subValue : result[key] = cloneDeepSpec(subValue, excludeKeys);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
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AAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAE7D,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,IAAI,MAAM,EAAE;QACV,OAAO,EAAE,KAAK,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,MAAM,EAAE;YACxC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,EAAE;gBACzC,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;aACxB;iBAAM;gBACL,MAAM,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;aACpD;SACF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","file":"clone-deep.js","sourcesContent":["import { isArray, isBoolean, isDate, isNumber, isString, isValid } from '@visactor/vutils';\nimport { isDataView, isHTMLElement } from './common';\n\n/**\n * 深拷贝 spec,为避免循环引用,DataView 维持原有引用\n * @param spec 原spec\n */\nexport function cloneDeepSpec(spec: any, excludeKeys: string[] = ['data']) {\n const value = spec;\n\n let result;\n if (!isValid(value) || typeof value !== 'object') {\n return value;\n }\n\n // 判断是不是不能深拷贝的对象\n if (isDataView(value) || isHTMLElement(value)) {\n return value;\n }\n\n const isArr = isArray(value);\n const length = value.length;\n // 不考虑特殊数组的额外处理\n if (isArr) {\n result = new Array(length);\n }\n // 不考虑 buffer / arguments 类型的处理以及 prototype 的额外处理\n else if (typeof value === 'object') {\n result = {};\n }\n // 不建议使用作为 Boolean / Number / String 作为构造器\n else if (isBoolean(value) || isNumber(value) || isString(value)) {\n result = value;\n } else if (isDate(value)) {\n result = new Date(+value);\n }\n // 不考虑 ArrayBuffer / DataView / TypedArray / map / set / regexp / symbol 类型\n else {\n result = undefined;\n }\n\n // 不考虑 map / set / TypedArray 类型的赋值\n\n // 不考虑对象的 symbol 属性\n const props = isArr ? undefined : Object.keys(Object(value));\n\n let index = -1;\n if (result) {\n while (++index < (props || value).length) {\n const key = props ? props[index] : index;\n const subValue = value[key];\n if (excludeKeys?.includes(key.toString())) {\n result[key] = subValue;\n } else {\n result[key] = cloneDeepSpec(subValue, excludeKeys);\n }\n }\n }\n\n return result;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataView } from "@visactor/vdataset";
|
|
2
|
+
|
|
3
|
+
export function isDataView(obj) {
|
|
4
|
+
return obj instanceof DataView;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function isHTMLElement(obj) {
|
|
8
|
+
try {
|
|
9
|
+
return obj instanceof Element;
|
|
10
|
+
} catch (_a) {
|
|
11
|
+
const htmlElementKeys = [ "children", "innerHTML", "classList", "setAttribute", "tagName", "getBoundingClientRect" ], keys = Object.keys(obj);
|
|
12
|
+
return htmlElementKeys.every((key => keys.includes(key)));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,OAAO,GAAG,YAAY,QAAQ,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAQ;IACpC,IAAI;QACF,OAAO,GAAG,YAAY,OAAO,CAAC;KAC/B;IAAC,WAAM;QAEN,MAAM,eAAe,GAAsB;YACzC,UAAU;YACV,WAAW;YACX,WAAW;YACX,cAAc;YACd,SAAS;YACT,uBAAuB;SACxB,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;KACzD;AACH,CAAC","file":"common.js","sourcesContent":["import { DataView } from '@visactor/vdataset';\n\nexport function isDataView(obj: any): obj is DataView {\n return obj instanceof DataView;\n}\n\nexport function isHTMLElement(obj: any): obj is Element {\n try {\n return obj instanceof Element;\n } catch {\n // 跨端 plan B\n const htmlElementKeys: (keyof Element)[] = [\n 'children',\n 'innerHTML',\n 'classList',\n 'setAttribute',\n 'tagName',\n 'getBoundingClientRect'\n ];\n const keys = Object.keys(obj);\n return htmlElementKeys.every(key => keys.includes(key));\n }\n}\n"]}
|
package/es/spec/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC","file":"index.js","sourcesContent":["export * from './clone-deep';\nexport * from './common';\nexport * from './merge-spec';\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isArray, isArrayLike, isObject, isPlainObject, isValid } from "@visactor/vutils";
|
|
2
|
+
|
|
3
|
+
function baseMerge(target, source, shallowArray = !1) {
|
|
4
|
+
if (source) {
|
|
5
|
+
if (target === source) return;
|
|
6
|
+
if (isValid(source) && "object" == typeof source) {
|
|
7
|
+
const iterable = Object(source), props = [];
|
|
8
|
+
for (const key in iterable) props.push(key);
|
|
9
|
+
let {length: length} = props, propIndex = -1;
|
|
10
|
+
for (;length--; ) {
|
|
11
|
+
const key = props[++propIndex];
|
|
12
|
+
isValid(iterable[key]) && "object" == typeof iterable[key] && !isArray(target[key]) ? baseMergeDeep(target, source, key, shallowArray) : assignMergeValue(target, key, iterable[key]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function baseMergeDeep(target, source, key, shallowArray = !1) {
|
|
19
|
+
const objValue = target[key], srcValue = source[key];
|
|
20
|
+
let newValue = source[key], isCommon = !0;
|
|
21
|
+
if (isArray(srcValue)) {
|
|
22
|
+
if (shallowArray) newValue = []; else if (isArray(objValue)) newValue = objValue; else if (isArrayLike(objValue)) {
|
|
23
|
+
newValue = new Array(objValue.length);
|
|
24
|
+
let index = -1;
|
|
25
|
+
const length = objValue.length;
|
|
26
|
+
for (;++index < length; ) newValue[index] = objValue[index];
|
|
27
|
+
}
|
|
28
|
+
} else isPlainObject(srcValue) ? (newValue = null != objValue ? objValue : {}, "function" != typeof objValue && "object" == typeof objValue || (newValue = {})) : isCommon = !1;
|
|
29
|
+
isCommon && baseMerge(newValue, srcValue, shallowArray), assignMergeValue(target, key, newValue);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function assignMergeValue(target, key, value) {
|
|
33
|
+
(void 0 !== value && !eq(target[key], value) || void 0 === value && !(key in target)) && (target[key] = value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function eq(value, other) {
|
|
37
|
+
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function mergeSpec(target, ...sources) {
|
|
41
|
+
let sourceIndex = -1;
|
|
42
|
+
const length = sources.length;
|
|
43
|
+
for (;++sourceIndex < length; ) {
|
|
44
|
+
baseMerge(target, sources[sourceIndex], !0);
|
|
45
|
+
}
|
|
46
|
+
return target;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function mergeSpecWithFilter(target, filter, spec, forceMerge) {
|
|
50
|
+
Object.keys(target).forEach((k => {
|
|
51
|
+
if (isObject(filter)) filter.type === k && (isArray(target[k]) ? target[k].length >= filter.index && (target[k][filter.index] = forceMerge ? mergeSpec({}, target[k][filter.index], spec) : spec) : target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec); else if (isArray(target[k])) {
|
|
52
|
+
const index = target[k].findIndex((_s => _s.id === filter));
|
|
53
|
+
index >= 0 && (target[k][index] = forceMerge ? mergeSpec({}, target[k][index], spec) : spec);
|
|
54
|
+
} else target.id === filter && (target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec);
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=merge-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spec/merge-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE1F,SAAS,SAAS,CAAC,MAAW,EAAE,MAAW,EAAE,YAAY,GAAG,KAAK;IAC/D,IAAI,MAAM,EAAE;QACV,IAAI,MAAM,KAAK,MAAM,EAAE;YACrB,OAAO;SACR;QACD,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAEjD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAChC,MAAM,KAAK,GAAG,EAAE,CAAC;YAEjB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;gBAC1B,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACjB;YACD,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;YACvB,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,MAAM,EAAE,EAAE;gBACf,MAAM,GAAG,GAAG,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC/B,IACE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;oBACtB,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,QAAQ;oBACjC,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EACrB;oBACA,aAAa,CAAC,MAA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CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;aAChE;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC","file":"merge-spec.js","sourcesContent":["import { isArray, isArrayLike, isObject, isPlainObject, isValid } from '@visactor/vutils';\n\nfunction baseMerge(target: any, source: any, shallowArray = false) {\n if (source) {\n if (target === source) {\n return;\n }\n if (isValid(source) && typeof source === 'object') {\n // baseFor\n const iterable = Object(source);\n const props = [];\n // keysIn\n for (const key in iterable) {\n props.push(key);\n }\n let { length } = props;\n let propIndex = -1;\n while (length--) {\n const key = props[++propIndex];\n if (\n isValid(iterable[key]) &&\n typeof iterable[key] === 'object' &&\n !isArray(target[key]) // VChart 特有逻辑\n ) {\n baseMergeDeep(target, source, key, shallowArray);\n } else {\n assignMergeValue(target, key, iterable[key]);\n }\n }\n }\n }\n}\n\n// 由于目前 VChart 内部对 spec 会先执行一次深拷贝,merge 暂时不考虑 source 中有环的问题\nfunction baseMergeDeep(target: object, source: object, key: string, shallowArray = false) {\n const objValue = target[key];\n const srcValue = source[key];\n let newValue = source[key];\n let isCommon = true;\n // 不考虑 buffer / typedArray 类型\n if (isArray(srcValue)) {\n if (shallowArray) {\n // 依据参数对数组做浅拷贝\n newValue = [];\n } else if (isArray(objValue)) {\n newValue = objValue;\n } else if (isArrayLike(objValue)) {\n // 如果 source 为数组,则 target 的 arrayLike 对象也视作为数组处理\n newValue = new Array(objValue.length);\n let index = -1;\n const length = objValue.length;\n while (++index < length) {\n newValue[index] = objValue[index];\n }\n }\n }\n // else if (isArray(srcValue) && shallowArray) {\n // newValue = [];\n // }\n // 不考虑 argument 类型\n else if (isPlainObject(srcValue)) {\n newValue = objValue ?? {};\n // 不考虑 prototype 的额外处理\n if (typeof objValue === 'function' || typeof objValue !== 'object') {\n newValue = {};\n }\n } else {\n isCommon = false;\n }\n // 对 class 等复杂对象或者浅拷贝的 array 不做拷贝处理\n if (isCommon) {\n baseMerge(newValue, srcValue, shallowArray);\n }\n assignMergeValue(target, key, newValue);\n}\n\nfunction assignMergeValue(target: object, key: string, value: any) {\n if ((value !== undefined && !eq(target[key], value)) || (value === undefined && !(key in target))) {\n // 不考虑 __proto__ 的赋值处理\n target[key] = value;\n }\n}\n\nfunction eq(value: any, other: any) {\n return value === other || (Number.isNaN(value) && Number.isNaN(other));\n}\n\n/* 与原生的 lodash merge 差异在于对数组是否应用最后一个 source 的结果\n * 以及对一些特殊情况的处理,比如对数组类型 padding 和对象类型的 padding 的 merge\n */\nexport function mergeSpec(target: any, ...sources: any[]): any {\n let sourceIndex = -1;\n const length = sources.length;\n while (++sourceIndex < length) {\n const source = sources[sourceIndex];\n baseMerge(target, source, true);\n }\n return target;\n}\n\nexport function mergeSpecWithFilter(\n target: any,\n filter: string | { type: string; index: number },\n spec: any,\n forceMerge: boolean\n) {\n Object.keys(target).forEach(k => {\n if (isObject(filter)) {\n if (filter.type === k) {\n if (isArray(target[k])) {\n if (target[k].length >= filter.index) {\n target[k][filter.index] = forceMerge ? mergeSpec({}, target[k][filter.index], spec) : spec;\n }\n } else {\n target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec;\n }\n }\n } else {\n // filter === user id\n if (isArray(target[k])) {\n const index = target[k].findIndex((_s: { id: string | number }) => _s.id === filter);\n if (index >= 0) {\n target[k][index] = forceMerge ? mergeSpec({}, target[k][index], spec) : spec;\n }\n } else if (target.id === filter) {\n target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec;\n }\n }\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vutils-extension",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.4",
|
|
4
4
|
"description": "The extension module for VUtil from VisActor",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "cjs/index.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@visactor/vutils": "~0.18.1",
|
|
16
|
+
"@visactor/vdataset": "~0.18.1",
|
|
16
17
|
"@visactor/vscale": "~0.18.1",
|
|
17
18
|
"@visactor/vrender-core": "0.18.8",
|
|
18
19
|
"@visactor/vrender-kits": "0.18.8",
|
|
@@ -38,9 +39,9 @@
|
|
|
38
39
|
"ts-node": "10.9.0",
|
|
39
40
|
"tslib": "2.3.1",
|
|
40
41
|
"tslint": "5.12.1",
|
|
41
|
-
"@internal/
|
|
42
|
+
"@internal/bundler": "0.0.1",
|
|
42
43
|
"@internal/ts-config": "0.0.1",
|
|
43
|
-
"@internal/
|
|
44
|
+
"@internal/eslint-config": "0.0.1"
|
|
44
45
|
},
|
|
45
46
|
"publishConfig": {
|
|
46
47
|
"access": "public"
|