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