diff --git a/src/avatar/index.js b/src/avatar/index.js deleted file mode 100644 index 5c849bc..0000000 --- a/src/avatar/index.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * - * @authors yutent (yutent@doui.cc) - * @date 2017-03-17 20:55:57 - * - */ - -'use strict' - -function arraySum(arr) { - var sum = 0 - arr.forEach(function(it) { - sum += +it - }) - return sum -} - -// 1216fc0c668c09ade029ceae6db87f97cf560e21 -export const create = (hash, size) => { - if (!hash) return this.defafultImg - - if (!size || size < 100) { - size = 100 - } - - var cv = document.createElement('canvas'), - ct = cv.getContext('2d'), - bg = hash.slice(-3), - color = hash.slice(-9, -6), - fixColor = color, - lens = hash.slice(0, 8).match(/([\w]{1})/g), - pos1 = hash.slice(8, 16).match(/([\w]{1})/g), - pos2 = hash.slice(16, 24).match(/([\w]{1})/g), - step = size / 10 - - cv.width = size - cv.height = size - - lens = lens.map(c => { - c = parseInt(c, 16) - return c % 8 - }) - pos1 = pos1.map(c => { - c = parseInt(c, 16) - return c % 4 - }) - pos2 = pos2.map(c => { - c = parseInt(c, 16) - return c % 4 - }) - fixColor = arraySum(lens) > 32 ? bg : color - - ct.fillStyle = '#' + bg - ct.fillRect(0, 0, size, size) - - for (var i = 1; i < 9; i++) { - var xl = lens[i - 1], - xp1 = pos1[i - 1], - xp2 = pos2[i - 1] - - if (xl + xp1 > 8) { - xl = 8 - xp1 - } - ct.fillStyle = '#' + color - ct.fillRect((xp1 + 1) * step, i * step, xl * step, step) - - ct.fillStyle = '#' + color - ct.fillRect((9 - xp1 - xl) * step, i * step, xl * step, step) - - ct.fillStyle = '#' + fixColor - ct.fillRect((xp2 + 1) * step, i * step, step, step) - - ct.fillStyle = '#' + fixColor - ct.fillRect((8 - xp2) * step, i * step, step, step) - } - - return cv.toDataURL() -} diff --git a/src/avatar/index.wc b/src/avatar/index.wc index cbc9c35..2241413 100644 --- a/src/avatar/index.wc +++ b/src/avatar/index.wc @@ -14,8 +14,7 @@ line-height: 1; font-size: var(--size, 32px); border-radius: 4px; - background: nth($cp, 2); - color: nth($cd, 1); + color: #fff; user-select: none; -moz-user-select: none; @@ -40,6 +39,28 @@ } } +:host([color='red']) { + background: #ff5061; +} +:host([color='teal']) { + background: #3fc2a7; +} +:host([color='purple']) { + background: #ac61ce; +} +:host([color='green']) { + background: #58d68d; +} +:host([color='orange']) { + background: #ffb618; +} +:host([color='dark']) { + background: #62778d; +} +:host([color='blue']) { + background: #66b1ff; +} + :host([size='large']) { width: 50px; height: 50px; @@ -64,6 +85,82 @@