@whitesev/utils 2.11.2 → 2.11.3

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.
@@ -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.2";
245
+ const version = "2.11.3";
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
- const value = Math.floor(Number(rgbcItemValue) * (1 - level));
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
- const value = Math.floor(255 - rgbcItemValue * level + rgbcItemValue);
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]);