Skip to content

Commit

Permalink
fix: fix the way to get the tmp element (antvis#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocode committed Aug 1, 2024
1 parent c499a30 commit febc1f3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/color/torgb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ const RGB_REG = /rgba?\(([\s.,0-9]+)\)/;
* 创建辅助 tag 取颜色
* @returns
*/
function createTmp(): HTMLElement {
const i = document.createElement('i');
function getTmp(): HTMLElement {
let i = document.getElementById('antv-web-colour-picker');
if (i) {
return i;
}
i = document.createElement('i');
i.id = 'antv-web-colour-picker';
i.title = 'Web Colour Picker';
i.style.display = 'none';
document.body.appendChild(i);
return i;
}

let iEl: HTMLElement;

/**
* 将颜色转换到 rgb 的格式
* @param {color} color 颜色
Expand All @@ -28,10 +31,7 @@ function toRGBString(color: string): string {
return color;
}

if (!iEl) {
// 防止防止在页头报错
iEl = createTmp();
}
const iEl = getTmp();

iEl.style.color = color;

Expand Down

0 comments on commit febc1f3

Please sign in to comment.