@aifuxi/semi-theme-default 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +128 -1
- package/dist/SBOM.spdx.json +4 -4
- package/dist/ai-chat-dialogue.css +20 -20
- package/dist/ai-chat-input.css +31 -31
- package/dist/anchor.css +9 -9
- package/dist/audio-player.css +4 -4
- package/dist/auto-complete.css +5 -5
- package/dist/avatar.css +41 -41
- package/dist/badge.css +4 -4
- package/dist/base.css +29 -2
- package/dist/breadcrumb.css +11 -11
- package/dist/button.css +9 -9
- package/dist/calendar.css +34 -34
- package/dist/card.css +14 -14
- package/dist/cascader.css +23 -23
- package/dist/chat.css +12 -12
- package/dist/checkbox.css +14 -14
- package/dist/code-highlight.css +1 -1
- package/dist/collapse.css +7 -7
- package/dist/color-picker.css +1 -1
- package/dist/colors/baseline.mjs +675 -0
- package/dist/colors/index.d.mts +29 -0
- package/dist/colors/index.mjs +10 -0
- package/dist/colors/palette.d.mts +44 -0
- package/dist/colors/palette.mjs +273 -0
- package/dist/colors/theme.mjs +102 -0
- package/dist/date-picker.css +32 -32
- package/dist/descriptions.css +26 -26
- package/dist/divider.css +1 -1
- package/dist/dropdown.css +7 -7
- package/dist/empty.css +1 -1
- package/dist/feedback.css +5 -5
- package/dist/float-button.css +3 -3
- package/dist/form.css +15 -15
- package/dist/highlight.css +1 -1
- package/dist/hot-keys.css +6 -6
- package/dist/image.css +6 -6
- package/dist/index.css +825 -794
- package/dist/input.css +26 -26
- package/dist/json-viewer.css +2 -2
- package/dist/list.css +3 -3
- package/dist/markdown-render.css +1 -1
- package/dist/modal.css +5 -5
- package/dist/navigation.css +16 -16
- package/dist/notification.css +14 -14
- package/dist/pagination.css +17 -17
- package/dist/popconfirm.css +4 -4
- package/dist/popover.css +3 -3
- package/dist/progress.css +2 -2
- package/dist/radio.css +21 -21
- package/dist/rating.css +2 -2
- package/dist/scroll-list.css +8 -8
- package/dist/select.css +23 -23
- package/dist/shared/foundation-input-textarea.css +7 -7
- package/dist/side-sheet.css +8 -8
- package/dist/sidebar.css +49 -49
- package/dist/slider.css +5 -5
- package/dist/steps.css +41 -41
- package/dist/style-dependencies.json +17 -1
- package/dist/switch.css +2 -2
- package/dist/table.css +9 -9
- package/dist/tabs.css +15 -15
- package/dist/tag-input.css +14 -14
- package/dist/tag.css +7 -7
- package/dist/time-picker.css +3 -3
- package/dist/timeline.css +6 -6
- package/dist/toast.css +4 -4
- package/dist/tooltip.css +4 -4
- package/dist/transfer.css +16 -16
- package/dist/tree-select.css +19 -19
- package/dist/tree.css +4 -4
- package/dist/typography.css +40 -36
- package/dist/upload.css +29 -29
- package/dist/user-guide.css +12 -12
- package/dist/video-player.css +12 -12
- package/package.json +6 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ColorPalette } from './palette.mjs';
|
|
2
|
+
export { generateColorScale, generateColorPalette } from './palette.mjs';
|
|
3
|
+
export type {
|
|
4
|
+
ColorMode,
|
|
5
|
+
ColorScale,
|
|
6
|
+
ColorPalette,
|
|
7
|
+
ColorPaletteName,
|
|
8
|
+
ColorGenerationOptions,
|
|
9
|
+
} from './palette.mjs';
|
|
10
|
+
|
|
11
|
+
/** 可以直接序列化为 JSON 的双模式主题;RGB 色盘与语义变量保持 Semi 格式。 */
|
|
12
|
+
export interface ColorTheme {
|
|
13
|
+
readonly version: 1;
|
|
14
|
+
readonly brand: string;
|
|
15
|
+
readonly palette: Readonly<{ light: ColorPalette; dark: ColorPalette }>;
|
|
16
|
+
readonly variables: Readonly<{
|
|
17
|
+
light: Readonly<Record<string, string>>;
|
|
18
|
+
dark: Readonly<Record<string, string>>;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 颜色只支持不透明 #RGB/#RRGGBB;整盘品牌色必须具有非零饱和度。 */
|
|
23
|
+
export function createColorTheme(options: { brand: string }): ColorTheme;
|
|
24
|
+
|
|
25
|
+
/** 调用方明确选择全局或局部模式边界;返回普通 CSS,不访问 DOM 或注入样式。 */
|
|
26
|
+
export function colorThemeToCss(
|
|
27
|
+
theme: ColorTheme,
|
|
28
|
+
options: { selectors: { light: string; dark: string } },
|
|
29
|
+
): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import baseline from './baseline.mjs';
|
|
2
|
+
import { buildColorTheme } from './theme.mjs';
|
|
3
|
+
|
|
4
|
+
export { generateColorScale, generateColorPalette } from './palette.mjs';
|
|
5
|
+
export { colorThemeToCss } from './theme.mjs';
|
|
6
|
+
|
|
7
|
+
/** 创建深浅模式颜色主题;默认组件 CSS 不会调用此函数或重新生成默认色盘。 */
|
|
8
|
+
export function createColorTheme(options) {
|
|
9
|
+
return buildColorTheme(options, baseline);
|
|
10
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** 与 Semi 色阶一致的公开模式,不读取系统或 DOM 状态。 */
|
|
2
|
+
export type ColorMode = 'light' | 'dark';
|
|
3
|
+
/** 十级色阶按 0…9 排列,每一级都是小写六位不透明 HEX。 */
|
|
4
|
+
export type ColorScale = readonly [
|
|
5
|
+
string,
|
|
6
|
+
string,
|
|
7
|
+
string,
|
|
8
|
+
string,
|
|
9
|
+
string,
|
|
10
|
+
string,
|
|
11
|
+
string,
|
|
12
|
+
string,
|
|
13
|
+
string,
|
|
14
|
+
string,
|
|
15
|
+
];
|
|
16
|
+
/** 色盘包含十六组基础色以及独立品牌色阶。 */
|
|
17
|
+
export type ColorPaletteName =
|
|
18
|
+
| 'red'
|
|
19
|
+
| 'pink'
|
|
20
|
+
| 'purple'
|
|
21
|
+
| 'violet'
|
|
22
|
+
| 'indigo'
|
|
23
|
+
| 'blue'
|
|
24
|
+
| 'light-blue'
|
|
25
|
+
| 'cyan'
|
|
26
|
+
| 'teal'
|
|
27
|
+
| 'green'
|
|
28
|
+
| 'light-green'
|
|
29
|
+
| 'lime'
|
|
30
|
+
| 'yellow'
|
|
31
|
+
| 'amber'
|
|
32
|
+
| 'orange'
|
|
33
|
+
| 'grey'
|
|
34
|
+
| 'brand';
|
|
35
|
+
/** 每组命名色均包含完整的十级梯度。 */
|
|
36
|
+
export type ColorPalette = Readonly<Record<ColorPaletteName, ColorScale>>;
|
|
37
|
+
/** 省略 mode 时生成浅色,非法运行时取值抛出 TypeError。 */
|
|
38
|
+
export interface ColorGenerationOptions {
|
|
39
|
+
mode?: ColorMode;
|
|
40
|
+
}
|
|
41
|
+
/** 生成单色阶;仅接受 #RGB/#RRGGBB,非法颜色抛 TypeError。 */
|
|
42
|
+
export function generateColorScale(color: string, options?: ColorGenerationOptions): ColorScale;
|
|
43
|
+
/** 生成完整色盘;无色相品牌色抛 RangeError,其他输入规则与单色阶一致。 */
|
|
44
|
+
export function generateColorPalette(brand: string, options?: ColorGenerationOptions): ColorPalette;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/** DSM 初始色轮的色相、饱和度与明度锚点;不作为默认主题 CSS 的来源。 */
|
|
2
|
+
const wheelAnchors = {
|
|
3
|
+
red: '#f93920',
|
|
4
|
+
pink: '#e91e63',
|
|
5
|
+
purple: '#9c27b0',
|
|
6
|
+
violet: '#6a3ac7',
|
|
7
|
+
indigo: '#3f51b5',
|
|
8
|
+
blue: '#0077fa',
|
|
9
|
+
'light-blue': '#0095ee',
|
|
10
|
+
cyan: '#05a4b6',
|
|
11
|
+
teal: '#00a696',
|
|
12
|
+
green: '#38aa43',
|
|
13
|
+
'light-green': '#7bb63c',
|
|
14
|
+
lime: '#9bd100',
|
|
15
|
+
yellow: '#fac800',
|
|
16
|
+
amber: '#f0b114',
|
|
17
|
+
orange: '#fc8800',
|
|
18
|
+
};
|
|
19
|
+
/** 内部梯度位置;50 对应公开第 0 级,500 对应浅色的品牌锚点。 */
|
|
20
|
+
const scalePositions = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
|
|
21
|
+
|
|
22
|
+
/** 仅解析公开承诺的不透明 HEX,内部始终使用整数 RGB 通道。 */
|
|
23
|
+
function parseHex(value) {
|
|
24
|
+
if (typeof value !== 'string' || !/^#(?:[a-f\d]{3}|[a-f\d]{6})$/i.test(value)) {
|
|
25
|
+
throw new TypeError('颜色必须为 #RGB 或 #RRGGBB 格式');
|
|
26
|
+
}
|
|
27
|
+
return hexToRgb(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 解码已校验或由内部生成的 HEX,不重复执行公开输入格式校验。 */
|
|
31
|
+
function hexToRgb(value) {
|
|
32
|
+
/** 短 HEX 按通道展开,避免浏览器参与颜色解析。 */
|
|
33
|
+
const digits =
|
|
34
|
+
value.length === 4
|
|
35
|
+
? value.slice(1).replace(/./g, /** 展开一位 HEX 通道。 */ (digit) => digit + digit)
|
|
36
|
+
: value.slice(1);
|
|
37
|
+
/** 连续三个字节分别为红、绿、蓝,保持输入通道整数精度。 */
|
|
38
|
+
const packed = Number.parseInt(digits, 16);
|
|
39
|
+
return [packed >> 16, (packed >> 8) & 255, packed & 255];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 校验模式边界;省略时只生成浅色,不访问系统主题。 */
|
|
43
|
+
function readMode(options) {
|
|
44
|
+
/** 模式是调用方唯一可配置的算法参数。 */
|
|
45
|
+
const mode = options?.mode === undefined ? 'light' : options.mode;
|
|
46
|
+
if (mode !== 'light' && mode !== 'dark') throw new TypeError('mode 必须为 light 或 dark');
|
|
47
|
+
return mode;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 将量值裁剪到闭区间;仅用于算法明确要求的饱和度及明度限制。 */
|
|
51
|
+
function clamp(value, lower = 0, upper = 1) {
|
|
52
|
+
return Math.min(Math.max(value, lower), upper);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 归一化循环位置,同时用于色相角度与色轮相邻索引。 */
|
|
56
|
+
function wrap(value, period) {
|
|
57
|
+
return ((value % period) + period) % period;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 将 RGB 转成 HSV;无色相颜色保留 NaN,以维持灰阶分支的计算语义。 */
|
|
61
|
+
function toHsv([red, green, blue]) {
|
|
62
|
+
/** 最大与最小通道之差决定饱和度,最大通道决定明度。 */
|
|
63
|
+
const max = Math.max(red, green, blue);
|
|
64
|
+
/** 最小通道不影响明度,只参与色度差。 */
|
|
65
|
+
const delta = max - Math.min(red, green, blue);
|
|
66
|
+
let hue = Number.NaN;
|
|
67
|
+
if (delta !== 0) {
|
|
68
|
+
if (red === max) hue = (green - blue) / delta;
|
|
69
|
+
if (green === max) hue = 2 + (blue - red) / delta;
|
|
70
|
+
if (blue === max) hue = 4 + (red - green) / delta;
|
|
71
|
+
hue *= 60;
|
|
72
|
+
if (hue < 0) hue += 360;
|
|
73
|
+
}
|
|
74
|
+
return [hue, max === 0 ? 0 : delta / max, max / 255];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 以整数通道生成规范 HEX;取整发生于序列化处,不提前改变 HSV 精度。 */
|
|
78
|
+
function rgbToHex(channels) {
|
|
79
|
+
return (
|
|
80
|
+
'#' +
|
|
81
|
+
channels
|
|
82
|
+
.map(
|
|
83
|
+
/** 将一个 RGB 通道写成两位小写 HEX。 */ (channel) =>
|
|
84
|
+
Math.round(clamp(channel, 0, 255))
|
|
85
|
+
.toString(16)
|
|
86
|
+
.padStart(2, '0'),
|
|
87
|
+
)
|
|
88
|
+
.join('')
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** HSV 的六个扇区分别指定 RGB 通道;运算顺序保留通道取整的一致性。 */
|
|
93
|
+
function hsvToHex(hue, saturation, value) {
|
|
94
|
+
/** HSV 的 V 是相对值;RGB 计算使用 0…255 范围。 */
|
|
95
|
+
const maximum = value * 255;
|
|
96
|
+
if (saturation === 0) return rgbToHex([maximum, maximum, maximum]);
|
|
97
|
+
/** 色相归一化后分成六个 60° 的扇区。 */
|
|
98
|
+
const sector = wrap(hue, 360) / 60;
|
|
99
|
+
/** 小数部分决定两个相邻主色之间的插值。 */
|
|
100
|
+
const fraction = sector - Math.floor(sector);
|
|
101
|
+
/** 最小通道及两个互补插值通道。 */
|
|
102
|
+
const minimum = maximum * (1 - saturation);
|
|
103
|
+
/** 扇区开始时由最大通道递减的中间值。 */
|
|
104
|
+
const descending = maximum * (1 - saturation * fraction);
|
|
105
|
+
/** 扇区开始时由最小通道递增的中间值。 */
|
|
106
|
+
const ascending = maximum * (1 - saturation * (1 - fraction));
|
|
107
|
+
/** 各扇区只是同一组通道的排列,不改变颜色计算参数。 */
|
|
108
|
+
const sectors = [
|
|
109
|
+
[maximum, ascending, minimum],
|
|
110
|
+
[descending, maximum, minimum],
|
|
111
|
+
[minimum, maximum, ascending],
|
|
112
|
+
[minimum, descending, maximum],
|
|
113
|
+
[ascending, minimum, maximum],
|
|
114
|
+
[maximum, minimum, descending],
|
|
115
|
+
];
|
|
116
|
+
return rgbToHex(sectors[Math.floor(sector)]);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 将一个已校验的 RGB 生成十级梯度;暗色先校准并量化,再计算与反转。 */
|
|
120
|
+
function createScale(rgb, mode) {
|
|
121
|
+
let [hue, saturation, value] = toHsv(rgb);
|
|
122
|
+
if (mode === 'dark') {
|
|
123
|
+
// 深色校准需要 HEX 往返;省略这次量化会产生一个通道的结果偏差。
|
|
124
|
+
// 固定规则:饱和度降为 92%,明度增加 0.01,并限制在有效范围内。
|
|
125
|
+
[hue, saturation, value] = toHsv(
|
|
126
|
+
hexToRgb(hsvToHex(hue, saturation * 0.92, Math.min(value + 0.01, 1))),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
/** 第 5 级是浅色锚点;其余位置按冷暖与相对亮度分段延伸。 */
|
|
130
|
+
const result = scalePositions.map(
|
|
131
|
+
/** 计算一个梯度位置的 HSV 变化量。 */ (position) => {
|
|
132
|
+
/** 色相偏移的内部位置差,与 S/V 的百位级差分开计算。 */
|
|
133
|
+
const distance = position - 500;
|
|
134
|
+
/** 饱和度和明度每级按 100 个内部位置单位变化。 */
|
|
135
|
+
const step = distance / 100;
|
|
136
|
+
let hueRate;
|
|
137
|
+
// 20/48/80/260° 划分冷暖偏移段;0.01/0.02/0.03 是每内部单位的度数。
|
|
138
|
+
if (position <= 500) hueRate = hue > 80 && hue < 260 ? 0.01 : -0.02;
|
|
139
|
+
else if (hue > 20 && hue < 48) hueRate = -0.03;
|
|
140
|
+
else hueRate = hue >= 48 && hue < 260 ? 0.01 : -0.02;
|
|
141
|
+
let saturationOffset = 0;
|
|
142
|
+
// 浅阶在五级范围内降低饱和度;最浅级额外减 0.02,深阶按 30/200° 分段。
|
|
143
|
+
if (position < 500) {
|
|
144
|
+
saturationOffset = (step * saturation) / 5;
|
|
145
|
+
if (position < 100) saturationOffset -= 0.02;
|
|
146
|
+
} else if (position > 500 && saturation !== 0) {
|
|
147
|
+
saturationOffset = step * (hue < 30 || hue > 200 ? 0.03 : 0.01);
|
|
148
|
+
}
|
|
149
|
+
let valueOffset = 0;
|
|
150
|
+
// 饱和度低于 0.1 时浅阶提亮加速 6%;深阶按亮度 0.8 与色相段选择速率。
|
|
151
|
+
if (position < 500) {
|
|
152
|
+
valueOffset = (step * (1 - value)) / 5;
|
|
153
|
+
if (saturation < 0.1) valueOffset *= 1.06;
|
|
154
|
+
} else if (position > 500) {
|
|
155
|
+
valueOffset =
|
|
156
|
+
(hue < 30 || hue > 200) && hue > 0
|
|
157
|
+
? step * (value > 0.8 ? 0.14 : 0.08)
|
|
158
|
+
: (step * value) / 6;
|
|
159
|
+
}
|
|
160
|
+
return hsvToHex(
|
|
161
|
+
wrap(hue + distance * hueRate, 360),
|
|
162
|
+
clamp(saturation + saturationOffset),
|
|
163
|
+
clamp(value - valueOffset),
|
|
164
|
+
);
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
return mode === 'dark' ? result.reverse() : result;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** 生成一个颜色的十级色阶;灰、黑、白同样支持,输出索引为 Semi 的 0…9。 */
|
|
171
|
+
export function generateColorScale(color, options) {
|
|
172
|
+
return createScale(parseHex(color), readMode(options));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** sRGB 通道线性化,使用 D65 CIE Lab 所需的标准传递函数。 */
|
|
176
|
+
function linearize(channel) {
|
|
177
|
+
/** 相对通道采用 0…1 范围,0.04045 为 sRGB 的分段阈值。 */
|
|
178
|
+
const normalized = channel / 255;
|
|
179
|
+
return normalized <= 0.04045 ? normalized / 12.92 : ((normalized + 0.055) / 1.055) ** 2.4;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** XYZ 到 Lab 的分段传递函数;小数常量精度与参考色彩模型一致。 */
|
|
183
|
+
function labCurve(value) {
|
|
184
|
+
return value > 0.008856452 ? value ** (1 / 3) : value / 0.12841855 + 0.137931034;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** 返回颜色相对标准红色的 CIE76 距离平方,用于色轮起点排序。 */
|
|
188
|
+
function redDistance(color) {
|
|
189
|
+
/** Lab 计算只参与排序,不能替代色阶本身使用的 HSV 运算。 */
|
|
190
|
+
const [red, green, blue] = hexToRgb(color).map(
|
|
191
|
+
/** 将通道转为线性光。 */ (channel) => linearize(channel),
|
|
192
|
+
);
|
|
193
|
+
/** D65 标准 sRGB→XYZ 矩阵和白点缩放值。 */
|
|
194
|
+
const x = labCurve((0.4124564 * red + 0.3575761 * green + 0.1804375 * blue) / 0.95047);
|
|
195
|
+
/** Y 使用白点 1,直接参与 L*。 */
|
|
196
|
+
const y = labCurve(0.2126729 * red + 0.7151522 * green + 0.072175 * blue);
|
|
197
|
+
/** Z 使用 D65 白点 1.08883。 */
|
|
198
|
+
const z = labCurve((0.0193339 * red + 0.119192 * green + 0.9503041 * blue) / 1.08883);
|
|
199
|
+
/** 标准红色按相同模型计算,避免以近似常量影响边界排序。 */
|
|
200
|
+
const redX = labCurve(0.4124564 / 0.95047);
|
|
201
|
+
/** 红色的线性 Y 通道。 */
|
|
202
|
+
const redY = labCurve(0.2126729);
|
|
203
|
+
/** 红色的线性 Z 通道。 */
|
|
204
|
+
const redZ = labCurve(0.0193339 / 1.08883);
|
|
205
|
+
return (
|
|
206
|
+
(Math.max(0, 116 * y - 16) - Math.max(0, 116 * redY - 16)) ** 2 +
|
|
207
|
+
(500 * (x - y) - 500 * (redX - redY)) ** 2 +
|
|
208
|
+
(200 * (y - z) - 200 * (redY - redZ)) ** 2
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** 由品牌色旋转初始色轮并生成全部色阶;无色相输入不构成有效品牌色轮。 */
|
|
213
|
+
export function generateColorPalette(brand, options) {
|
|
214
|
+
/** 输入仅解析一次,后续内部颜色均由算法生成。 */
|
|
215
|
+
const rgb = parseHex(brand);
|
|
216
|
+
/** 无色相会让参考色轮的偏移率退化为 NaN,公开入口明确拒绝。 */
|
|
217
|
+
const [brandHue, brandSaturation, brandValue] = toHsv(rgb);
|
|
218
|
+
if (brandSaturation === 0) throw new RangeError('整盘生成要求品牌色具有非零饱和度');
|
|
219
|
+
/** 模式只影响 S/V 对整盘的偏移及最终暗色校准。 */
|
|
220
|
+
const mode = readMode(options);
|
|
221
|
+
/** 保持初始色轮命名顺序,尤其保留相同距离时的第一个锚点。 */
|
|
222
|
+
const names = Object.keys(wheelAnchors);
|
|
223
|
+
/** 预先解算初始色轮,避免排序过程中改变锚点。 */
|
|
224
|
+
const anchors = names.map(
|
|
225
|
+
/** 读取一个初始命名色的 HSV。 */ (name) => toHsv(hexToRgb(wheelAnchors[name])),
|
|
226
|
+
);
|
|
227
|
+
let closestIndex = 0;
|
|
228
|
+
for (let index = 1; index < anchors.length; index += 1) {
|
|
229
|
+
if (Math.abs(anchors[index][0] - brandHue) < Math.abs(anchors[closestIndex][0] - brandHue))
|
|
230
|
+
closestIndex = index;
|
|
231
|
+
}
|
|
232
|
+
/** 色相偏移选用最近锚点一侧的间隔;末尾两项依参考规则连接初始项。 */
|
|
233
|
+
const intervals = anchors.map(
|
|
234
|
+
/** 计算参考色轮定义的每项旋转间隔。 */ (anchor, index) =>
|
|
235
|
+
wrap(anchor[0] - anchors[index < anchors.length - 2 ? index + 1 : 0][0], 360),
|
|
236
|
+
);
|
|
237
|
+
/** 正向偏移时采用前一侧间隔,负向时采用当前侧间隔。 */
|
|
238
|
+
const intervalIndex =
|
|
239
|
+
brandHue > anchors[closestIndex][0] ? wrap(closestIndex - 1, anchors.length) : closestIndex;
|
|
240
|
+
/** 色轮允许品牌与锚点差异的一半,避免跨越色相定义。 */
|
|
241
|
+
const hueRatio = (brandHue - anchors[closestIndex][0]) / intervals[intervalIndex] / 2;
|
|
242
|
+
/** 暗色轮仅旋转色相,不再按品牌 S/V 同步偏移。 */
|
|
243
|
+
const saturationRatio =
|
|
244
|
+
mode === 'light'
|
|
245
|
+
? (brandSaturation - anchors[closestIndex][1]) / anchors[closestIndex][1] / 2
|
|
246
|
+
: 0;
|
|
247
|
+
/** 与饱和度相同,亮度偏移仅用于浅色轮。 */
|
|
248
|
+
const valueRatio =
|
|
249
|
+
mode === 'light' ? (brandValue - anchors[closestIndex][2]) / anchors[closestIndex][2] / 2 : 0;
|
|
250
|
+
/** 色轮颜色量化后再按色相排序,不能对未量化的 HSV 排序。 */
|
|
251
|
+
const wheel = anchors
|
|
252
|
+
.map(
|
|
253
|
+
/** 旋转一项;固定下限 S=0.65、V=0.7,保持基础色轮的可用色度。 */ (anchor, index) =>
|
|
254
|
+
hsvToHex(
|
|
255
|
+
wrap(anchor[0] + intervals[index] * hueRatio, 360),
|
|
256
|
+
clamp(anchor[1] * (1 + saturationRatio), 0.65, 1),
|
|
257
|
+
clamp(anchor[2] * (1 + valueRatio), 0.7, 1),
|
|
258
|
+
),
|
|
259
|
+
)
|
|
260
|
+
.sort(
|
|
261
|
+
/** 将命名色轮按色相降序排列。 */ (left, right) =>
|
|
262
|
+
toHsv(hexToRgb(right))[0] - toHsv(hexToRgb(left))[0],
|
|
263
|
+
);
|
|
264
|
+
if (redDistance(wheel[0]) > redDistance(wheel[wheel.length - 1])) wheel.unshift(wheel.pop());
|
|
265
|
+
/** 插入顺序是公开命名顺序,先基础有色相,再 grey 和 brand。 */
|
|
266
|
+
const palette = {};
|
|
267
|
+
for (let index = 0; index < names.length; index += 1)
|
|
268
|
+
palette[names[index]] = createScale(hexToRgb(wheel[index]), mode);
|
|
269
|
+
// 灰色轴沿用品牌色相,但固定 S=0.09、V=0.46;它不参与有色色轮的排序。
|
|
270
|
+
palette.grey = createScale(hexToRgb(hsvToHex(brandHue, 0.09, 0.46)), mode);
|
|
271
|
+
palette.brand = createScale(rgb, mode);
|
|
272
|
+
return palette;
|
|
273
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { generateColorPalette } from './palette.mjs';
|
|
2
|
+
|
|
3
|
+
/** 识别可随颜色主题覆盖的变量,不将排版、圆角或尺寸混入主题。 */
|
|
4
|
+
export function isColorToken(name) {
|
|
5
|
+
return (
|
|
6
|
+
/^--semi-(?:(?:red|pink|purple|violet|indigo|blue|light-blue|cyan|teal|green|light-green|lime|yellow|amber|orange|grey|brand)-[0-9]|black|white)$/.test(
|
|
7
|
+
name,
|
|
8
|
+
) ||
|
|
9
|
+
name.startsWith('--semi-color-') ||
|
|
10
|
+
name.startsWith('--semi-ai-') ||
|
|
11
|
+
name === '--semi-shadow-elevated'
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** 绑定固定基线的语义引用;此内部函数只由公开入口和构建验收调用。 */
|
|
16
|
+
export function buildColorTheme({ brand }, baseline) {
|
|
17
|
+
/** 两种模式各自生成,深色不是将浅色数组直接倒序。 */
|
|
18
|
+
const palette = {
|
|
19
|
+
light: generateColorPalette(brand),
|
|
20
|
+
dark: generateColorPalette(brand, { mode: 'dark' }),
|
|
21
|
+
};
|
|
22
|
+
/** 每次调用独立复制基线变量,避免业务修改返回对象污染其他主题。 */
|
|
23
|
+
const variables = { light: { ...baseline.light }, dark: { ...baseline.dark } };
|
|
24
|
+
for (const mode of ['light', 'dark']) {
|
|
25
|
+
for (const [name, scale] of Object.entries(palette[mode])) {
|
|
26
|
+
for (const [level, hex] of scale.entries()) {
|
|
27
|
+
/** Semi 的基础色变量为逗号分隔的 RGB 通道,而非完整 CSS 颜色。 */
|
|
28
|
+
const channels = [1, 3, 5].map(
|
|
29
|
+
/** 每两个 HEX 字符对应一个 8 位颜色通道。 */
|
|
30
|
+
(offset) => Number.parseInt(hex.slice(offset, offset + 2), 16),
|
|
31
|
+
);
|
|
32
|
+
variables[mode][`--semi-${name}-${level}`] = channels.join(', ');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const [name, value] of Object.entries(variables[mode])) {
|
|
36
|
+
if (/^--semi-color-(?:primary(?:-|$)|link(?:-|$)|focus-border$)/.test(name)) {
|
|
37
|
+
// 主操作、链接、焦点绑定品牌色;info 仍消费独立 blue 色相。
|
|
38
|
+
variables[mode][name] = value.replace(/var\(--semi-blue-(\d)\)/g, 'var(--semi-brand-$1)');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { version: 1, brand: palette.light.brand[5], palette, variables };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 为模式变量生成私有载体名称,使强制模式能消费最近主题的另一套颜色。 */
|
|
46
|
+
function modeToken(name, mode) {
|
|
47
|
+
return `--semi-theme-${mode}-${name.slice('--semi-'.length)}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 序列化声明列表,保持变量顺序稳定,便于保存、审阅和缓存 CSS。 */
|
|
51
|
+
function declarations(variables) {
|
|
52
|
+
return Object.entries(variables)
|
|
53
|
+
.map(
|
|
54
|
+
/** 变量值来自生成器和固定基线,不依赖 DOM 或 Sass 解析。 */
|
|
55
|
+
([name, value]) => ` ${name}: ${value};`,
|
|
56
|
+
)
|
|
57
|
+
.join('\n');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 输出普通 CSS;调用方明确提供模式选择器,函数不推断 DOM 层级或修改页面。 */
|
|
61
|
+
export function colorThemeToCss(theme, { selectors }) {
|
|
62
|
+
for (const mode of ['light', 'dark']) {
|
|
63
|
+
if (
|
|
64
|
+
typeof selectors[mode] !== 'string' ||
|
|
65
|
+
!selectors[mode].trim() ||
|
|
66
|
+
/[{};]/.test(selectors[mode])
|
|
67
|
+
) {
|
|
68
|
+
throw new TypeError('颜色主题需要有效且非空的 light/dark CSS 选择器');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** 两种模式共用载体,以便在任一当前模式中嵌套 always-light/dark。 */
|
|
72
|
+
const carriers = {};
|
|
73
|
+
for (const mode of ['light', 'dark']) {
|
|
74
|
+
for (const [name, value] of Object.entries(theme.variables[mode])) {
|
|
75
|
+
// 将引用也改为同模式载体,防止深色载体在浅色根上提前解析成浅色。
|
|
76
|
+
carriers[modeToken(name, mode)] = value.replace(
|
|
77
|
+
/var\((--semi-[\w-]+)/g,
|
|
78
|
+
/** 只重定向颜色引用,不扩展到布局或其他业务变量。 */
|
|
79
|
+
(match, referenced) =>
|
|
80
|
+
isColorToken(referenced) ? `var(${modeToken(referenced, mode)}` : match,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** :is() 正确容纳逗号选择器;强制模式规则只声明当前匹配元素的变量。 */
|
|
85
|
+
const scope = `:is(${selectors.light}, ${selectors.dark})`;
|
|
86
|
+
/** 私有载体先定义,随后定义当前模式和显式强制模式。 */
|
|
87
|
+
const rules = [`${scope} {\n${declarations(carriers)}\n}`];
|
|
88
|
+
for (const mode of ['light', 'dark']) {
|
|
89
|
+
rules.push(`${selectors[mode]} {\n${declarations(theme.variables[mode])}\n}`);
|
|
90
|
+
}
|
|
91
|
+
for (const mode of ['light', 'dark']) {
|
|
92
|
+
/** 规则在嵌套主题间引用相同载体名,因此不会跨主题抢用外层颜色。 */
|
|
93
|
+
const forced = {};
|
|
94
|
+
for (const name of Object.keys(theme.variables[mode])) {
|
|
95
|
+
forced[name] = `var(${modeToken(name, mode)})`;
|
|
96
|
+
}
|
|
97
|
+
rules.push(
|
|
98
|
+
`${scope}.semi-always-${mode}, ${scope} .semi-always-${mode} {\n${declarations(forced)}\n}`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return `${rules.join('\n\n')}\n`;
|
|
102
|
+
}
|
package/dist/date-picker.css
CHANGED
|
@@ -109,9 +109,9 @@
|
|
|
109
109
|
}
|
|
110
110
|
.semi-datepicker-month-grid .semi-scrolllist-header-title {
|
|
111
111
|
padding: 0;
|
|
112
|
-
font-size: 14px;
|
|
113
|
-
line-height: 20px;
|
|
114
|
-
font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
112
|
+
font-size: var(--semi-font-size-regular, 14px);
|
|
113
|
+
line-height: var(--semi-line-height-regular, 20px);
|
|
114
|
+
font-family: var(--semi-font-family-regular, "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif);
|
|
115
115
|
min-height: 24px;
|
|
116
116
|
line-height: 24px;
|
|
117
117
|
}
|
|
@@ -198,12 +198,12 @@
|
|
|
198
198
|
min-width: 32px;
|
|
199
199
|
}
|
|
200
200
|
.semi-datepicker-navigation-month {
|
|
201
|
-
font-size: 16px;
|
|
202
|
-
line-height: 22px;
|
|
203
|
-
font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
201
|
+
font-size: var(--semi-font-size-header-6, 16px);
|
|
202
|
+
line-height: var(--semi-line-height-header-6, 22px);
|
|
203
|
+
font-family: var(--semi-font-family-regular, "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif);
|
|
204
204
|
flex-grow: 1;
|
|
205
205
|
text-align: center;
|
|
206
|
-
font-weight: 600;
|
|
206
|
+
font-weight: var(--semi-font-weight-strong, 600);
|
|
207
207
|
color: var(--semi-color-text-0);
|
|
208
208
|
}
|
|
209
209
|
.semi-datepicker-navigation-month .semi-button {
|
|
@@ -216,10 +216,10 @@
|
|
|
216
216
|
padding-top: 0;
|
|
217
217
|
}
|
|
218
218
|
.semi-datepicker-weekday {
|
|
219
|
-
font-size: 12px;
|
|
220
|
-
line-height: 16px;
|
|
221
|
-
font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
222
|
-
font-weight: 600;
|
|
219
|
+
font-size: var(--semi-font-size-small, 12px);
|
|
220
|
+
line-height: var(--semi-line-height-small, 16px);
|
|
221
|
+
font-family: var(--semi-font-family-regular, "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif);
|
|
222
|
+
font-weight: var(--semi-font-weight-strong, 600);
|
|
223
223
|
color: var(--semi-color-text-2);
|
|
224
224
|
border-bottom: 1px solid var(--semi-color-border);
|
|
225
225
|
}
|
|
@@ -266,7 +266,7 @@
|
|
|
266
266
|
.semi-datepicker-day-today .semi-datepicker-day-main {
|
|
267
267
|
color: var(--semi-color-primary);
|
|
268
268
|
background-color: var(--semi-color-fill-0);
|
|
269
|
-
font-weight: 600;
|
|
269
|
+
font-weight: var(--semi-font-weight-strong, 600);
|
|
270
270
|
}
|
|
271
271
|
.semi-datepicker-day-today.semi-datepicker-day-disabled .semi-datepicker-day-main {
|
|
272
272
|
color: var(--semi-color-primary-disabled);
|
|
@@ -373,7 +373,7 @@
|
|
|
373
373
|
}
|
|
374
374
|
.semi-datepicker-switch-date-active, .semi-datepicker-switch-time-active {
|
|
375
375
|
color: var(--semi-color-text-0);
|
|
376
|
-
font-weight: 600;
|
|
376
|
+
font-weight: var(--semi-font-weight-strong, 600);
|
|
377
377
|
cursor: auto;
|
|
378
378
|
}
|
|
379
379
|
.semi-datepicker-switch-date-active:hover, .semi-datepicker-switch-time-active:hover {
|
|
@@ -395,7 +395,7 @@
|
|
|
395
395
|
}
|
|
396
396
|
.semi-datepicker-quick-control-header {
|
|
397
397
|
padding: 18px 12px 0;
|
|
398
|
-
font-weight: 600;
|
|
398
|
+
font-weight: var(--semi-datepicker-preset-header-font-weight, 600);
|
|
399
399
|
}
|
|
400
400
|
.semi-datepicker-quick-control-left {
|
|
401
401
|
border-right: 1px solid var(--semi-color-border);
|
|
@@ -680,7 +680,7 @@
|
|
|
680
680
|
height: 40px;
|
|
681
681
|
}
|
|
682
682
|
.semi-datepicker-range-input-large .semi-input-default {
|
|
683
|
-
font-size: 16px;
|
|
683
|
+
font-size: var(--semi-datepicker-range-input-large-font-size, 16px);
|
|
684
684
|
}
|
|
685
685
|
.semi-datepicker-range-input:hover .semi-datepicker-range-input-clearbtn {
|
|
686
686
|
display: flex;
|
|
@@ -735,10 +735,10 @@
|
|
|
735
735
|
display: flex;
|
|
736
736
|
align-items: center;
|
|
737
737
|
justify-content: center;
|
|
738
|
-
font-weight: 600;
|
|
739
|
-
font-size: 14px;
|
|
740
|
-
line-height: 20px;
|
|
741
|
-
font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
738
|
+
font-weight: var(--semi-datepicker-range-input-prefix-suffix-clearbtn-font-weight, 600);
|
|
739
|
+
font-size: var(--semi-datepicker-range-input-prefix-suffix-clearbtn-font-size, 14px);
|
|
740
|
+
line-height: var(--semi-datepicker-range-input-prefix-suffix-clearbtn-line-height, 20px);
|
|
741
|
+
font-family: var(--semi-font-family-regular, "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif);
|
|
742
742
|
white-space: nowrap;
|
|
743
743
|
color: var(--semi-color-text-2);
|
|
744
744
|
}
|
|
@@ -762,9 +762,9 @@
|
|
|
762
762
|
* 小尺寸 DatePicker
|
|
763
763
|
*/
|
|
764
764
|
.semi-datepicker-compact {
|
|
765
|
-
font-size: 12px;
|
|
766
|
-
line-height: 16px;
|
|
767
|
-
font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
765
|
+
font-size: var(--semi-font-size-small, 12px);
|
|
766
|
+
line-height: var(--semi-line-height-small, 16px);
|
|
767
|
+
font-family: var(--semi-font-family-regular, "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif);
|
|
768
768
|
line-height: 20px;
|
|
769
769
|
display: inline-block;
|
|
770
770
|
max-width: calc(100vw - 32px);
|
|
@@ -833,9 +833,9 @@
|
|
|
833
833
|
border: 1px solid var(--semi-color-border);
|
|
834
834
|
}
|
|
835
835
|
.semi-datepicker-compact .semi-datepicker-month-grid .semi-scrolllist {
|
|
836
|
-
font-size: 12px;
|
|
837
|
-
line-height: 16px;
|
|
838
|
-
font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
836
|
+
font-size: var(--semi-font-size-small, 12px);
|
|
837
|
+
line-height: var(--semi-line-height-small, 16px);
|
|
838
|
+
font-family: var(--semi-font-family-regular, "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif);
|
|
839
839
|
line-height: 20px;
|
|
840
840
|
}
|
|
841
841
|
.semi-datepicker-compact .semi-datepicker-month-grid .semi-scrolllist-header {
|
|
@@ -877,9 +877,9 @@
|
|
|
877
877
|
height: 100%;
|
|
878
878
|
}
|
|
879
879
|
.semi-datepicker-compact.semi-datepicker-panel-yam .semi-scrolllist {
|
|
880
|
-
font-size: 12px;
|
|
881
|
-
line-height: 16px;
|
|
882
|
-
font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
880
|
+
font-size: var(--semi-font-size-small, 12px);
|
|
881
|
+
line-height: var(--semi-line-height-small, 16px);
|
|
882
|
+
font-family: var(--semi-font-family-regular, "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif);
|
|
883
883
|
line-height: 20px;
|
|
884
884
|
}
|
|
885
885
|
.semi-datepicker-compact .semi-datepicker-tpk {
|
|
@@ -906,9 +906,9 @@
|
|
|
906
906
|
overflow: hidden;
|
|
907
907
|
}
|
|
908
908
|
.semi-datepicker-compact .semi-datepicker-navigation-month .semi-button {
|
|
909
|
-
font-size: 12px;
|
|
910
|
-
line-height: 16px;
|
|
911
|
-
font-family: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
909
|
+
font-size: var(--semi-font-size-small, 12px);
|
|
910
|
+
line-height: var(--semi-line-height-small, 16px);
|
|
911
|
+
font-family: var(--semi-font-family-regular, "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif);
|
|
912
912
|
line-height: 20px;
|
|
913
913
|
max-width: 100%;
|
|
914
914
|
}
|
|
@@ -993,7 +993,7 @@
|
|
|
993
993
|
}
|
|
994
994
|
.semi-datepicker-compact .semi-datepicker-quick-control-header {
|
|
995
995
|
padding: 16px 12px 0;
|
|
996
|
-
font-weight: 600;
|
|
996
|
+
font-weight: var(--semi-datepicker-preset-header-font-weight, 600);
|
|
997
997
|
}
|
|
998
998
|
.semi-datepicker-compact .semi-datepicker-quick-control-left-content-wrapper, .semi-datepicker-compact .semi-datepicker-quick-control-right-content-wrapper {
|
|
999
999
|
margin-top: 12px;
|