@domql/utils 2.3.53 → 2.3.57
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/dist/cjs/array.js +1 -0
- package/dist/cjs/function.js +46 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/log.js +35 -0
- package/dist/cjs/node.js +35 -0
- package/dist/cjs/object.js +258 -0
- package/dist/cjs/package-cjs.json +4 -0
- package/dist/cjs/types.js +92 -0
- package/dist/esm/array.js +0 -0
- package/dist/esm/function.js +26 -0
- package/dist/esm/log.js +15 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +238 -0
- package/dist/esm/types.js +72 -0
- package/dist/iife/array.js +3 -0
- package/dist/iife/function.js +25 -0
- package/dist/iife/index.js +23 -0
- package/dist/iife/log.js +14 -0
- package/dist/iife/node.js +13 -0
- package/dist/iife/object.js +220 -0
- package/dist/iife/types.js +57 -0
- package/package.json +6 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var function_exports = {};
|
|
20
|
+
__export(function_exports, {
|
|
21
|
+
debounce: () => debounce,
|
|
22
|
+
memoize: () => memoize
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(function_exports);
|
|
25
|
+
const debounce = (element, func, timeout = 300) => {
|
|
26
|
+
let timer;
|
|
27
|
+
return (...args) => {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
timer = setTimeout(() => {
|
|
30
|
+
func.apply(element, args);
|
|
31
|
+
}, timeout);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const memoize = (fn) => {
|
|
35
|
+
const cache = {};
|
|
36
|
+
return (...args) => {
|
|
37
|
+
const n = args[0];
|
|
38
|
+
if (n in cache) {
|
|
39
|
+
return cache[n];
|
|
40
|
+
} else {
|
|
41
|
+
const result = fn(n);
|
|
42
|
+
cache[n] = result;
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var utils_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(utils_exports);
|
|
18
|
+
__reExport(utils_exports, require("./types.js"), module.exports);
|
|
19
|
+
__reExport(utils_exports, require("./object.js"), module.exports);
|
|
20
|
+
__reExport(utils_exports, require("./function.js"), module.exports);
|
|
21
|
+
__reExport(utils_exports, require("./array.js"), module.exports);
|
|
22
|
+
__reExport(utils_exports, require("./node.js"), module.exports);
|
|
23
|
+
__reExport(utils_exports, require("./log.js"), module.exports);
|
package/dist/cjs/log.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var log_exports = {};
|
|
20
|
+
__export(log_exports, {
|
|
21
|
+
logGroupIf: () => logGroupIf,
|
|
22
|
+
logIf: () => logIf
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(log_exports);
|
|
25
|
+
const logIf = (bool, ...arg) => {
|
|
26
|
+
if (bool)
|
|
27
|
+
arg.map((v) => console.log(v));
|
|
28
|
+
};
|
|
29
|
+
const logGroupIf = (bool, key, ...arg) => {
|
|
30
|
+
if (bool) {
|
|
31
|
+
console.group(key);
|
|
32
|
+
arg.map((v) => console.log(v));
|
|
33
|
+
console.groupEnd(key);
|
|
34
|
+
}
|
|
35
|
+
};
|
package/dist/cjs/node.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var node_exports = {};
|
|
20
|
+
__export(node_exports, {
|
|
21
|
+
cleanWithNode: () => cleanWithNode,
|
|
22
|
+
createID: () => createID,
|
|
23
|
+
createSnapshotId: () => createSnapshotId
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(node_exports);
|
|
26
|
+
const cleanWithNode = (extend) => delete extend.node && extend;
|
|
27
|
+
const createID = function() {
|
|
28
|
+
let index = 0;
|
|
29
|
+
function newId() {
|
|
30
|
+
index++;
|
|
31
|
+
return index;
|
|
32
|
+
}
|
|
33
|
+
return newId;
|
|
34
|
+
}();
|
|
35
|
+
const createSnapshotId = createID;
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var object_exports = {};
|
|
20
|
+
__export(object_exports, {
|
|
21
|
+
clone: () => clone,
|
|
22
|
+
deepClone: () => deepClone,
|
|
23
|
+
deepCloneExclude: () => deepCloneExclude,
|
|
24
|
+
deepDestringify: () => deepDestringify,
|
|
25
|
+
deepMerge: () => deepMerge,
|
|
26
|
+
deepStringify: () => deepStringify,
|
|
27
|
+
diff: () => diff,
|
|
28
|
+
exec: () => exec,
|
|
29
|
+
flattenRecursive: () => flattenRecursive,
|
|
30
|
+
isEqualDeep: () => isEqualDeep,
|
|
31
|
+
map: () => map,
|
|
32
|
+
merge: () => merge,
|
|
33
|
+
mergeAndCloneIfArray: () => mergeAndCloneIfArray,
|
|
34
|
+
mergeArray: () => mergeArray,
|
|
35
|
+
mergeArrayExclude: () => mergeArrayExclude,
|
|
36
|
+
mergeIfExisted: () => mergeIfExisted,
|
|
37
|
+
overwrite: () => overwrite,
|
|
38
|
+
overwriteDeep: () => overwriteDeep,
|
|
39
|
+
overwriteObj: () => overwriteObj
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(object_exports);
|
|
42
|
+
var import_types = require("./types.js");
|
|
43
|
+
const exec = (param, element, state) => {
|
|
44
|
+
if ((0, import_types.isFunction)(param))
|
|
45
|
+
return param(element, state || element.state);
|
|
46
|
+
return param;
|
|
47
|
+
};
|
|
48
|
+
const map = (obj2, extention, element) => {
|
|
49
|
+
for (const e in extention) {
|
|
50
|
+
obj2[e] = exec(extention[e], element);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const merge = (element, obj2) => {
|
|
54
|
+
for (const e in obj2) {
|
|
55
|
+
const elementProp = element[e];
|
|
56
|
+
const objProp2 = obj2[e];
|
|
57
|
+
if (elementProp === void 0) {
|
|
58
|
+
element[e] = objProp2;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return element;
|
|
62
|
+
};
|
|
63
|
+
const deepMerge = (element, extend) => {
|
|
64
|
+
for (const e in extend) {
|
|
65
|
+
const elementProp = element[e];
|
|
66
|
+
const extendProp = extend[e];
|
|
67
|
+
if (e === "parent" || e === "props")
|
|
68
|
+
continue;
|
|
69
|
+
if (elementProp === void 0) {
|
|
70
|
+
element[e] = extendProp;
|
|
71
|
+
} else if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObject)(extendProp)) {
|
|
72
|
+
deepMerge(elementProp, extendProp);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return element;
|
|
76
|
+
};
|
|
77
|
+
const clone = (obj2) => {
|
|
78
|
+
const o = {};
|
|
79
|
+
for (const prop2 in obj2) {
|
|
80
|
+
if (prop2 === "node")
|
|
81
|
+
continue;
|
|
82
|
+
o[prop2] = obj2[prop2];
|
|
83
|
+
}
|
|
84
|
+
return o;
|
|
85
|
+
};
|
|
86
|
+
const deepCloneExclude = (obj2, exclude = []) => {
|
|
87
|
+
if ((0, import_types.isArray)(obj2)) {
|
|
88
|
+
return obj2.map((x) => deepCloneExclude(x, exclude));
|
|
89
|
+
}
|
|
90
|
+
const o = {};
|
|
91
|
+
for (const k in obj2) {
|
|
92
|
+
if (exclude.indexOf(k) > -1)
|
|
93
|
+
continue;
|
|
94
|
+
let v = obj2[k];
|
|
95
|
+
if (k === "extend" && (0, import_types.isArray)(v)) {
|
|
96
|
+
v = mergeArrayExclude(v, exclude);
|
|
97
|
+
}
|
|
98
|
+
if ((0, import_types.isArray)(v)) {
|
|
99
|
+
o[k] = v.map((x) => deepCloneExclude(x, exclude));
|
|
100
|
+
} else if ((0, import_types.isObject)(v)) {
|
|
101
|
+
o[k] = deepCloneExclude(v, exclude);
|
|
102
|
+
} else
|
|
103
|
+
o[k] = v;
|
|
104
|
+
}
|
|
105
|
+
return o;
|
|
106
|
+
};
|
|
107
|
+
const mergeArrayExclude = (arr, excl = []) => {
|
|
108
|
+
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
109
|
+
};
|
|
110
|
+
const deepClone = (obj2) => {
|
|
111
|
+
if ((0, import_types.isArray)(obj2)) {
|
|
112
|
+
return obj2.map(deepClone);
|
|
113
|
+
}
|
|
114
|
+
const o = {};
|
|
115
|
+
for (const prop2 in obj2) {
|
|
116
|
+
let objProp2 = obj2[prop2];
|
|
117
|
+
if (prop2 === "extend" && (0, import_types.isArray)(objProp2)) {
|
|
118
|
+
objProp2 = mergeArray(objProp2);
|
|
119
|
+
}
|
|
120
|
+
if ((0, import_types.isArray)(objProp2)) {
|
|
121
|
+
o[prop2] = objProp2.map((v) => (0, import_types.isObject)(v) ? deepClone(v) : v);
|
|
122
|
+
} else if ((0, import_types.isObject)(objProp2)) {
|
|
123
|
+
o[prop2] = deepClone(objProp2);
|
|
124
|
+
} else
|
|
125
|
+
o[prop2] = objProp2;
|
|
126
|
+
}
|
|
127
|
+
return o;
|
|
128
|
+
};
|
|
129
|
+
const deepStringify = (obj2, stringified2 = {}) => {
|
|
130
|
+
for (const prop2 in obj2) {
|
|
131
|
+
const objProp2 = obj2[prop2];
|
|
132
|
+
if ((0, import_types.isFunction)(objProp2)) {
|
|
133
|
+
stringified2[prop2] = objProp2.toString();
|
|
134
|
+
} else if ((0, import_types.isObject)(objProp2)) {
|
|
135
|
+
stringified2[prop2] = {};
|
|
136
|
+
deepStringify(objProp2[prop2], stringified2[prop2]);
|
|
137
|
+
} else if ((0, import_types.isArray)(objProp2)) {
|
|
138
|
+
stringified2[prop2] = [];
|
|
139
|
+
objProp2.map((v, i) => deepStringify(v, stringified2[prop2][i]));
|
|
140
|
+
} else
|
|
141
|
+
stringified2[prop2] = objProp2;
|
|
142
|
+
}
|
|
143
|
+
return stringified2;
|
|
144
|
+
};
|
|
145
|
+
const deepDestringify = (obj, stringified = {}) => {
|
|
146
|
+
for (const prop in obj) {
|
|
147
|
+
const objProp = obj[prop];
|
|
148
|
+
if ((0, import_types.isString)(objProp)) {
|
|
149
|
+
if (objProp.includes("=>") || objProp.includes("function") || objProp[0] === "(") {
|
|
150
|
+
try {
|
|
151
|
+
const evalProp = eval(objProp);
|
|
152
|
+
stringified[prop] = evalProp;
|
|
153
|
+
} catch (e) {
|
|
154
|
+
if (e)
|
|
155
|
+
stringified[prop] = objProp;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} else
|
|
159
|
+
stringified[prop] = objProp;
|
|
160
|
+
if ((0, import_types.isObject)(objProp))
|
|
161
|
+
deepDestringify(stringified[prop], stringified[prop]);
|
|
162
|
+
}
|
|
163
|
+
return stringified;
|
|
164
|
+
};
|
|
165
|
+
const overwrite = (element, params, options) => {
|
|
166
|
+
const { ref } = element;
|
|
167
|
+
const changes = {};
|
|
168
|
+
for (const e in params) {
|
|
169
|
+
if (e === "props")
|
|
170
|
+
continue;
|
|
171
|
+
const elementProp = element[e];
|
|
172
|
+
const paramsProp = params[e];
|
|
173
|
+
if (paramsProp) {
|
|
174
|
+
ref.__cache[e] = changes[e] = elementProp;
|
|
175
|
+
ref[e] = paramsProp;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return changes;
|
|
179
|
+
};
|
|
180
|
+
const diff = (obj2, original, cache) => {
|
|
181
|
+
const changes = cache || {};
|
|
182
|
+
for (const e in obj2) {
|
|
183
|
+
if (e === "ref")
|
|
184
|
+
continue;
|
|
185
|
+
const originalProp = original[e];
|
|
186
|
+
const objProp2 = obj2[e];
|
|
187
|
+
if ((0, import_types.isObjectLike)(originalProp) && (0, import_types.isObjectLike)(objProp2)) {
|
|
188
|
+
changes[e] = {};
|
|
189
|
+
diff(originalProp, objProp2, changes[e]);
|
|
190
|
+
} else if (objProp2 !== void 0) {
|
|
191
|
+
changes[e] = objProp2;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return changes;
|
|
195
|
+
};
|
|
196
|
+
const overwriteObj = (params, obj2) => {
|
|
197
|
+
const changes = {};
|
|
198
|
+
for (const e in params) {
|
|
199
|
+
const objProp2 = obj2[e];
|
|
200
|
+
const paramsProp = params[e];
|
|
201
|
+
if (paramsProp) {
|
|
202
|
+
obj2[e] = changes[e] = objProp2;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return changes;
|
|
206
|
+
};
|
|
207
|
+
const overwriteDeep = (params, obj2) => {
|
|
208
|
+
for (const e in params) {
|
|
209
|
+
const objProp2 = obj2[e];
|
|
210
|
+
const paramsProp = params[e];
|
|
211
|
+
if ((0, import_types.isObjectLike)(objProp2) && (0, import_types.isObjectLike)(paramsProp)) {
|
|
212
|
+
overwriteDeep(objProp2, paramsProp);
|
|
213
|
+
} else if (paramsProp !== void 0) {
|
|
214
|
+
obj2[e] = paramsProp;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return obj2;
|
|
218
|
+
};
|
|
219
|
+
const mergeIfExisted = (a, b) => {
|
|
220
|
+
if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b))
|
|
221
|
+
return deepMerge(a, b);
|
|
222
|
+
return a || b;
|
|
223
|
+
};
|
|
224
|
+
const mergeArray = (arr) => {
|
|
225
|
+
return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {});
|
|
226
|
+
};
|
|
227
|
+
const mergeAndCloneIfArray = (obj2) => {
|
|
228
|
+
return (0, import_types.isArray)(obj2) ? mergeArray(obj2) : deepClone(obj2);
|
|
229
|
+
};
|
|
230
|
+
const flattenRecursive = (param, prop2, stack = []) => {
|
|
231
|
+
const objectized = mergeAndCloneIfArray(param);
|
|
232
|
+
stack.push(objectized);
|
|
233
|
+
const extendOfExtend = objectized[prop2];
|
|
234
|
+
if (extendOfExtend)
|
|
235
|
+
flattenRecursive(extendOfExtend, prop2, stack);
|
|
236
|
+
delete objectized[prop2];
|
|
237
|
+
return stack;
|
|
238
|
+
};
|
|
239
|
+
const isEqualDeep = (param, element) => {
|
|
240
|
+
if (param === element)
|
|
241
|
+
return true;
|
|
242
|
+
if (!param || !element)
|
|
243
|
+
return false;
|
|
244
|
+
for (const prop2 in param) {
|
|
245
|
+
const paramProp = param[prop2];
|
|
246
|
+
const elementProp = element[prop2];
|
|
247
|
+
if ((0, import_types.isObjectLike)(paramProp)) {
|
|
248
|
+
const isEqual = isEqualDeep(paramProp, elementProp);
|
|
249
|
+
if (!isEqual)
|
|
250
|
+
return false;
|
|
251
|
+
} else {
|
|
252
|
+
const isEqual = paramProp === elementProp;
|
|
253
|
+
if (!isEqual)
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return true;
|
|
258
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var types_exports = {};
|
|
20
|
+
__export(types_exports, {
|
|
21
|
+
TYPES: () => TYPES,
|
|
22
|
+
is: () => is,
|
|
23
|
+
isArray: () => isArray,
|
|
24
|
+
isBoolean: () => isBoolean,
|
|
25
|
+
isDefined: () => isDefined,
|
|
26
|
+
isFunction: () => isFunction,
|
|
27
|
+
isHtmlElement: () => isHtmlElement,
|
|
28
|
+
isNode: () => isNode,
|
|
29
|
+
isNot: () => isNot,
|
|
30
|
+
isNull: () => isNull,
|
|
31
|
+
isNumber: () => isNumber,
|
|
32
|
+
isObject: () => isObject,
|
|
33
|
+
isObjectLike: () => isObjectLike,
|
|
34
|
+
isString: () => isString,
|
|
35
|
+
isUndefined: () => isUndefined,
|
|
36
|
+
isValidHtmlTag: () => isValidHtmlTag
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(types_exports);
|
|
39
|
+
var import_globals = require("@domql/globals");
|
|
40
|
+
var import_tags = require("@domql/tags");
|
|
41
|
+
const isValidHtmlTag = (arg) => import_tags.HTML_TAGS.body.indexOf(arg);
|
|
42
|
+
const isObject = (arg) => {
|
|
43
|
+
if (arg === null)
|
|
44
|
+
return false;
|
|
45
|
+
return typeof arg === "object" && arg.constructor === Object;
|
|
46
|
+
};
|
|
47
|
+
const isString = (arg) => typeof arg === "string";
|
|
48
|
+
const isNumber = (arg) => typeof arg === "number";
|
|
49
|
+
const isFunction = (arg) => typeof arg === "function";
|
|
50
|
+
const isBoolean = (arg) => arg === true || arg === false;
|
|
51
|
+
const isNull = (arg) => arg === null;
|
|
52
|
+
const isArray = (arg) => Array.isArray(arg);
|
|
53
|
+
const isObjectLike = (arg) => {
|
|
54
|
+
if (arg === null)
|
|
55
|
+
return false;
|
|
56
|
+
return typeof arg === "object";
|
|
57
|
+
};
|
|
58
|
+
const isNode = (obj) => {
|
|
59
|
+
return typeof import_globals.window.Node === "object" ? obj instanceof import_globals.window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string";
|
|
60
|
+
};
|
|
61
|
+
const isHtmlElement = (obj) => {
|
|
62
|
+
return typeof import_globals.window.HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string";
|
|
63
|
+
};
|
|
64
|
+
const isDefined = (arg) => {
|
|
65
|
+
return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isNull(arg);
|
|
66
|
+
};
|
|
67
|
+
const isUndefined = (arg) => {
|
|
68
|
+
return arg === void 0;
|
|
69
|
+
};
|
|
70
|
+
const TYPES = {
|
|
71
|
+
boolean: isBoolean,
|
|
72
|
+
array: isArray,
|
|
73
|
+
object: isObject,
|
|
74
|
+
string: isString,
|
|
75
|
+
number: isNumber,
|
|
76
|
+
null: isNull,
|
|
77
|
+
function: isFunction,
|
|
78
|
+
objectLike: isObjectLike,
|
|
79
|
+
node: isNode,
|
|
80
|
+
htmlElement: isHtmlElement,
|
|
81
|
+
defined: isDefined
|
|
82
|
+
};
|
|
83
|
+
const is = (arg) => {
|
|
84
|
+
return (...args) => {
|
|
85
|
+
return args.map((val) => TYPES[val](arg)).filter((v) => v).length > 0;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const isNot = (arg) => {
|
|
89
|
+
return (...args) => {
|
|
90
|
+
return args.map((val) => TYPES[val](arg)).filter((v) => v).length === 0;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const debounce = (element, func, timeout = 300) => {
|
|
2
|
+
let timer;
|
|
3
|
+
return (...args) => {
|
|
4
|
+
clearTimeout(timer);
|
|
5
|
+
timer = setTimeout(() => {
|
|
6
|
+
func.apply(element, args);
|
|
7
|
+
}, timeout);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const memoize = (fn) => {
|
|
11
|
+
const cache = {};
|
|
12
|
+
return (...args) => {
|
|
13
|
+
const n = args[0];
|
|
14
|
+
if (n in cache) {
|
|
15
|
+
return cache[n];
|
|
16
|
+
} else {
|
|
17
|
+
const result = fn(n);
|
|
18
|
+
cache[n] = result;
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
debounce,
|
|
25
|
+
memoize
|
|
26
|
+
};
|
package/dist/esm/log.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const logIf = (bool, ...arg) => {
|
|
2
|
+
if (bool)
|
|
3
|
+
arg.map((v) => console.log(v));
|
|
4
|
+
};
|
|
5
|
+
const logGroupIf = (bool, key, ...arg) => {
|
|
6
|
+
if (bool) {
|
|
7
|
+
console.group(key);
|
|
8
|
+
arg.map((v) => console.log(v));
|
|
9
|
+
console.groupEnd(key);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
logGroupIf,
|
|
14
|
+
logIf
|
|
15
|
+
};
|
package/dist/esm/node.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const cleanWithNode = (extend) => delete extend.node && extend;
|
|
2
|
+
const createID = function() {
|
|
3
|
+
let index = 0;
|
|
4
|
+
function newId() {
|
|
5
|
+
index++;
|
|
6
|
+
return index;
|
|
7
|
+
}
|
|
8
|
+
return newId;
|
|
9
|
+
}();
|
|
10
|
+
const createSnapshotId = createID;
|
|
11
|
+
export {
|
|
12
|
+
cleanWithNode,
|
|
13
|
+
createID,
|
|
14
|
+
createSnapshotId
|
|
15
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { isFunction, isObjectLike, isObject, isArray, isString } from "./types.js";
|
|
2
|
+
const exec = (param, element, state) => {
|
|
3
|
+
if (isFunction(param))
|
|
4
|
+
return param(element, state || element.state);
|
|
5
|
+
return param;
|
|
6
|
+
};
|
|
7
|
+
const map = (obj2, extention, element) => {
|
|
8
|
+
for (const e in extention) {
|
|
9
|
+
obj2[e] = exec(extention[e], element);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const merge = (element, obj2) => {
|
|
13
|
+
for (const e in obj2) {
|
|
14
|
+
const elementProp = element[e];
|
|
15
|
+
const objProp2 = obj2[e];
|
|
16
|
+
if (elementProp === void 0) {
|
|
17
|
+
element[e] = objProp2;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return element;
|
|
21
|
+
};
|
|
22
|
+
const deepMerge = (element, extend) => {
|
|
23
|
+
for (const e in extend) {
|
|
24
|
+
const elementProp = element[e];
|
|
25
|
+
const extendProp = extend[e];
|
|
26
|
+
if (e === "parent" || e === "props")
|
|
27
|
+
continue;
|
|
28
|
+
if (elementProp === void 0) {
|
|
29
|
+
element[e] = extendProp;
|
|
30
|
+
} else if (isObjectLike(elementProp) && isObject(extendProp)) {
|
|
31
|
+
deepMerge(elementProp, extendProp);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return element;
|
|
35
|
+
};
|
|
36
|
+
const clone = (obj2) => {
|
|
37
|
+
const o = {};
|
|
38
|
+
for (const prop2 in obj2) {
|
|
39
|
+
if (prop2 === "node")
|
|
40
|
+
continue;
|
|
41
|
+
o[prop2] = obj2[prop2];
|
|
42
|
+
}
|
|
43
|
+
return o;
|
|
44
|
+
};
|
|
45
|
+
const deepCloneExclude = (obj2, exclude = []) => {
|
|
46
|
+
if (isArray(obj2)) {
|
|
47
|
+
return obj2.map((x) => deepCloneExclude(x, exclude));
|
|
48
|
+
}
|
|
49
|
+
const o = {};
|
|
50
|
+
for (const k in obj2) {
|
|
51
|
+
if (exclude.indexOf(k) > -1)
|
|
52
|
+
continue;
|
|
53
|
+
let v = obj2[k];
|
|
54
|
+
if (k === "extend" && isArray(v)) {
|
|
55
|
+
v = mergeArrayExclude(v, exclude);
|
|
56
|
+
}
|
|
57
|
+
if (isArray(v)) {
|
|
58
|
+
o[k] = v.map((x) => deepCloneExclude(x, exclude));
|
|
59
|
+
} else if (isObject(v)) {
|
|
60
|
+
o[k] = deepCloneExclude(v, exclude);
|
|
61
|
+
} else
|
|
62
|
+
o[k] = v;
|
|
63
|
+
}
|
|
64
|
+
return o;
|
|
65
|
+
};
|
|
66
|
+
const mergeArrayExclude = (arr, excl = []) => {
|
|
67
|
+
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
68
|
+
};
|
|
69
|
+
const deepClone = (obj2) => {
|
|
70
|
+
if (isArray(obj2)) {
|
|
71
|
+
return obj2.map(deepClone);
|
|
72
|
+
}
|
|
73
|
+
const o = {};
|
|
74
|
+
for (const prop2 in obj2) {
|
|
75
|
+
let objProp2 = obj2[prop2];
|
|
76
|
+
if (prop2 === "extend" && isArray(objProp2)) {
|
|
77
|
+
objProp2 = mergeArray(objProp2);
|
|
78
|
+
}
|
|
79
|
+
if (isArray(objProp2)) {
|
|
80
|
+
o[prop2] = objProp2.map((v) => isObject(v) ? deepClone(v) : v);
|
|
81
|
+
} else if (isObject(objProp2)) {
|
|
82
|
+
o[prop2] = deepClone(objProp2);
|
|
83
|
+
} else
|
|
84
|
+
o[prop2] = objProp2;
|
|
85
|
+
}
|
|
86
|
+
return o;
|
|
87
|
+
};
|
|
88
|
+
const deepStringify = (obj2, stringified2 = {}) => {
|
|
89
|
+
for (const prop2 in obj2) {
|
|
90
|
+
const objProp2 = obj2[prop2];
|
|
91
|
+
if (isFunction(objProp2)) {
|
|
92
|
+
stringified2[prop2] = objProp2.toString();
|
|
93
|
+
} else if (isObject(objProp2)) {
|
|
94
|
+
stringified2[prop2] = {};
|
|
95
|
+
deepStringify(objProp2[prop2], stringified2[prop2]);
|
|
96
|
+
} else if (isArray(objProp2)) {
|
|
97
|
+
stringified2[prop2] = [];
|
|
98
|
+
objProp2.map((v, i) => deepStringify(v, stringified2[prop2][i]));
|
|
99
|
+
} else
|
|
100
|
+
stringified2[prop2] = objProp2;
|
|
101
|
+
}
|
|
102
|
+
return stringified2;
|
|
103
|
+
};
|
|
104
|
+
const deepDestringify = (obj, stringified = {}) => {
|
|
105
|
+
for (const prop in obj) {
|
|
106
|
+
const objProp = obj[prop];
|
|
107
|
+
if (isString(objProp)) {
|
|
108
|
+
if (objProp.includes("=>") || objProp.includes("function") || objProp[0] === "(") {
|
|
109
|
+
try {
|
|
110
|
+
const evalProp = eval(objProp);
|
|
111
|
+
stringified[prop] = evalProp;
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (e)
|
|
114
|
+
stringified[prop] = objProp;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} else
|
|
118
|
+
stringified[prop] = objProp;
|
|
119
|
+
if (isObject(objProp))
|
|
120
|
+
deepDestringify(stringified[prop], stringified[prop]);
|
|
121
|
+
}
|
|
122
|
+
return stringified;
|
|
123
|
+
};
|
|
124
|
+
const overwrite = (element, params, options) => {
|
|
125
|
+
const { ref } = element;
|
|
126
|
+
const changes = {};
|
|
127
|
+
for (const e in params) {
|
|
128
|
+
if (e === "props")
|
|
129
|
+
continue;
|
|
130
|
+
const elementProp = element[e];
|
|
131
|
+
const paramsProp = params[e];
|
|
132
|
+
if (paramsProp) {
|
|
133
|
+
ref.__cache[e] = changes[e] = elementProp;
|
|
134
|
+
ref[e] = paramsProp;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return changes;
|
|
138
|
+
};
|
|
139
|
+
const diff = (obj2, original, cache) => {
|
|
140
|
+
const changes = cache || {};
|
|
141
|
+
for (const e in obj2) {
|
|
142
|
+
if (e === "ref")
|
|
143
|
+
continue;
|
|
144
|
+
const originalProp = original[e];
|
|
145
|
+
const objProp2 = obj2[e];
|
|
146
|
+
if (isObjectLike(originalProp) && isObjectLike(objProp2)) {
|
|
147
|
+
changes[e] = {};
|
|
148
|
+
diff(originalProp, objProp2, changes[e]);
|
|
149
|
+
} else if (objProp2 !== void 0) {
|
|
150
|
+
changes[e] = objProp2;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return changes;
|
|
154
|
+
};
|
|
155
|
+
const overwriteObj = (params, obj2) => {
|
|
156
|
+
const changes = {};
|
|
157
|
+
for (const e in params) {
|
|
158
|
+
const objProp2 = obj2[e];
|
|
159
|
+
const paramsProp = params[e];
|
|
160
|
+
if (paramsProp) {
|
|
161
|
+
obj2[e] = changes[e] = objProp2;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return changes;
|
|
165
|
+
};
|
|
166
|
+
const overwriteDeep = (params, obj2) => {
|
|
167
|
+
for (const e in params) {
|
|
168
|
+
const objProp2 = obj2[e];
|
|
169
|
+
const paramsProp = params[e];
|
|
170
|
+
if (isObjectLike(objProp2) && isObjectLike(paramsProp)) {
|
|
171
|
+
overwriteDeep(objProp2, paramsProp);
|
|
172
|
+
} else if (paramsProp !== void 0) {
|
|
173
|
+
obj2[e] = paramsProp;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return obj2;
|
|
177
|
+
};
|
|
178
|
+
const mergeIfExisted = (a, b) => {
|
|
179
|
+
if (isObjectLike(a) && isObjectLike(b))
|
|
180
|
+
return deepMerge(a, b);
|
|
181
|
+
return a || b;
|
|
182
|
+
};
|
|
183
|
+
const mergeArray = (arr) => {
|
|
184
|
+
return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {});
|
|
185
|
+
};
|
|
186
|
+
const mergeAndCloneIfArray = (obj2) => {
|
|
187
|
+
return isArray(obj2) ? mergeArray(obj2) : deepClone(obj2);
|
|
188
|
+
};
|
|
189
|
+
const flattenRecursive = (param, prop2, stack = []) => {
|
|
190
|
+
const objectized = mergeAndCloneIfArray(param);
|
|
191
|
+
stack.push(objectized);
|
|
192
|
+
const extendOfExtend = objectized[prop2];
|
|
193
|
+
if (extendOfExtend)
|
|
194
|
+
flattenRecursive(extendOfExtend, prop2, stack);
|
|
195
|
+
delete objectized[prop2];
|
|
196
|
+
return stack;
|
|
197
|
+
};
|
|
198
|
+
const isEqualDeep = (param, element) => {
|
|
199
|
+
if (param === element)
|
|
200
|
+
return true;
|
|
201
|
+
if (!param || !element)
|
|
202
|
+
return false;
|
|
203
|
+
for (const prop2 in param) {
|
|
204
|
+
const paramProp = param[prop2];
|
|
205
|
+
const elementProp = element[prop2];
|
|
206
|
+
if (isObjectLike(paramProp)) {
|
|
207
|
+
const isEqual = isEqualDeep(paramProp, elementProp);
|
|
208
|
+
if (!isEqual)
|
|
209
|
+
return false;
|
|
210
|
+
} else {
|
|
211
|
+
const isEqual = paramProp === elementProp;
|
|
212
|
+
if (!isEqual)
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
};
|
|
218
|
+
export {
|
|
219
|
+
clone,
|
|
220
|
+
deepClone,
|
|
221
|
+
deepCloneExclude,
|
|
222
|
+
deepDestringify,
|
|
223
|
+
deepMerge,
|
|
224
|
+
deepStringify,
|
|
225
|
+
diff,
|
|
226
|
+
exec,
|
|
227
|
+
flattenRecursive,
|
|
228
|
+
isEqualDeep,
|
|
229
|
+
map,
|
|
230
|
+
merge,
|
|
231
|
+
mergeAndCloneIfArray,
|
|
232
|
+
mergeArray,
|
|
233
|
+
mergeArrayExclude,
|
|
234
|
+
mergeIfExisted,
|
|
235
|
+
overwrite,
|
|
236
|
+
overwriteDeep,
|
|
237
|
+
overwriteObj
|
|
238
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { window } from "@domql/globals";
|
|
2
|
+
import { HTML_TAGS } from "@domql/tags";
|
|
3
|
+
const isValidHtmlTag = (arg) => HTML_TAGS.body.indexOf(arg);
|
|
4
|
+
const isObject = (arg) => {
|
|
5
|
+
if (arg === null)
|
|
6
|
+
return false;
|
|
7
|
+
return typeof arg === "object" && arg.constructor === Object;
|
|
8
|
+
};
|
|
9
|
+
const isString = (arg) => typeof arg === "string";
|
|
10
|
+
const isNumber = (arg) => typeof arg === "number";
|
|
11
|
+
const isFunction = (arg) => typeof arg === "function";
|
|
12
|
+
const isBoolean = (arg) => arg === true || arg === false;
|
|
13
|
+
const isNull = (arg) => arg === null;
|
|
14
|
+
const isArray = (arg) => Array.isArray(arg);
|
|
15
|
+
const isObjectLike = (arg) => {
|
|
16
|
+
if (arg === null)
|
|
17
|
+
return false;
|
|
18
|
+
return typeof arg === "object";
|
|
19
|
+
};
|
|
20
|
+
const isNode = (obj) => {
|
|
21
|
+
return typeof window.Node === "object" ? obj instanceof window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string";
|
|
22
|
+
};
|
|
23
|
+
const isHtmlElement = (obj) => {
|
|
24
|
+
return typeof window.HTMLElement === "object" ? obj instanceof window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string";
|
|
25
|
+
};
|
|
26
|
+
const isDefined = (arg) => {
|
|
27
|
+
return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isNull(arg);
|
|
28
|
+
};
|
|
29
|
+
const isUndefined = (arg) => {
|
|
30
|
+
return arg === void 0;
|
|
31
|
+
};
|
|
32
|
+
const TYPES = {
|
|
33
|
+
boolean: isBoolean,
|
|
34
|
+
array: isArray,
|
|
35
|
+
object: isObject,
|
|
36
|
+
string: isString,
|
|
37
|
+
number: isNumber,
|
|
38
|
+
null: isNull,
|
|
39
|
+
function: isFunction,
|
|
40
|
+
objectLike: isObjectLike,
|
|
41
|
+
node: isNode,
|
|
42
|
+
htmlElement: isHtmlElement,
|
|
43
|
+
defined: isDefined
|
|
44
|
+
};
|
|
45
|
+
const is = (arg) => {
|
|
46
|
+
return (...args) => {
|
|
47
|
+
return args.map((val) => TYPES[val](arg)).filter((v) => v).length > 0;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const isNot = (arg) => {
|
|
51
|
+
return (...args) => {
|
|
52
|
+
return args.map((val) => TYPES[val](arg)).filter((v) => v).length === 0;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
TYPES,
|
|
57
|
+
is,
|
|
58
|
+
isArray,
|
|
59
|
+
isBoolean,
|
|
60
|
+
isDefined,
|
|
61
|
+
isFunction,
|
|
62
|
+
isHtmlElement,
|
|
63
|
+
isNode,
|
|
64
|
+
isNot,
|
|
65
|
+
isNull,
|
|
66
|
+
isNumber,
|
|
67
|
+
isObject,
|
|
68
|
+
isObjectLike,
|
|
69
|
+
isString,
|
|
70
|
+
isUndefined,
|
|
71
|
+
isValidHtmlTag
|
|
72
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
const debounce = (element, func, timeout = 300) => {
|
|
4
|
+
let timer;
|
|
5
|
+
return (...args) => {
|
|
6
|
+
clearTimeout(timer);
|
|
7
|
+
timer = setTimeout(() => {
|
|
8
|
+
func.apply(element, args);
|
|
9
|
+
}, timeout);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const memoize = (fn) => {
|
|
13
|
+
const cache = {};
|
|
14
|
+
return (...args) => {
|
|
15
|
+
const n = args[0];
|
|
16
|
+
if (n in cache) {
|
|
17
|
+
return cache[n];
|
|
18
|
+
} else {
|
|
19
|
+
const result = fn(n);
|
|
20
|
+
cache[n] = result;
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
16
|
+
var utils_exports = {};
|
|
17
|
+
__reExport(utils_exports, require("./types.js"));
|
|
18
|
+
__reExport(utils_exports, require("./object.js"));
|
|
19
|
+
__reExport(utils_exports, require("./function.js"));
|
|
20
|
+
__reExport(utils_exports, require("./array.js"));
|
|
21
|
+
__reExport(utils_exports, require("./node.js"));
|
|
22
|
+
__reExport(utils_exports, require("./log.js"));
|
|
23
|
+
})();
|
package/dist/iife/log.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
const logIf = (bool, ...arg) => {
|
|
4
|
+
if (bool)
|
|
5
|
+
arg.map((v) => console.log(v));
|
|
6
|
+
};
|
|
7
|
+
const logGroupIf = (bool, key, ...arg) => {
|
|
8
|
+
if (bool) {
|
|
9
|
+
console.group(key);
|
|
10
|
+
arg.map((v) => console.log(v));
|
|
11
|
+
console.groupEnd(key);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
const cleanWithNode = (extend) => delete extend.node && extend;
|
|
4
|
+
const createID = function() {
|
|
5
|
+
let index = 0;
|
|
6
|
+
function newId() {
|
|
7
|
+
index++;
|
|
8
|
+
return index;
|
|
9
|
+
}
|
|
10
|
+
return newId;
|
|
11
|
+
}();
|
|
12
|
+
const createSnapshotId = createID;
|
|
13
|
+
})();
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
var import_types = require("./types.js");
|
|
4
|
+
const exec = (param, element, state) => {
|
|
5
|
+
if ((0, import_types.isFunction)(param))
|
|
6
|
+
return param(element, state || element.state);
|
|
7
|
+
return param;
|
|
8
|
+
};
|
|
9
|
+
const map = (obj2, extention, element) => {
|
|
10
|
+
for (const e in extention) {
|
|
11
|
+
obj2[e] = exec(extention[e], element);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const merge = (element, obj2) => {
|
|
15
|
+
for (const e in obj2) {
|
|
16
|
+
const elementProp = element[e];
|
|
17
|
+
const objProp2 = obj2[e];
|
|
18
|
+
if (elementProp === void 0) {
|
|
19
|
+
element[e] = objProp2;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return element;
|
|
23
|
+
};
|
|
24
|
+
const deepMerge = (element, extend) => {
|
|
25
|
+
for (const e in extend) {
|
|
26
|
+
const elementProp = element[e];
|
|
27
|
+
const extendProp = extend[e];
|
|
28
|
+
if (e === "parent" || e === "props")
|
|
29
|
+
continue;
|
|
30
|
+
if (elementProp === void 0) {
|
|
31
|
+
element[e] = extendProp;
|
|
32
|
+
} else if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObject)(extendProp)) {
|
|
33
|
+
deepMerge(elementProp, extendProp);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return element;
|
|
37
|
+
};
|
|
38
|
+
const clone = (obj2) => {
|
|
39
|
+
const o = {};
|
|
40
|
+
for (const prop2 in obj2) {
|
|
41
|
+
if (prop2 === "node")
|
|
42
|
+
continue;
|
|
43
|
+
o[prop2] = obj2[prop2];
|
|
44
|
+
}
|
|
45
|
+
return o;
|
|
46
|
+
};
|
|
47
|
+
const deepCloneExclude = (obj2, exclude = []) => {
|
|
48
|
+
if ((0, import_types.isArray)(obj2)) {
|
|
49
|
+
return obj2.map((x) => deepCloneExclude(x, exclude));
|
|
50
|
+
}
|
|
51
|
+
const o = {};
|
|
52
|
+
for (const k in obj2) {
|
|
53
|
+
if (exclude.indexOf(k) > -1)
|
|
54
|
+
continue;
|
|
55
|
+
let v = obj2[k];
|
|
56
|
+
if (k === "extend" && (0, import_types.isArray)(v)) {
|
|
57
|
+
v = mergeArrayExclude(v, exclude);
|
|
58
|
+
}
|
|
59
|
+
if ((0, import_types.isArray)(v)) {
|
|
60
|
+
o[k] = v.map((x) => deepCloneExclude(x, exclude));
|
|
61
|
+
} else if ((0, import_types.isObject)(v)) {
|
|
62
|
+
o[k] = deepCloneExclude(v, exclude);
|
|
63
|
+
} else
|
|
64
|
+
o[k] = v;
|
|
65
|
+
}
|
|
66
|
+
return o;
|
|
67
|
+
};
|
|
68
|
+
const mergeArrayExclude = (arr, excl = []) => {
|
|
69
|
+
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
70
|
+
};
|
|
71
|
+
const deepClone = (obj2) => {
|
|
72
|
+
if ((0, import_types.isArray)(obj2)) {
|
|
73
|
+
return obj2.map(deepClone);
|
|
74
|
+
}
|
|
75
|
+
const o = {};
|
|
76
|
+
for (const prop2 in obj2) {
|
|
77
|
+
let objProp2 = obj2[prop2];
|
|
78
|
+
if (prop2 === "extend" && (0, import_types.isArray)(objProp2)) {
|
|
79
|
+
objProp2 = mergeArray(objProp2);
|
|
80
|
+
}
|
|
81
|
+
if ((0, import_types.isArray)(objProp2)) {
|
|
82
|
+
o[prop2] = objProp2.map((v) => (0, import_types.isObject)(v) ? deepClone(v) : v);
|
|
83
|
+
} else if ((0, import_types.isObject)(objProp2)) {
|
|
84
|
+
o[prop2] = deepClone(objProp2);
|
|
85
|
+
} else
|
|
86
|
+
o[prop2] = objProp2;
|
|
87
|
+
}
|
|
88
|
+
return o;
|
|
89
|
+
};
|
|
90
|
+
const deepStringify = (obj2, stringified2 = {}) => {
|
|
91
|
+
for (const prop2 in obj2) {
|
|
92
|
+
const objProp2 = obj2[prop2];
|
|
93
|
+
if ((0, import_types.isFunction)(objProp2)) {
|
|
94
|
+
stringified2[prop2] = objProp2.toString();
|
|
95
|
+
} else if ((0, import_types.isObject)(objProp2)) {
|
|
96
|
+
stringified2[prop2] = {};
|
|
97
|
+
deepStringify(objProp2[prop2], stringified2[prop2]);
|
|
98
|
+
} else if ((0, import_types.isArray)(objProp2)) {
|
|
99
|
+
stringified2[prop2] = [];
|
|
100
|
+
objProp2.map((v, i) => deepStringify(v, stringified2[prop2][i]));
|
|
101
|
+
} else
|
|
102
|
+
stringified2[prop2] = objProp2;
|
|
103
|
+
}
|
|
104
|
+
return stringified2;
|
|
105
|
+
};
|
|
106
|
+
const deepDestringify = (obj, stringified = {}) => {
|
|
107
|
+
for (const prop in obj) {
|
|
108
|
+
const objProp = obj[prop];
|
|
109
|
+
if ((0, import_types.isString)(objProp)) {
|
|
110
|
+
if (objProp.includes("=>") || objProp.includes("function") || objProp[0] === "(") {
|
|
111
|
+
try {
|
|
112
|
+
const evalProp = eval(objProp);
|
|
113
|
+
stringified[prop] = evalProp;
|
|
114
|
+
} catch (e) {
|
|
115
|
+
if (e)
|
|
116
|
+
stringified[prop] = objProp;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} else
|
|
120
|
+
stringified[prop] = objProp;
|
|
121
|
+
if ((0, import_types.isObject)(objProp))
|
|
122
|
+
deepDestringify(stringified[prop], stringified[prop]);
|
|
123
|
+
}
|
|
124
|
+
return stringified;
|
|
125
|
+
};
|
|
126
|
+
const overwrite = (element, params, options) => {
|
|
127
|
+
const { ref } = element;
|
|
128
|
+
const changes = {};
|
|
129
|
+
for (const e in params) {
|
|
130
|
+
if (e === "props")
|
|
131
|
+
continue;
|
|
132
|
+
const elementProp = element[e];
|
|
133
|
+
const paramsProp = params[e];
|
|
134
|
+
if (paramsProp) {
|
|
135
|
+
ref.__cache[e] = changes[e] = elementProp;
|
|
136
|
+
ref[e] = paramsProp;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return changes;
|
|
140
|
+
};
|
|
141
|
+
const diff = (obj2, original, cache) => {
|
|
142
|
+
const changes = cache || {};
|
|
143
|
+
for (const e in obj2) {
|
|
144
|
+
if (e === "ref")
|
|
145
|
+
continue;
|
|
146
|
+
const originalProp = original[e];
|
|
147
|
+
const objProp2 = obj2[e];
|
|
148
|
+
if ((0, import_types.isObjectLike)(originalProp) && (0, import_types.isObjectLike)(objProp2)) {
|
|
149
|
+
changes[e] = {};
|
|
150
|
+
diff(originalProp, objProp2, changes[e]);
|
|
151
|
+
} else if (objProp2 !== void 0) {
|
|
152
|
+
changes[e] = objProp2;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return changes;
|
|
156
|
+
};
|
|
157
|
+
const overwriteObj = (params, obj2) => {
|
|
158
|
+
const changes = {};
|
|
159
|
+
for (const e in params) {
|
|
160
|
+
const objProp2 = obj2[e];
|
|
161
|
+
const paramsProp = params[e];
|
|
162
|
+
if (paramsProp) {
|
|
163
|
+
obj2[e] = changes[e] = objProp2;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return changes;
|
|
167
|
+
};
|
|
168
|
+
const overwriteDeep = (params, obj2) => {
|
|
169
|
+
for (const e in params) {
|
|
170
|
+
const objProp2 = obj2[e];
|
|
171
|
+
const paramsProp = params[e];
|
|
172
|
+
if ((0, import_types.isObjectLike)(objProp2) && (0, import_types.isObjectLike)(paramsProp)) {
|
|
173
|
+
overwriteDeep(objProp2, paramsProp);
|
|
174
|
+
} else if (paramsProp !== void 0) {
|
|
175
|
+
obj2[e] = paramsProp;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return obj2;
|
|
179
|
+
};
|
|
180
|
+
const mergeIfExisted = (a, b) => {
|
|
181
|
+
if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b))
|
|
182
|
+
return deepMerge(a, b);
|
|
183
|
+
return a || b;
|
|
184
|
+
};
|
|
185
|
+
const mergeArray = (arr) => {
|
|
186
|
+
return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {});
|
|
187
|
+
};
|
|
188
|
+
const mergeAndCloneIfArray = (obj2) => {
|
|
189
|
+
return (0, import_types.isArray)(obj2) ? mergeArray(obj2) : deepClone(obj2);
|
|
190
|
+
};
|
|
191
|
+
const flattenRecursive = (param, prop2, stack = []) => {
|
|
192
|
+
const objectized = mergeAndCloneIfArray(param);
|
|
193
|
+
stack.push(objectized);
|
|
194
|
+
const extendOfExtend = objectized[prop2];
|
|
195
|
+
if (extendOfExtend)
|
|
196
|
+
flattenRecursive(extendOfExtend, prop2, stack);
|
|
197
|
+
delete objectized[prop2];
|
|
198
|
+
return stack;
|
|
199
|
+
};
|
|
200
|
+
const isEqualDeep = (param, element) => {
|
|
201
|
+
if (param === element)
|
|
202
|
+
return true;
|
|
203
|
+
if (!param || !element)
|
|
204
|
+
return false;
|
|
205
|
+
for (const prop2 in param) {
|
|
206
|
+
const paramProp = param[prop2];
|
|
207
|
+
const elementProp = element[prop2];
|
|
208
|
+
if ((0, import_types.isObjectLike)(paramProp)) {
|
|
209
|
+
const isEqual = isEqualDeep(paramProp, elementProp);
|
|
210
|
+
if (!isEqual)
|
|
211
|
+
return false;
|
|
212
|
+
} else {
|
|
213
|
+
const isEqual = paramProp === elementProp;
|
|
214
|
+
if (!isEqual)
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
};
|
|
220
|
+
})();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
var import_globals = require("@domql/globals");
|
|
4
|
+
var import_tags = require("@domql/tags");
|
|
5
|
+
const isValidHtmlTag = (arg) => import_tags.HTML_TAGS.body.indexOf(arg);
|
|
6
|
+
const isObject = (arg) => {
|
|
7
|
+
if (arg === null)
|
|
8
|
+
return false;
|
|
9
|
+
return typeof arg === "object" && arg.constructor === Object;
|
|
10
|
+
};
|
|
11
|
+
const isString = (arg) => typeof arg === "string";
|
|
12
|
+
const isNumber = (arg) => typeof arg === "number";
|
|
13
|
+
const isFunction = (arg) => typeof arg === "function";
|
|
14
|
+
const isBoolean = (arg) => arg === true || arg === false;
|
|
15
|
+
const isNull = (arg) => arg === null;
|
|
16
|
+
const isArray = (arg) => Array.isArray(arg);
|
|
17
|
+
const isObjectLike = (arg) => {
|
|
18
|
+
if (arg === null)
|
|
19
|
+
return false;
|
|
20
|
+
return typeof arg === "object";
|
|
21
|
+
};
|
|
22
|
+
const isNode = (obj) => {
|
|
23
|
+
return typeof import_globals.window.Node === "object" ? obj instanceof import_globals.window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string";
|
|
24
|
+
};
|
|
25
|
+
const isHtmlElement = (obj) => {
|
|
26
|
+
return typeof import_globals.window.HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string";
|
|
27
|
+
};
|
|
28
|
+
const isDefined = (arg) => {
|
|
29
|
+
return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isNull(arg);
|
|
30
|
+
};
|
|
31
|
+
const isUndefined = (arg) => {
|
|
32
|
+
return arg === void 0;
|
|
33
|
+
};
|
|
34
|
+
const TYPES = {
|
|
35
|
+
boolean: isBoolean,
|
|
36
|
+
array: isArray,
|
|
37
|
+
object: isObject,
|
|
38
|
+
string: isString,
|
|
39
|
+
number: isNumber,
|
|
40
|
+
null: isNull,
|
|
41
|
+
function: isFunction,
|
|
42
|
+
objectLike: isObjectLike,
|
|
43
|
+
node: isNode,
|
|
44
|
+
htmlElement: isHtmlElement,
|
|
45
|
+
defined: isDefined
|
|
46
|
+
};
|
|
47
|
+
const is = (arg) => {
|
|
48
|
+
return (...args) => {
|
|
49
|
+
return args.map((val) => TYPES[val](arg)).filter((v) => v).length > 0;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const isNot = (arg) => {
|
|
53
|
+
return (...args) => {
|
|
54
|
+
return args.map((val) => TYPES[val](arg)).filter((v) => v).length === 0;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.57",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -11,17 +11,18 @@
|
|
|
11
11
|
"source": "index.js",
|
|
12
12
|
"files": [
|
|
13
13
|
"*.js",
|
|
14
|
-
"dist
|
|
14
|
+
"dist"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
+
"copy:package:cjs": "cp ../../package-cjs.json dist/cjs",
|
|
17
18
|
"build:esm": "npx esbuild *.js --target=es2020 --format=esm --outdir=dist/esm",
|
|
18
|
-
"build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
19
|
+
"build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs && yarn copy:package:cjs",
|
|
19
20
|
"build:iife": "npx esbuild *.js --target=node16 --format=iife --outdir=dist/iife",
|
|
20
|
-
"prepublish": "
|
|
21
|
+
"prepublish": "rimraf -I dist && yarn build:esm && yarn build:cjs && yarn build:iife"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"@domql/globals": "latest",
|
|
24
25
|
"@domql/tags": "latest"
|
|
25
26
|
},
|
|
26
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "d557c80ac22bfe7a747badf29553c297e2b05cda"
|
|
27
28
|
}
|