MCPcopy
hub / github.com/plait-board/drawnix / removeHexAlpha

Function removeHexAlpha

packages/drawnix/src/utils/color.ts:46–62  ·  view source on GitHub ↗
(hexColor: string)

Source from the content-addressed store, hash-verified

44}
45
46export function removeHexAlpha(hexColor: string) {
47 // 移除可能存在的 # 前缀,并转换为大写
48 const hexColorClone = hexColor.replace(/^#/, '').toUpperCase();
49
50 if (hexColorClone.length === 8) {
51 // 8位十六进制,移除最后两位
52 return '#' + hexColorClone.slice(0, 6);
53 } else if (hexColorClone.length === 4) {
54 // 4位十六进制(简写形式),移除最后一位
55 return '#' + hexColorClone.slice(0, 3);
56 } else if (hexColorClone.length === 6 || hexColorClone.length === 3) {
57 // 已经是标准的 6 位或 3 位形式,直接返回
58 return '#' + hexColorClone;
59 } else {
60 return hexColor;
61 }
62}
63
64export function isTransparent(color?: string) {
65 return color === TRANSPARENT;

Callers 7

color-picker.tsxFile · 0.90
PopupStrokeButtonFunction · 0.90
PopupToolbarFunction · 0.90
PopupFillButtonFunction · 0.90
setFillColorOpacityFunction · 0.90
setStrokeColorOpacityFunction · 0.90
setTextColorOpacityFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected