mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-14 08:51:26 +08:00
240210a281
* feat: qrcode * chore: code clean * feat: New Component Qr-Code (#38891) * feat: QrCode * fix * fix * fix: fix bug * fix: fix bug * fix * fix * fix * delete * delete * test case * fix lint * bundlesize * demo * fix: fix test * remove dep * update snap * en docs * refactor: rename tests dir * Update components/qr-code/demo/base.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/base.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/download.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/download.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/download.tsx Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/logo.md Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/index.tsx Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qr-code/demo/logo.md Co-authored-by: MadCcc <1075746765@qq.com> * rename * fix * adjust text * rename * fix title * rename * rename * fix: snap * fix * bundlesize * update demo * update docs * add demo * add docs * add docs * test: add warning * update demo * bundlesize * update test case * update demo * feat: add onRefresh、add status * fix: fix demo * fix: fix demo * add locale * add locale * add test case * update snap * fix demo * update demo * update demo * update demo * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/interface.ts Co-authored-by: MadCcc <1075746765@qq.com> * Update components/qrcode/style/index.ts Co-authored-by: MadCcc <1075746765@qq.com> * fix * Update components/qrcode/index.tsx Co-authored-by: MadCcc <1075746765@qq.com> * fix * fix * fix * add decs * fix * fix * fix type * fix * fix demo * fix lint * fix lint * add test case for bordered * prettier-ignore Co-authored-by: MadCcc <1075746765@qq.com> Co-authored-by: 栗嘉男 <lijianan@lijianandeMacBook-Pro.local>
30 lines
940 B
TypeScript
30 lines
940 B
TypeScript
import { TinyColor } from '@ctrl/tinycolor';
|
|
|
|
function isStableColor(color: number): boolean {
|
|
return color >= 0 && color <= 255;
|
|
}
|
|
|
|
function getAlphaColor(frontColor: string, backgroundColor: string): string {
|
|
const { r: fR, g: fG, b: fB, a: originAlpha } = new TinyColor(frontColor).toRgb();
|
|
if (originAlpha < 1) {
|
|
return frontColor;
|
|
}
|
|
|
|
const { r: bR, g: bG, b: bB } = new TinyColor(backgroundColor).toRgb();
|
|
|
|
for (let fA = 0.01; fA <= 1; fA += 0.01) {
|
|
const r = Math.round((fR - bR * (1 - fA)) / fA);
|
|
const g = Math.round((fG - bG * (1 - fA)) / fA);
|
|
const b = Math.round((fB - bB * (1 - fA)) / fA);
|
|
if (isStableColor(r) && isStableColor(g) && isStableColor(b)) {
|
|
return new TinyColor({ r, g, b, a: Math.round(fA * 100) / 100 }).toRgbString();
|
|
}
|
|
}
|
|
|
|
// fallback
|
|
/* istanbul ignore next */
|
|
return new TinyColor({ r: fR, g: fG, b: fB, a: 1 }).toRgbString();
|
|
}
|
|
|
|
export default getAlphaColor;
|