zhengyiming
3 小时以前 fd06689a59dcdaf03d8f98d9531ad6f2c2b258c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * @Author: ShawnPhang
 * @Date: 2023-04-26 11:30:10
 * @Description:
 * @LastEditors: ShawnPhang <https://m.palxp.cn>
 * @LastEditTime: 2023-11-28 11:03:14
 */
export const parseBackgroundValue = (value: string): string => {
  if (value.startsWith('#')) return '纯色';
  if (value.startsWith('linear-gradient')) return '渐变';
  return '图案';
};
 
interface Stop {
  color: string;
  offset: number;
}
 
export const toGradientString = (angle: number, stops: Stop[]) => {
  const s: string[] = [];
  stops.forEach((stop) => {
    s.push(`${stop.color} ${stop.offset * 100}%`);
  });
  return `linear-gradient(${angle}deg, ${s.join(',')})`;
};
 
/**
 * 显示全局提示
 * @param content
 * @param tooltipVisible
 * @returns
 */
export function toolTip(content: string) {
  const tooltip = drawTooltip(content);
  document.body.appendChild(tooltip);
  setTimeout(() => tooltip?.parentNode?.removeChild(tooltip), 2000);
}
 
function drawTooltip(content: string, tooltipVisible = true) {
  const tooltip: any = document.createElement('div');
  tooltip.id = 'color-pipette-tooltip-container';
  tooltip.innerHTML = content;
  tooltip.style = `
    position: fixed;
    left: 50%;
    top: 9%;
    z-index: 10002;
    display: ${tooltipVisible ? 'flex' : 'none'};
    align-items: center;
    background-color: rgba(0,0,0,0.4);
    padding: 6px 12px;
    border-radius: 4px;
    color: #fff;
    font-size: 18px;
    pointer-events: none;
  `;
  return tooltip;
}