@whitesev/utils 2.8.2 → 2.9.1

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.
Files changed (73) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +283 -776
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +2 -0
  5. package/dist/index.amd.min.js.map +1 -0
  6. package/dist/index.cjs.js +283 -776
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +2 -0
  9. package/dist/index.cjs.min.js.map +1 -0
  10. package/dist/index.esm.js +283 -776
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +2 -0
  13. package/dist/index.esm.min.js.map +1 -0
  14. package/dist/index.iife.js +283 -776
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +2 -0
  17. package/dist/index.iife.min.js.map +1 -0
  18. package/dist/index.system.js +283 -776
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +2 -0
  21. package/dist/index.system.min.js.map +1 -0
  22. package/dist/index.umd.js +283 -776
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +2 -0
  25. package/dist/index.umd.min.js.map +1 -0
  26. package/dist/types/src/Utils.d.ts +132 -448
  27. package/dist/types/src/UtilsGMCookie.d.ts +4 -0
  28. package/dist/types/src/UtilsGMMenu.d.ts +3 -6
  29. package/dist/types/src/types/Httpx.d.ts +1344 -1344
  30. package/dist/types/src/types/Log.d.ts +19 -19
  31. package/dist/types/src/types/Progress.d.ts +20 -20
  32. package/dist/types/src/types/React.d.ts +119 -119
  33. package/dist/types/src/types/TryCatch.d.ts +9 -9
  34. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  35. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  36. package/dist/types/src/types/Vue2.d.ts +166 -166
  37. package/dist/types/src/types/WindowApi.d.ts +14 -14
  38. package/dist/types/src/types/ajaxHooker.d.ts +153 -151
  39. package/dist/types/src/types/env.d.ts +7 -7
  40. package/dist/types/src/types/global.d.ts +31 -31
  41. package/package.json +11 -10
  42. package/src/ColorConversion.ts +105 -105
  43. package/src/CommonUtil.ts +280 -280
  44. package/src/DOMUtils.ts +251 -251
  45. package/src/Dictionary.ts +153 -153
  46. package/src/GBKEncoder.ts +108 -108
  47. package/src/Hooks.ts +73 -73
  48. package/src/Httpx.ts +1457 -1457
  49. package/src/LockFunction.ts +62 -62
  50. package/src/Log.ts +258 -258
  51. package/src/Progress.ts +108 -108
  52. package/src/TryCatch.ts +86 -86
  53. package/src/Utils.ts +3827 -4773
  54. package/src/UtilsCommon.ts +14 -14
  55. package/src/UtilsGMCookie.ts +272 -254
  56. package/src/UtilsGMMenu.ts +441 -445
  57. package/src/Vue.ts +233 -233
  58. package/src/WindowApi.ts +59 -59
  59. package/src/indexedDB.ts +497 -497
  60. package/src/types/Httpx.d.ts +1344 -1344
  61. package/src/types/Log.d.ts +19 -19
  62. package/src/types/Progress.d.ts +20 -20
  63. package/src/types/React.d.ts +119 -119
  64. package/src/types/TryCatch.d.ts +9 -9
  65. package/src/types/UtilsGMCookie.d.ts +93 -93
  66. package/src/types/UtilsGMMenu.d.ts +77 -77
  67. package/src/types/Vue2.d.ts +166 -166
  68. package/src/types/WindowApi.d.ts +14 -14
  69. package/src/types/ajaxHooker.d.ts +153 -151
  70. package/src/types/env.d.ts +7 -7
  71. package/src/types/global.d.ts +31 -31
  72. package/dist/types/src/types/Event.d.ts +0 -188
  73. package/src/types/Event.d.ts +0 -188
package/src/Vue.ts CHANGED
@@ -1,233 +1,233 @@
1
- // @ts-nocheck
2
- const VueUtils = {
3
- /** 标签 */
4
- ReactiveFlags: {
5
- IS_REACTIVE: Symbol("isReactive"),
6
- },
7
- /**
8
- * 判断是否是对象
9
- * @param value
10
- */
11
- isObject(value: any) {
12
- return typeof value === "object" && value !== null;
13
- },
14
- /**
15
- * 判断是否是函数
16
- * @param val
17
- */
18
- isFunction(val: any) {
19
- return typeof val === "function";
20
- },
21
- /**
22
- * 处理对象再次代理,可以直接返回
23
- * @param value
24
- */
25
- isReactive(value: any) {
26
- return !!(value && value[VueUtils.ReactiveFlags.IS_REACTIVE]);
27
- },
28
- /**
29
- * 判断是否是数组
30
- * @param value
31
- */
32
- isArray(value: any): boolean {
33
- return Array.isArray(value);
34
- },
35
- };
36
-
37
- class ReactiveEffect {
38
- deps: any[] = [];
39
- private active = true;
40
- private fn;
41
- private scheduler;
42
- constructor(fn: (...args: any[]) => any, scheduler: any) {
43
- this.fn = fn;
44
- this.scheduler = scheduler;
45
- }
46
- run(cb: (activeEffect: any) => void) {
47
- if (!this.active) {
48
- this.fn();
49
- }
50
- try {
51
- if (typeof cb === "function") {
52
- cb(this);
53
- }
54
- return this.fn();
55
- } finally {
56
- if (typeof cb === "function") {
57
- cb(undefined);
58
- }
59
- }
60
- }
61
- }
62
- class RefImpl {
63
- _value;
64
- _isRef = true;
65
- _rawValue;
66
- _vue: Vue;
67
- constructor(vueIns: Vue, rawValue: any) {
68
- this._vue = vueIns;
69
- this._rawValue = rawValue;
70
- this._value = this._vue.toReactive(rawValue);
71
- }
72
- get value() {
73
- return this._value;
74
- }
75
- set value(newValue) {
76
- if (newValue !== this._rawValue) {
77
- this._value = this._vue.toReactive(newValue);
78
- this._rawValue = newValue;
79
- }
80
- }
81
- }
82
- class ObjectRefImpl {
83
- object;
84
- key;
85
- constructor(object: any, key: any) {
86
- this.object = object;
87
- this.key = key;
88
- }
89
- get value() {
90
- return this.object[this.key];
91
- }
92
- set value(newValue) {
93
- this.object[this.key] = newValue;
94
- }
95
- }
96
- export class Vue {
97
- private reactMap = new WeakMap();
98
- private targetMap = new WeakMap();
99
- private activeEffect = undefined as any as ReactiveEffect;
100
- constructor() {
101
- // 将数据转化成响应式的数据,只能做对象的代理
102
- }
103
- /**
104
- * 生成一个被代理的对象
105
- * @param target 需要代理的对象
106
- */
107
- reactive<T extends object>(target: T): T {
108
- const that = this;
109
- if (!(typeof target === "object" && target !== null)) {
110
- return void 0 as any as T;
111
- }
112
- if (VueUtils.isReactive(target)) {
113
- return target;
114
- }
115
- const exisProxy = this.reactMap.get(target);
116
- if (exisProxy) {
117
- return exisProxy;
118
- }
119
- const proxy = new Proxy(target, {
120
- get(target, key, receiver) {
121
- if (key === VueUtils.ReactiveFlags.IS_REACTIVE) {
122
- return true;
123
- }
124
- that.track(target, "get", key);
125
- return Reflect.get(target, key, receiver);
126
- },
127
- set(target, key, value, receiver) {
128
- const oldValue = target[key as keyof T];
129
- const result = Reflect.set(target, key, value, receiver);
130
- if (oldValue !== value) {
131
- that.trigger(target, "set", key, oldValue, value);
132
- }
133
- return result;
134
- },
135
- });
136
- that.reactMap.set(target, proxy);
137
- return proxy;
138
- }
139
- /**
140
- * 观察被reactive的对象值改变
141
- * @param source 被观察的对象,这里采用函数返回对象
142
- * @param changeCallBack 值改变的回调
143
- */
144
- watch<T>(source: () => T, changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void) {
145
- let getter;
146
- if (VueUtils.isReactive(source)) {
147
- getter = () => this.traversal(source);
148
- } else if (VueUtils.isFunction(source)) {
149
- getter = source;
150
- } else {
151
- return;
152
- }
153
- let oldValue: any;
154
- const job = () => {
155
- const newValue = effect.run((activeEffect) => {
156
- this.activeEffect = activeEffect;
157
- });
158
- changeCallBack(newValue, oldValue);
159
- oldValue = newValue;
160
- };
161
- const effect = new ReactiveEffect(getter, job);
162
- oldValue = effect.run((activeEffect) => {
163
- this.activeEffect = activeEffect;
164
- });
165
- }
166
- toReactive(value: any) {
167
- return VueUtils.isObject(value) ? this.reactive(value) : value;
168
- }
169
- ref(value: any) {
170
- return new RefImpl(this, value);
171
- }
172
- toRef(object: any, key: any) {
173
- return new ObjectRefImpl(object, key);
174
- }
175
- toRefs(object: any) {
176
- const result = VueUtils.isArray(object) ? new Array(object.length) : {};
177
- for (const key in object) {
178
- (result as any)[key as any] = this.toRef(object, key);
179
- }
180
- return result;
181
- }
182
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
183
- private trigger(target: any, type: string, key: string | symbol, oldValue: any, value: any) {
184
- const depsMap = this.targetMap.get(target);
185
- if (!depsMap) return;
186
- const effects = depsMap.get(key);
187
- this.triggerEffect(effects, "effects");
188
- }
189
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
190
- private triggerEffect(effects: any[], name: string) {
191
- if (effects) {
192
- effects.forEach((effect) => {
193
- if (effect.scheduler) {
194
- effect.scheduler();
195
- } else {
196
- effect.run();
197
- }
198
- });
199
- }
200
- }
201
- private track(target: WeakKey, type: string, key: string | symbol) {
202
- if (!this.activeEffect) return;
203
- let depsMap = this.targetMap.get(target);
204
- if (!depsMap) {
205
- this.targetMap.set(target, (depsMap = new Map()));
206
- }
207
- let dep = depsMap.get(key);
208
- if (!dep) {
209
- depsMap.set(key, (dep = new Set()));
210
- }
211
- this.trackEffect(dep);
212
- }
213
- private trackEffect(dep: any) {
214
- if (this.activeEffect) {
215
- const shouldTrack = !dep.has(this.activeEffect);
216
- if (shouldTrack) {
217
- dep.add(this.activeEffect);
218
- this.activeEffect.deps.push(dep);
219
- }
220
- }
221
- }
222
- private traversal(value: any, set = new Set()) {
223
- if (!VueUtils.isObject(value)) return value;
224
- if (set.has(value)) {
225
- return value;
226
- }
227
- set.add(value);
228
- for (const key in value) {
229
- this.traversal(value[key], set);
230
- }
231
- return value;
232
- }
233
- }
1
+ // @ts-nocheck
2
+ const VueUtils = {
3
+ /** 标签 */
4
+ ReactiveFlags: {
5
+ IS_REACTIVE: Symbol("isReactive"),
6
+ },
7
+ /**
8
+ * 判断是否是对象
9
+ * @param value
10
+ */
11
+ isObject(value: any) {
12
+ return typeof value === "object" && value !== null;
13
+ },
14
+ /**
15
+ * 判断是否是函数
16
+ * @param val
17
+ */
18
+ isFunction(val: any) {
19
+ return typeof val === "function";
20
+ },
21
+ /**
22
+ * 处理对象再次代理,可以直接返回
23
+ * @param value
24
+ */
25
+ isReactive(value: any) {
26
+ return !!(value && value[VueUtils.ReactiveFlags.IS_REACTIVE]);
27
+ },
28
+ /**
29
+ * 判断是否是数组
30
+ * @param value
31
+ */
32
+ isArray(value: any): boolean {
33
+ return Array.isArray(value);
34
+ },
35
+ };
36
+
37
+ class ReactiveEffect {
38
+ deps: any[] = [];
39
+ private active = true;
40
+ private fn;
41
+ private scheduler;
42
+ constructor(fn: (...args: any[]) => any, scheduler: any) {
43
+ this.fn = fn;
44
+ this.scheduler = scheduler;
45
+ }
46
+ run(cb: (activeEffect: any) => void) {
47
+ if (!this.active) {
48
+ this.fn();
49
+ }
50
+ try {
51
+ if (typeof cb === "function") {
52
+ cb(this);
53
+ }
54
+ return this.fn();
55
+ } finally {
56
+ if (typeof cb === "function") {
57
+ cb(undefined);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ class RefImpl {
63
+ _value;
64
+ _isRef = true;
65
+ _rawValue;
66
+ _vue: Vue;
67
+ constructor(vueIns: Vue, rawValue: any) {
68
+ this._vue = vueIns;
69
+ this._rawValue = rawValue;
70
+ this._value = this._vue.toReactive(rawValue);
71
+ }
72
+ get value() {
73
+ return this._value;
74
+ }
75
+ set value(newValue) {
76
+ if (newValue !== this._rawValue) {
77
+ this._value = this._vue.toReactive(newValue);
78
+ this._rawValue = newValue;
79
+ }
80
+ }
81
+ }
82
+ class ObjectRefImpl {
83
+ object;
84
+ key;
85
+ constructor(object: any, key: any) {
86
+ this.object = object;
87
+ this.key = key;
88
+ }
89
+ get value() {
90
+ return this.object[this.key];
91
+ }
92
+ set value(newValue) {
93
+ this.object[this.key] = newValue;
94
+ }
95
+ }
96
+ export class Vue {
97
+ private reactMap = new WeakMap();
98
+ private targetMap = new WeakMap();
99
+ private activeEffect = undefined as any as ReactiveEffect;
100
+ constructor() {
101
+ // 将数据转化成响应式的数据,只能做对象的代理
102
+ }
103
+ /**
104
+ * 生成一个被代理的对象
105
+ * @param target 需要代理的对象
106
+ */
107
+ reactive<T extends object>(target: T): T {
108
+ const that = this;
109
+ if (!(typeof target === "object" && target !== null)) {
110
+ return void 0 as any as T;
111
+ }
112
+ if (VueUtils.isReactive(target)) {
113
+ return target;
114
+ }
115
+ const exisProxy = this.reactMap.get(target);
116
+ if (exisProxy) {
117
+ return exisProxy;
118
+ }
119
+ const proxy = new Proxy(target, {
120
+ get(target, key, receiver) {
121
+ if (key === VueUtils.ReactiveFlags.IS_REACTIVE) {
122
+ return true;
123
+ }
124
+ that.track(target, "get", key);
125
+ return Reflect.get(target, key, receiver);
126
+ },
127
+ set(target, key, value, receiver) {
128
+ const oldValue = target[key as keyof T];
129
+ const result = Reflect.set(target, key, value, receiver);
130
+ if (oldValue !== value) {
131
+ that.trigger(target, "set", key, oldValue, value);
132
+ }
133
+ return result;
134
+ },
135
+ });
136
+ that.reactMap.set(target, proxy);
137
+ return proxy;
138
+ }
139
+ /**
140
+ * 观察被reactive的对象值改变
141
+ * @param source 被观察的对象,这里采用函数返回对象
142
+ * @param changeCallBack 值改变的回调
143
+ */
144
+ watch<T>(source: () => T, changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void) {
145
+ let getter;
146
+ if (VueUtils.isReactive(source)) {
147
+ getter = () => this.traversal(source);
148
+ } else if (VueUtils.isFunction(source)) {
149
+ getter = source;
150
+ } else {
151
+ return;
152
+ }
153
+ let oldValue: any;
154
+ const job = () => {
155
+ const newValue = effect.run((activeEffect) => {
156
+ this.activeEffect = activeEffect;
157
+ });
158
+ changeCallBack(newValue, oldValue);
159
+ oldValue = newValue;
160
+ };
161
+ const effect = new ReactiveEffect(getter, job);
162
+ oldValue = effect.run((activeEffect) => {
163
+ this.activeEffect = activeEffect;
164
+ });
165
+ }
166
+ toReactive(value: any) {
167
+ return VueUtils.isObject(value) ? this.reactive(value) : value;
168
+ }
169
+ ref(value: any) {
170
+ return new RefImpl(this, value);
171
+ }
172
+ toRef(object: any, key: any) {
173
+ return new ObjectRefImpl(object, key);
174
+ }
175
+ toRefs(object: any) {
176
+ const result = VueUtils.isArray(object) ? new Array(object.length) : {};
177
+ for (const key in object) {
178
+ (result as any)[key as any] = this.toRef(object, key);
179
+ }
180
+ return result;
181
+ }
182
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
183
+ private trigger(target: any, type: string, key: string | symbol, oldValue: any, value: any) {
184
+ const depsMap = this.targetMap.get(target);
185
+ if (!depsMap) return;
186
+ const effects = depsMap.get(key);
187
+ this.triggerEffect(effects, "effects");
188
+ }
189
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
190
+ private triggerEffect(effects: any[], name: string) {
191
+ if (effects) {
192
+ effects.forEach((effect) => {
193
+ if (effect.scheduler) {
194
+ effect.scheduler();
195
+ } else {
196
+ effect.run();
197
+ }
198
+ });
199
+ }
200
+ }
201
+ private track(target: WeakKey, type: string, key: string | symbol) {
202
+ if (!this.activeEffect) return;
203
+ let depsMap = this.targetMap.get(target);
204
+ if (!depsMap) {
205
+ this.targetMap.set(target, (depsMap = new Map()));
206
+ }
207
+ let dep = depsMap.get(key);
208
+ if (!dep) {
209
+ depsMap.set(key, (dep = new Set()));
210
+ }
211
+ this.trackEffect(dep);
212
+ }
213
+ private trackEffect(dep: any) {
214
+ if (this.activeEffect) {
215
+ const shouldTrack = !dep.has(this.activeEffect);
216
+ if (shouldTrack) {
217
+ dep.add(this.activeEffect);
218
+ this.activeEffect.deps.push(dep);
219
+ }
220
+ }
221
+ }
222
+ private traversal(value: any, set = new Set()) {
223
+ if (!VueUtils.isObject(value)) return value;
224
+ if (set.has(value)) {
225
+ return value;
226
+ }
227
+ set.add(value);
228
+ for (const key in value) {
229
+ this.traversal(value[key], set);
230
+ }
231
+ return value;
232
+ }
233
+ }
package/src/WindowApi.ts CHANGED
@@ -1,59 +1,59 @@
1
- import type { WindowApiOption } from "./types/WindowApi";
2
-
3
- export class WindowApi {
4
- /** 默认的配置 */
5
- private defaultApi: Required<WindowApiOption> = {
6
- document: document,
7
- window: window,
8
- globalThis: globalThis,
9
- self: self,
10
- top: top!,
11
- setTimeout: globalThis.setTimeout.bind(globalThis),
12
- setInterval: globalThis.setInterval.bind(globalThis),
13
- clearTimeout: globalThis.clearTimeout.bind(globalThis),
14
- clearInterval: globalThis.clearInterval.bind(globalThis),
15
- };
16
- /** 使用的配置 */
17
- private api: Required<WindowApiOption>;
18
- constructor(option?: WindowApiOption) {
19
- if (option) {
20
- if (option.globalThis == null) {
21
- option.globalThis = option.window;
22
- }
23
- if (option.self == null) {
24
- option.self = option.window;
25
- }
26
- }
27
- if (!option) {
28
- option = Object.assign({}, this.defaultApi);
29
- }
30
- this.api = Object.assign({}, option as Required<WindowApiOption>);
31
- }
32
- get document() {
33
- return this.api.document;
34
- }
35
- get window() {
36
- return this.api.window;
37
- }
38
- get globalThis() {
39
- return this.api.globalThis;
40
- }
41
- get self() {
42
- return this.api.self;
43
- }
44
- get top() {
45
- return this.api.top;
46
- }
47
- get setTimeout() {
48
- return this.api.setTimeout;
49
- }
50
- get setInterval() {
51
- return this.api.setInterval;
52
- }
53
- get clearTimeout() {
54
- return this.api.clearTimeout;
55
- }
56
- get clearInterval() {
57
- return this.api.clearInterval;
58
- }
59
- }
1
+ import type { WindowApiOption } from "./types/WindowApi";
2
+
3
+ export class WindowApi {
4
+ /** 默认的配置 */
5
+ private defaultApi: Required<WindowApiOption> = {
6
+ document: document,
7
+ window: window,
8
+ globalThis: globalThis,
9
+ self: self,
10
+ top: top!,
11
+ setTimeout: globalThis.setTimeout.bind(globalThis),
12
+ setInterval: globalThis.setInterval.bind(globalThis),
13
+ clearTimeout: globalThis.clearTimeout.bind(globalThis),
14
+ clearInterval: globalThis.clearInterval.bind(globalThis),
15
+ };
16
+ /** 使用的配置 */
17
+ private api: Required<WindowApiOption>;
18
+ constructor(option?: WindowApiOption) {
19
+ if (option) {
20
+ if (option.globalThis == null) {
21
+ option.globalThis = option.window;
22
+ }
23
+ if (option.self == null) {
24
+ option.self = option.window;
25
+ }
26
+ }
27
+ if (!option) {
28
+ option = Object.assign({}, this.defaultApi);
29
+ }
30
+ this.api = Object.assign({}, option as Required<WindowApiOption>);
31
+ }
32
+ get document() {
33
+ return this.api.document;
34
+ }
35
+ get window() {
36
+ return this.api.window;
37
+ }
38
+ get globalThis() {
39
+ return this.api.globalThis;
40
+ }
41
+ get self() {
42
+ return this.api.self;
43
+ }
44
+ get top() {
45
+ return this.api.top;
46
+ }
47
+ get setTimeout() {
48
+ return this.api.setTimeout;
49
+ }
50
+ get setInterval() {
51
+ return this.api.setInterval;
52
+ }
53
+ get clearTimeout() {
54
+ return this.api.clearTimeout;
55
+ }
56
+ get clearInterval() {
57
+ return this.api.clearInterval;
58
+ }
59
+ }