Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the way to get the tmp element (#115) #116

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading