Skip to content

Commit

Permalink
fix: fix the way to get the tmp element (#115) (#116)
Browse files Browse the repository at this point in the history
* fix: fix the way to get the tmp element (#115)

* test: fix ci issues
  • Loading branch information
nekocode authored Aug 6, 2024
1 parent 43574e8 commit b00dbcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Use Node.js 12
- name: Use Node.js 16
uses: actions/setup-node@v2
with:
node-version: 12
node-version: 16
- name: ci
run: |
npm install
npm install --force
npm run ci
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 b00dbcf

Please sign in to comment.