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