* @function LevelRenderer.Tool.Color.prototype.normalize * @description 颜色规范化。 * @param {string} color - 颜色。 * @returns {string} 规范化后的颜色
(color)
| 618 | * @returns {string} 规范化后的颜色 |
| 619 | */ |
| 620 | normalize(color) { |
| 621 | // 颜色名 |
| 622 | if (this._nameColors[color]) { |
| 623 | color = this._nameColors[color]; |
| 624 | } |
| 625 | // 去掉空格 |
| 626 | color = this.trim(color); |
| 627 | // hsv与hsb等价 |
| 628 | color = color.replace(/hsv/i, 'hsb'); |
| 629 | // rgb转为rrggbb |
| 630 | if (/^#[\da-f]{3}$/i.test(color)) { |
| 631 | color = parseInt(color.slice(1), 16); |
| 632 | var r = (color & 0xf00) << 8; |
| 633 | var g = (color & 0xf0) << 4; |
| 634 | var b = color & 0xf; |
| 635 | |
| 636 | color = '#' + ((1 << 24) + (r << 4) + r + (g << 4) + g + (b << 4) + b).toString(16).slice(1); |
| 637 | } |
| 638 | // 或者使用以下正则替换,不过 chrome 下性能相对差点 |
| 639 | // color = color.replace(/^#([\da-f])([\da-f])([\da-f])$/i, '#$1$1$2$2$3$3'); |
| 640 | return color; |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * @function LevelRenderer.Tool.Color.prototype.lift |
no test coverage detected