@whitesev/utils 2.10.0 → 2.11.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.
- package/dist/index.amd.js +116 -29
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +116 -29
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +116 -29
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +116 -29
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +116 -29
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +116 -29
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +32 -6
- package/dist/types/src/Vue.d.ts +24 -1
- package/package.json +1 -1
- package/src/Utils.ts +57 -12
- package/src/Vue.ts +92 -21
package/dist/index.system.js
CHANGED
|
@@ -242,7 +242,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
242
242
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
243
243
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
244
244
|
|
|
245
|
-
const version = "2.
|
|
245
|
+
const version = "2.11.1";
|
|
246
246
|
|
|
247
247
|
/* eslint-disable */
|
|
248
248
|
// ==UserScript==
|
|
@@ -5339,7 +5339,6 @@ System.register('Utils', [], (function (exports) {
|
|
|
5339
5339
|
}
|
|
5340
5340
|
}
|
|
5341
5341
|
|
|
5342
|
-
// @ts-nocheck
|
|
5343
5342
|
const VueUtils = {
|
|
5344
5343
|
/** 标签 */
|
|
5345
5344
|
ReactiveFlags: {
|
|
@@ -5379,9 +5378,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
5379
5378
|
active = true;
|
|
5380
5379
|
fn;
|
|
5381
5380
|
scheduler;
|
|
5382
|
-
|
|
5381
|
+
options;
|
|
5382
|
+
constructor(fn, scheduler, options) {
|
|
5383
5383
|
this.fn = fn;
|
|
5384
5384
|
this.scheduler = scheduler;
|
|
5385
|
+
this.options = options; // 默认值为'same'
|
|
5385
5386
|
}
|
|
5386
5387
|
run(cb) {
|
|
5387
5388
|
if (!this.active) {
|
|
@@ -5399,6 +5400,18 @@ System.register('Utils', [], (function (exports) {
|
|
|
5399
5400
|
}
|
|
5400
5401
|
}
|
|
5401
5402
|
}
|
|
5403
|
+
stop() {
|
|
5404
|
+
if (this.active) {
|
|
5405
|
+
// 清除依赖关系
|
|
5406
|
+
if (this.deps && this.deps.length) {
|
|
5407
|
+
this.deps.forEach((dep) => {
|
|
5408
|
+
dep.delete(this);
|
|
5409
|
+
});
|
|
5410
|
+
this.deps.length = 0;
|
|
5411
|
+
}
|
|
5412
|
+
this.active = false;
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5402
5415
|
}
|
|
5403
5416
|
class RefImpl {
|
|
5404
5417
|
_value;
|
|
@@ -5468,9 +5481,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5468
5481
|
set(target, key, value, receiver) {
|
|
5469
5482
|
const oldValue = target[key];
|
|
5470
5483
|
const result = Reflect.set(target, key, value, receiver);
|
|
5471
|
-
|
|
5472
|
-
that.trigger(target, "set", key, oldValue, value);
|
|
5473
|
-
}
|
|
5484
|
+
that.trigger(target, "set", key, oldValue, value);
|
|
5474
5485
|
return result;
|
|
5475
5486
|
},
|
|
5476
5487
|
});
|
|
@@ -5481,8 +5492,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
5481
5492
|
* 观察被reactive的对象值改变
|
|
5482
5493
|
* @param source 被观察的对象,这里采用函数返回对象
|
|
5483
5494
|
* @param changeCallBack 值改变的回调
|
|
5495
|
+
* @param options 配置项
|
|
5484
5496
|
*/
|
|
5485
|
-
watch(source, changeCallBack) {
|
|
5497
|
+
watch(source, changeCallBack, options) {
|
|
5486
5498
|
let getter;
|
|
5487
5499
|
if (VueUtils.isReactive(source)) {
|
|
5488
5500
|
getter = () => this.traversal(source);
|
|
@@ -5494,17 +5506,35 @@ System.register('Utils', [], (function (exports) {
|
|
|
5494
5506
|
return;
|
|
5495
5507
|
}
|
|
5496
5508
|
let oldValue;
|
|
5509
|
+
const unwatch = () => {
|
|
5510
|
+
effect.stop();
|
|
5511
|
+
};
|
|
5497
5512
|
const job = () => {
|
|
5498
5513
|
const newValue = effect.run((activeEffect) => {
|
|
5499
5514
|
this.activeEffect = activeEffect;
|
|
5500
5515
|
});
|
|
5501
5516
|
changeCallBack(newValue, oldValue);
|
|
5517
|
+
if (options?.once) {
|
|
5518
|
+
// 仅触发一次
|
|
5519
|
+
unwatch();
|
|
5520
|
+
}
|
|
5502
5521
|
oldValue = newValue;
|
|
5503
5522
|
};
|
|
5504
|
-
const effect = new ReactiveEffect(getter, job
|
|
5523
|
+
const effect = new ReactiveEffect(getter, job, {
|
|
5524
|
+
triggerMethod: "not-same",
|
|
5525
|
+
...(options ?? {}),
|
|
5526
|
+
});
|
|
5505
5527
|
oldValue = effect.run((activeEffect) => {
|
|
5506
5528
|
this.activeEffect = activeEffect;
|
|
5507
5529
|
});
|
|
5530
|
+
if (options) {
|
|
5531
|
+
if (options.immediate) {
|
|
5532
|
+
job();
|
|
5533
|
+
}
|
|
5534
|
+
}
|
|
5535
|
+
return {
|
|
5536
|
+
unwatch,
|
|
5537
|
+
};
|
|
5508
5538
|
}
|
|
5509
5539
|
toReactive(value) {
|
|
5510
5540
|
return VueUtils.isObject(value) ? this.reactive(value) : value;
|
|
@@ -5522,28 +5552,40 @@ System.register('Utils', [], (function (exports) {
|
|
|
5522
5552
|
}
|
|
5523
5553
|
return result;
|
|
5524
5554
|
}
|
|
5525
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5526
5555
|
trigger(target, type, key, oldValue, value) {
|
|
5527
5556
|
const depsMap = this.targetMap.get(target);
|
|
5528
5557
|
if (!depsMap)
|
|
5529
5558
|
return;
|
|
5530
5559
|
const effects = depsMap.get(key);
|
|
5531
|
-
this.triggerEffect(effects, "effects");
|
|
5560
|
+
this.triggerEffect(effects, type, "effects", oldValue, value);
|
|
5532
5561
|
}
|
|
5533
|
-
|
|
5534
|
-
triggerEffect(effects, name) {
|
|
5562
|
+
triggerEffect(effects, _type, _name, oldValue, value) {
|
|
5535
5563
|
if (effects) {
|
|
5564
|
+
const isSame = oldValue === value;
|
|
5536
5565
|
effects.forEach((effect) => {
|
|
5537
|
-
if (effect.
|
|
5538
|
-
|
|
5566
|
+
if (effect.options.triggerMethod === "not-same") {
|
|
5567
|
+
if (isSame) {
|
|
5568
|
+
return;
|
|
5569
|
+
}
|
|
5570
|
+
if (effect.scheduler) {
|
|
5571
|
+
effect.scheduler();
|
|
5572
|
+
}
|
|
5573
|
+
else {
|
|
5574
|
+
effect.run();
|
|
5575
|
+
}
|
|
5539
5576
|
}
|
|
5540
|
-
else {
|
|
5541
|
-
effect.
|
|
5577
|
+
else if (effect.options.triggerMethod === "set") {
|
|
5578
|
+
if (effect.scheduler) {
|
|
5579
|
+
effect.scheduler();
|
|
5580
|
+
}
|
|
5581
|
+
else {
|
|
5582
|
+
effect.run();
|
|
5583
|
+
}
|
|
5542
5584
|
}
|
|
5543
5585
|
});
|
|
5544
5586
|
}
|
|
5545
5587
|
}
|
|
5546
|
-
track(target,
|
|
5588
|
+
track(target, _type, key) {
|
|
5547
5589
|
if (!this.activeEffect)
|
|
5548
5590
|
return;
|
|
5549
5591
|
let depsMap = this.targetMap.get(target);
|
|
@@ -8225,14 +8267,39 @@ System.register('Utils', [], (function (exports) {
|
|
|
8225
8267
|
/**
|
|
8226
8268
|
* 自定义的动态响应对象
|
|
8227
8269
|
* @example
|
|
8228
|
-
*
|
|
8229
|
-
*
|
|
8230
|
-
*
|
|
8270
|
+
* const vue = new Utils.Vue();
|
|
8271
|
+
* const reactive = vue.reactive({
|
|
8272
|
+
* name: "",
|
|
8273
|
+
* });
|
|
8274
|
+
* vue.watch(()=>reactive.name, (newValue, oldValue)=>{
|
|
8231
8275
|
* console.log("newValue ==> " + newValue);
|
|
8232
8276
|
* console.log("oldValue ==> " + oldValue);
|
|
8233
8277
|
* })
|
|
8234
|
-
*
|
|
8235
|
-
* >
|
|
8278
|
+
* reactive.name = "测试";
|
|
8279
|
+
* > newValue ==> 测试
|
|
8280
|
+
* > oldValue ==>
|
|
8281
|
+
* reactive.name = "null";
|
|
8282
|
+
* > newValue ==> null
|
|
8283
|
+
* > oldValue ==> 测试
|
|
8284
|
+
* reactive.name = "null";
|
|
8285
|
+
* @example
|
|
8286
|
+
* const vue = new Utils.Vue();
|
|
8287
|
+
* const reactive = vue.reactive({
|
|
8288
|
+
* name: "",
|
|
8289
|
+
* });
|
|
8290
|
+
* vue.watch(()=>reactive.name, (newValue, oldValue)=>{
|
|
8291
|
+
* console.log("newValue ==> " + newValue);
|
|
8292
|
+
* console.log("oldValue ==> " + oldValue);
|
|
8293
|
+
* },{
|
|
8294
|
+
* triggerMethod: "set",
|
|
8295
|
+
* })
|
|
8296
|
+
* reactive.name = "测试";
|
|
8297
|
+
* > newValue ==> 测试
|
|
8298
|
+
* > oldValue ==>
|
|
8299
|
+
* reactive.name = "测试";
|
|
8300
|
+
* > newValue ==> 测试
|
|
8301
|
+
* > oldValue ==> 测试
|
|
8302
|
+
*
|
|
8236
8303
|
*/
|
|
8237
8304
|
Vue = Vue;
|
|
8238
8305
|
ModuleRaid = ModuleRaid;
|
|
@@ -8309,10 +8376,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
8309
8376
|
}
|
|
8310
8377
|
/**
|
|
8311
8378
|
* 判断页面中是否存在`worker-src`的CSP规则
|
|
8379
|
+
* @param timeout 超时时间,默认为`1500ms`
|
|
8312
8380
|
*/
|
|
8313
|
-
hasWorkerCSP() {
|
|
8381
|
+
hasWorkerCSP(timeout = 1500) {
|
|
8314
8382
|
return new Promise((resolve) => {
|
|
8315
8383
|
let flag = true;
|
|
8384
|
+
let timeId = void 0;
|
|
8385
|
+
let worker = void 0;
|
|
8316
8386
|
let workerBlobUrl = void 0;
|
|
8317
8387
|
const workerJs = /*js*/ `
|
|
8318
8388
|
(() => {
|
|
@@ -8328,11 +8398,26 @@ System.register('Utils', [], (function (exports) {
|
|
|
8328
8398
|
}
|
|
8329
8399
|
);
|
|
8330
8400
|
})();`;
|
|
8401
|
+
/**
|
|
8402
|
+
* 返回结果
|
|
8403
|
+
*/
|
|
8404
|
+
const finishCallBack = () => {
|
|
8405
|
+
clearTimeout(timeId);
|
|
8406
|
+
if (worker != null) {
|
|
8407
|
+
worker.terminate();
|
|
8408
|
+
}
|
|
8409
|
+
// 释放
|
|
8410
|
+
if (typeof workerBlobUrl === "string") {
|
|
8411
|
+
globalThis.URL.revokeObjectURL(workerBlobUrl);
|
|
8412
|
+
workerBlobUrl = void 0;
|
|
8413
|
+
}
|
|
8414
|
+
resolve(flag);
|
|
8415
|
+
};
|
|
8331
8416
|
try {
|
|
8332
8417
|
const workerScript = new Blob([workerJs], {
|
|
8333
8418
|
type: "application/javascript",
|
|
8334
8419
|
});
|
|
8335
|
-
workerBlobUrl =
|
|
8420
|
+
workerBlobUrl = globalThis.URL.createObjectURL(workerScript);
|
|
8336
8421
|
// @ts-expect-error
|
|
8337
8422
|
if (globalThis.trustedTypes && typeof globalThis.trustedTypes.createPolicy === "function") {
|
|
8338
8423
|
// 使用这个后虽然不报错,但是仍会有blob错误
|
|
@@ -8344,25 +8429,27 @@ System.register('Utils', [], (function (exports) {
|
|
|
8344
8429
|
});
|
|
8345
8430
|
workerBlobUrl = workerPolicy.createScriptURL(workerBlobUrl);
|
|
8346
8431
|
}
|
|
8347
|
-
|
|
8432
|
+
worker = new Worker(workerBlobUrl);
|
|
8348
8433
|
worker.onmessage = (data) => {
|
|
8349
8434
|
if (data.data.success) {
|
|
8350
8435
|
flag = false;
|
|
8436
|
+
finishCallBack();
|
|
8351
8437
|
}
|
|
8352
8438
|
};
|
|
8353
|
-
setTimeout(() => {
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
}, 500);
|
|
8439
|
+
timeId = setTimeout(() => {
|
|
8440
|
+
finishCallBack();
|
|
8441
|
+
}, timeout);
|
|
8357
8442
|
worker.postMessage("test");
|
|
8358
8443
|
}
|
|
8359
8444
|
catch {
|
|
8360
8445
|
flag = true;
|
|
8446
|
+
finishCallBack();
|
|
8361
8447
|
}
|
|
8362
8448
|
finally {
|
|
8363
8449
|
// 释放
|
|
8364
8450
|
if (typeof workerBlobUrl === "string") {
|
|
8365
8451
|
globalThis.URL.revokeObjectURL(workerBlobUrl);
|
|
8452
|
+
workerBlobUrl = void 0;
|
|
8366
8453
|
}
|
|
8367
8454
|
}
|
|
8368
8455
|
});
|