@whitesev/utils 2.11.2 → 2.11.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/dist/index.amd.js +73 -3
- 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 +73 -3
- 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 +73 -3
- 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 +73 -3
- 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 +73 -3
- 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 +73 -3
- 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 +20 -0
- package/package.json +1 -1
- package/src/ColorConversion.ts +18 -2
- package/src/Utils.ts +72 -0
package/dist/index.umd.js
CHANGED
|
@@ -243,7 +243,7 @@
|
|
|
243
243
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
244
244
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
245
245
|
|
|
246
|
-
const version = "2.11.
|
|
246
|
+
const version = "2.11.4";
|
|
247
247
|
|
|
248
248
|
/* eslint-disable */
|
|
249
249
|
// ==UserScript==
|
|
@@ -1337,10 +1337,19 @@
|
|
|
1337
1337
|
if (isNaN(level)) {
|
|
1338
1338
|
throw new TypeError(`输入错误的level:${level}`);
|
|
1339
1339
|
}
|
|
1340
|
+
if (level < 0 || level > 1) {
|
|
1341
|
+
throw new TypeError(`level must between 0~1.0: ${level}`);
|
|
1342
|
+
}
|
|
1340
1343
|
const rgbc = this.hexToRgb(color);
|
|
1341
1344
|
for (let index = 0; index < 3; index++) {
|
|
1342
1345
|
const rgbcItemValue = rgbc[index];
|
|
1343
|
-
|
|
1346
|
+
let value = Math.floor(Number(rgbcItemValue) * (1 - level));
|
|
1347
|
+
if (value > 255) {
|
|
1348
|
+
value = 255;
|
|
1349
|
+
}
|
|
1350
|
+
else if (value < 0) {
|
|
1351
|
+
value = 0;
|
|
1352
|
+
}
|
|
1344
1353
|
Reflect.set(rgbc, index, value);
|
|
1345
1354
|
}
|
|
1346
1355
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
@@ -1360,10 +1369,19 @@
|
|
|
1360
1369
|
if (isNaN(level)) {
|
|
1361
1370
|
throw new TypeError(`输入错误的level:${level}`);
|
|
1362
1371
|
}
|
|
1372
|
+
if (level < 0 || level > 1) {
|
|
1373
|
+
throw new TypeError(`level must between 0~1.0: ${level}`);
|
|
1374
|
+
}
|
|
1363
1375
|
const rgbc = this.hexToRgb(color);
|
|
1364
1376
|
for (let index = 0; index < 3; index++) {
|
|
1365
1377
|
const rgbcItemValue = Number(rgbc[index]);
|
|
1366
|
-
|
|
1378
|
+
let value = Math.floor(255 - rgbcItemValue * level + rgbcItemValue);
|
|
1379
|
+
if (value > 255) {
|
|
1380
|
+
value = 255;
|
|
1381
|
+
}
|
|
1382
|
+
else if (value < 0) {
|
|
1383
|
+
value = 0;
|
|
1384
|
+
}
|
|
1367
1385
|
Reflect.set(rgbc, index, value);
|
|
1368
1386
|
}
|
|
1369
1387
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
@@ -8468,6 +8486,58 @@
|
|
|
8468
8486
|
}
|
|
8469
8487
|
});
|
|
8470
8488
|
}
|
|
8489
|
+
calcPositionDistance(...args) {
|
|
8490
|
+
let position = {
|
|
8491
|
+
x: 0,
|
|
8492
|
+
y: 0,
|
|
8493
|
+
};
|
|
8494
|
+
let otherPosition = {
|
|
8495
|
+
x: 0,
|
|
8496
|
+
y: 0,
|
|
8497
|
+
};
|
|
8498
|
+
if (typeof args[0] === "object" && args[0] != null && typeof args[1] === "object" && args[1] != null) {
|
|
8499
|
+
position = args[0];
|
|
8500
|
+
otherPosition = args[1];
|
|
8501
|
+
}
|
|
8502
|
+
else if (args.length === 4) {
|
|
8503
|
+
position = {
|
|
8504
|
+
x: args[0],
|
|
8505
|
+
y: args[1],
|
|
8506
|
+
};
|
|
8507
|
+
otherPosition = {
|
|
8508
|
+
x: args[2],
|
|
8509
|
+
y: args[3],
|
|
8510
|
+
};
|
|
8511
|
+
}
|
|
8512
|
+
else {
|
|
8513
|
+
throw new Error("Invalid arguments");
|
|
8514
|
+
}
|
|
8515
|
+
if (typeof position.x === "string") {
|
|
8516
|
+
position.x = Number(position.x);
|
|
8517
|
+
}
|
|
8518
|
+
if (isNaN(position.x)) {
|
|
8519
|
+
throw new Error(`Invalid x: ${position.x}`);
|
|
8520
|
+
}
|
|
8521
|
+
if (typeof position.y === "string") {
|
|
8522
|
+
position.y = Number(position.y);
|
|
8523
|
+
}
|
|
8524
|
+
if (isNaN(position.y)) {
|
|
8525
|
+
throw new Error(`Invalid y: ${position.y}`);
|
|
8526
|
+
}
|
|
8527
|
+
if (typeof otherPosition.x === "string") {
|
|
8528
|
+
otherPosition.x = Number(otherPosition.x);
|
|
8529
|
+
}
|
|
8530
|
+
if (isNaN(otherPosition.x)) {
|
|
8531
|
+
throw new Error(`Invalid x: ${otherPosition.x}`);
|
|
8532
|
+
}
|
|
8533
|
+
if (typeof otherPosition.y === "string") {
|
|
8534
|
+
otherPosition.y = Number(otherPosition.y);
|
|
8535
|
+
}
|
|
8536
|
+
if (isNaN(otherPosition.y)) {
|
|
8537
|
+
throw new Error(`Invalid y: ${otherPosition.y}`);
|
|
8538
|
+
}
|
|
8539
|
+
return Math.sqrt(Math.pow(otherPosition.x - position.x, 2) + Math.pow(otherPosition.y - position.y, 2));
|
|
8540
|
+
}
|
|
8471
8541
|
}
|
|
8472
8542
|
const utils = new Utils();
|
|
8473
8543
|
|