@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.esm.js
CHANGED
|
@@ -237,7 +237,7 @@ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
|
237
237
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
238
238
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
239
239
|
|
|
240
|
-
const version = "2.11.
|
|
240
|
+
const version = "2.11.4";
|
|
241
241
|
|
|
242
242
|
/* eslint-disable */
|
|
243
243
|
// ==UserScript==
|
|
@@ -1331,10 +1331,19 @@ class ColorConversion {
|
|
|
1331
1331
|
if (isNaN(level)) {
|
|
1332
1332
|
throw new TypeError(`输入错误的level:${level}`);
|
|
1333
1333
|
}
|
|
1334
|
+
if (level < 0 || level > 1) {
|
|
1335
|
+
throw new TypeError(`level must between 0~1.0: ${level}`);
|
|
1336
|
+
}
|
|
1334
1337
|
const rgbc = this.hexToRgb(color);
|
|
1335
1338
|
for (let index = 0; index < 3; index++) {
|
|
1336
1339
|
const rgbcItemValue = rgbc[index];
|
|
1337
|
-
|
|
1340
|
+
let value = Math.floor(Number(rgbcItemValue) * (1 - level));
|
|
1341
|
+
if (value > 255) {
|
|
1342
|
+
value = 255;
|
|
1343
|
+
}
|
|
1344
|
+
else if (value < 0) {
|
|
1345
|
+
value = 0;
|
|
1346
|
+
}
|
|
1338
1347
|
Reflect.set(rgbc, index, value);
|
|
1339
1348
|
}
|
|
1340
1349
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
@@ -1354,10 +1363,19 @@ class ColorConversion {
|
|
|
1354
1363
|
if (isNaN(level)) {
|
|
1355
1364
|
throw new TypeError(`输入错误的level:${level}`);
|
|
1356
1365
|
}
|
|
1366
|
+
if (level < 0 || level > 1) {
|
|
1367
|
+
throw new TypeError(`level must between 0~1.0: ${level}`);
|
|
1368
|
+
}
|
|
1357
1369
|
const rgbc = this.hexToRgb(color);
|
|
1358
1370
|
for (let index = 0; index < 3; index++) {
|
|
1359
1371
|
const rgbcItemValue = Number(rgbc[index]);
|
|
1360
|
-
|
|
1372
|
+
let value = Math.floor(255 - rgbcItemValue * level + rgbcItemValue);
|
|
1373
|
+
if (value > 255) {
|
|
1374
|
+
value = 255;
|
|
1375
|
+
}
|
|
1376
|
+
else if (value < 0) {
|
|
1377
|
+
value = 0;
|
|
1378
|
+
}
|
|
1361
1379
|
Reflect.set(rgbc, index, value);
|
|
1362
1380
|
}
|
|
1363
1381
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
@@ -8462,6 +8480,58 @@ class Utils {
|
|
|
8462
8480
|
}
|
|
8463
8481
|
});
|
|
8464
8482
|
}
|
|
8483
|
+
calcPositionDistance(...args) {
|
|
8484
|
+
let position = {
|
|
8485
|
+
x: 0,
|
|
8486
|
+
y: 0,
|
|
8487
|
+
};
|
|
8488
|
+
let otherPosition = {
|
|
8489
|
+
x: 0,
|
|
8490
|
+
y: 0,
|
|
8491
|
+
};
|
|
8492
|
+
if (typeof args[0] === "object" && args[0] != null && typeof args[1] === "object" && args[1] != null) {
|
|
8493
|
+
position = args[0];
|
|
8494
|
+
otherPosition = args[1];
|
|
8495
|
+
}
|
|
8496
|
+
else if (args.length === 4) {
|
|
8497
|
+
position = {
|
|
8498
|
+
x: args[0],
|
|
8499
|
+
y: args[1],
|
|
8500
|
+
};
|
|
8501
|
+
otherPosition = {
|
|
8502
|
+
x: args[2],
|
|
8503
|
+
y: args[3],
|
|
8504
|
+
};
|
|
8505
|
+
}
|
|
8506
|
+
else {
|
|
8507
|
+
throw new Error("Invalid arguments");
|
|
8508
|
+
}
|
|
8509
|
+
if (typeof position.x === "string") {
|
|
8510
|
+
position.x = Number(position.x);
|
|
8511
|
+
}
|
|
8512
|
+
if (isNaN(position.x)) {
|
|
8513
|
+
throw new Error(`Invalid x: ${position.x}`);
|
|
8514
|
+
}
|
|
8515
|
+
if (typeof position.y === "string") {
|
|
8516
|
+
position.y = Number(position.y);
|
|
8517
|
+
}
|
|
8518
|
+
if (isNaN(position.y)) {
|
|
8519
|
+
throw new Error(`Invalid y: ${position.y}`);
|
|
8520
|
+
}
|
|
8521
|
+
if (typeof otherPosition.x === "string") {
|
|
8522
|
+
otherPosition.x = Number(otherPosition.x);
|
|
8523
|
+
}
|
|
8524
|
+
if (isNaN(otherPosition.x)) {
|
|
8525
|
+
throw new Error(`Invalid x: ${otherPosition.x}`);
|
|
8526
|
+
}
|
|
8527
|
+
if (typeof otherPosition.y === "string") {
|
|
8528
|
+
otherPosition.y = Number(otherPosition.y);
|
|
8529
|
+
}
|
|
8530
|
+
if (isNaN(otherPosition.y)) {
|
|
8531
|
+
throw new Error(`Invalid y: ${otherPosition.y}`);
|
|
8532
|
+
}
|
|
8533
|
+
return Math.sqrt(Math.pow(otherPosition.x - position.x, 2) + Math.pow(otherPosition.y - position.y, 2));
|
|
8534
|
+
}
|
|
8465
8535
|
}
|
|
8466
8536
|
const utils = new Utils();
|
|
8467
8537
|
|