soma-kit 0.1.10 → 0.1.11
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/package.json +1 -1
- package/src/theme/nine-dim-palettes.ts +208 -13
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ export interface PaletteToneSpec {
|
|
|
9
9
|
canvas: string;
|
|
10
10
|
card: string;
|
|
11
11
|
sunken: string;
|
|
12
|
+
raised?: string;
|
|
12
13
|
secBg: string;
|
|
13
14
|
secText: string;
|
|
14
15
|
hover: string;
|
|
@@ -34,7 +35,7 @@ export interface PaletteSeed {
|
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
const PALETTE_SEEDS: readonly PaletteSeed[] = [
|
|
38
|
+
export const PALETTE_SEEDS: readonly PaletteSeed[] = [
|
|
38
39
|
{
|
|
39
40
|
enumKey: "CLASSIC_TECH_BLUE",
|
|
40
41
|
name: "01 · 经典科技蓝",
|
|
@@ -1003,6 +1004,193 @@ const FONT_SCALES: Record<string, {
|
|
|
1003
1004
|
};
|
|
1004
1005
|
|
|
1005
1006
|
|
|
1007
|
+
export interface HarmonicPaletteSurfaces {
|
|
1008
|
+
canvas: string;
|
|
1009
|
+
well: string;
|
|
1010
|
+
card: string;
|
|
1011
|
+
float: string;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function parseHexRgb(hex: string): [number, number, number] {
|
|
1015
|
+
const clean = hex.trim().replace(/^#/, "");
|
|
1016
|
+
if (clean.length === 3) {
|
|
1017
|
+
const r = parseInt(clean[0]! + clean[0]!, 16);
|
|
1018
|
+
const g = parseInt(clean[1]! + clean[1]!, 16);
|
|
1019
|
+
const b = parseInt(clean[2]! + clean[2]!, 16);
|
|
1020
|
+
return [r, g, b];
|
|
1021
|
+
}
|
|
1022
|
+
const r = parseInt(clean.slice(0, 2), 16);
|
|
1023
|
+
const g = parseInt(clean.slice(2, 4), 16);
|
|
1024
|
+
const b = parseInt(clean.slice(4, 6), 16);
|
|
1025
|
+
return [
|
|
1026
|
+
Number.isNaN(r) ? 255 : r,
|
|
1027
|
+
Number.isNaN(g) ? 255 : g,
|
|
1028
|
+
Number.isNaN(b) ? 255 : b,
|
|
1029
|
+
];
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function toHexByte(n: number): string {
|
|
1033
|
+
return Math.max(0, Math.min(255, Math.round(n))).toString(16).padStart(2, "0");
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
function rgbToHex([r, g, b]: [number, number, number]): string {
|
|
1037
|
+
return `#${toHexByte(r)}${toHexByte(g)}${toHexByte(b)}`;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
function rgbSum(hex: string): number {
|
|
1041
|
+
const [r, g, b] = parseHexRgb(hex);
|
|
1042
|
+
return r + g + b;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function manhattanRgb(a: string, b: string): number {
|
|
1046
|
+
const [ra, ga, ba] = parseHexRgb(a);
|
|
1047
|
+
const [rb, gb, bb] = parseHexRgb(b);
|
|
1048
|
+
return Math.abs(ra - rb) + Math.abs(ga - gb) + Math.abs(ba - bb);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function mixHex(a: string, b: string, ratio: number): string {
|
|
1052
|
+
const [ra, ga, ba] = parseHexRgb(a);
|
|
1053
|
+
const [rb, gb, bb] = parseHexRgb(b);
|
|
1054
|
+
return rgbToHex([
|
|
1055
|
+
ra + (rb - ra) * ratio,
|
|
1056
|
+
ga + (gb - ga) * ratio,
|
|
1057
|
+
ba + (bb - ba) * ratio,
|
|
1058
|
+
]);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function collectSeedSurfacePool(seed: PaletteSeed): {
|
|
1062
|
+
rawPool: string[];
|
|
1063
|
+
harmonicPool: string[];
|
|
1064
|
+
} {
|
|
1065
|
+
const set = new Set<string>();
|
|
1066
|
+
for (const d of ["LIGHTENED", "NORMAL", "DARKENED"] as const) {
|
|
1067
|
+
const t = seed.tones[d];
|
|
1068
|
+
set.add(t.card.toLowerCase());
|
|
1069
|
+
set.add(t.sunken.toLowerCase());
|
|
1070
|
+
set.add(t.canvas.toLowerCase());
|
|
1071
|
+
}
|
|
1072
|
+
const basePool = [...set].sort((a, b) => rgbSum(a) - rgbSum(b));
|
|
1073
|
+
const expanded = new Set<string>(basePool);
|
|
1074
|
+
for (let i = 0; i < basePool.length - 1; i++) {
|
|
1075
|
+
for (const ratio of [0.2, 0.35, 0.5, 0.65, 0.8]) {
|
|
1076
|
+
expanded.add(mixHex(basePool[i]!, basePool[i + 1]!, ratio));
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return {
|
|
1080
|
+
rawPool: basePool,
|
|
1081
|
+
harmonicPool: [...expanded].sort((a, b) => rgbSum(a) - rgbSum(b)),
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
export function deriveSurfaceRaised(
|
|
1086
|
+
tone: PaletteToneSpec,
|
|
1087
|
+
isDark: boolean,
|
|
1088
|
+
toneKey: "NORMAL" | "LIGHTENED" | "DARKENED",
|
|
1089
|
+
): string {
|
|
1090
|
+
if (tone.raised) {
|
|
1091
|
+
return tone.raised;
|
|
1092
|
+
}
|
|
1093
|
+
if (isDark) {
|
|
1094
|
+
const ratio = toneKey === "LIGHTENED" ? 0.08 : toneKey === "DARKENED" ? 0.05 : 0.06;
|
|
1095
|
+
return mixHex(tone.card, "#ffffff", ratio);
|
|
1096
|
+
}
|
|
1097
|
+
if (tone.card.toLowerCase() !== "#ffffff") {
|
|
1098
|
+
return mixHex(tone.card, "#ffffff", 0.55);
|
|
1099
|
+
}
|
|
1100
|
+
return "#ffffff";
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* 基于当前配色方案(PaletteSeed)自身的色阶池(LIGHTENED / NORMAL / DARKENED)与同色相轴,
|
|
1105
|
+
* 按确定性规则自动选出满足明度单调递增且相邻层 |ΔR|+|ΔG|+|ΔB| >= 12 的四层表面色(canvas / well / card / float)。
|
|
1106
|
+
*/
|
|
1107
|
+
export function resolveHarmonicPaletteSurfaces(
|
|
1108
|
+
seed: PaletteSeed,
|
|
1109
|
+
toneKey: "NORMAL" | "LIGHTENED" | "DARKENED",
|
|
1110
|
+
): HarmonicPaletteSurfaces {
|
|
1111
|
+
const MIN_DIST = 12;
|
|
1112
|
+
const tone = seed.tones[toneKey];
|
|
1113
|
+
const { rawPool, harmonicPool } = collectSeedSurfacePool(seed);
|
|
1114
|
+
const card = tone.card.toLowerCase();
|
|
1115
|
+
const cardLum = rgbSum(card);
|
|
1116
|
+
|
|
1117
|
+
const localPair = [tone.canvas.toLowerCase(), tone.sunken.toLowerCase()].sort(
|
|
1118
|
+
(a, b) => rgbSum(a) - rgbSum(b),
|
|
1119
|
+
);
|
|
1120
|
+
const localCanvasCandidate = localPair[0]!;
|
|
1121
|
+
const localWellCandidate = localPair[1]!;
|
|
1122
|
+
|
|
1123
|
+
// 1. 选 well(L2 内凹表面):优先取本档较亮候选色;若与 card 同色或距离 < 12,从同一 seed 候选池选最贴近 card 的合格同系色
|
|
1124
|
+
let well = localWellCandidate;
|
|
1125
|
+
if (rgbSum(well) >= cardLum || manhattanRgb(well, card) < MIN_DIST || cardLum - rgbSum(well) < MIN_DIST) {
|
|
1126
|
+
const rawCandidates = rawPool.filter(
|
|
1127
|
+
(c) => rgbSum(c) <= cardLum - MIN_DIST && manhattanRgb(c, card) >= MIN_DIST,
|
|
1128
|
+
);
|
|
1129
|
+
if (rawCandidates.length > 0) {
|
|
1130
|
+
well = rawCandidates[rawCandidates.length - 1]!;
|
|
1131
|
+
} else {
|
|
1132
|
+
const harmCandidates = harmonicPool.filter(
|
|
1133
|
+
(c) => rgbSum(c) <= cardLum - MIN_DIST && manhattanRgb(c, card) >= MIN_DIST,
|
|
1134
|
+
);
|
|
1135
|
+
well = harmCandidates.length > 0
|
|
1136
|
+
? harmCandidates[harmCandidates.length - 1]!
|
|
1137
|
+
: mixHex(card, seed.tones.DARKENED.sunken.toLowerCase(), 0.25);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
const wellLum = rgbSum(well);
|
|
1141
|
+
|
|
1142
|
+
// 2. 选 canvas(L0 画布表面):优先取本档较深候选色;若与 well 同色或距离 < 12,从同一 seed 候选池选下一级梯度色
|
|
1143
|
+
let canvas = localCanvasCandidate;
|
|
1144
|
+
if (rgbSum(canvas) > wellLum - MIN_DIST || manhattanRgb(canvas, well) < MIN_DIST) {
|
|
1145
|
+
const rawCandidates = rawPool.filter(
|
|
1146
|
+
(c) => rgbSum(c) <= wellLum - MIN_DIST && manhattanRgb(c, well) >= MIN_DIST,
|
|
1147
|
+
);
|
|
1148
|
+
if (rawCandidates.length > 0) {
|
|
1149
|
+
canvas = rawCandidates[rawCandidates.length - 1]!;
|
|
1150
|
+
} else {
|
|
1151
|
+
const harmCandidates = harmonicPool.filter(
|
|
1152
|
+
(c) => rgbSum(c) <= wellLum - MIN_DIST && manhattanRgb(c, well) >= MIN_DIST,
|
|
1153
|
+
);
|
|
1154
|
+
if (harmCandidates.length > 0) {
|
|
1155
|
+
canvas = harmCandidates[harmCandidates.length - 1]!;
|
|
1156
|
+
} else {
|
|
1157
|
+
const darkest = rawPool[0]!;
|
|
1158
|
+
const [rc, gc, bc] = parseHexRgb(well);
|
|
1159
|
+
const [rd, gd, bd] = parseHexRgb(darkest);
|
|
1160
|
+
const [rCard, gCard, bCard] = parseHexRgb(card);
|
|
1161
|
+
const vx = rCard - rd || 1;
|
|
1162
|
+
const vy = gCard - gd || 1;
|
|
1163
|
+
const vz = bCard - bd || 1;
|
|
1164
|
+
const vSum = Math.abs(vx) + Math.abs(vy) + Math.abs(vz);
|
|
1165
|
+
const scale = Math.max(MIN_DIST, 14) / vSum;
|
|
1166
|
+
canvas = rgbToHex([rc - vx * scale, gc - vy * scale, bc - vz * scale]);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// 3. 选 float(L3 浮层/提升表面):优先从同一 seed 更亮一档的候选色或同色相轴派生
|
|
1172
|
+
let float = tone.raised ? tone.raised.toLowerCase() : "#ffffff";
|
|
1173
|
+
if (!tone.raised) {
|
|
1174
|
+
if (seed.isDark) {
|
|
1175
|
+
const lighterRaw = rawPool.filter(
|
|
1176
|
+
(c) => rgbSum(c) >= cardLum + MIN_DIST && manhattanRgb(c, card) >= MIN_DIST,
|
|
1177
|
+
);
|
|
1178
|
+
float = lighterRaw.length > 0
|
|
1179
|
+
? lighterRaw[0]!
|
|
1180
|
+
: deriveSurfaceRaised(tone, true, toneKey);
|
|
1181
|
+
} else if (card !== "#ffffff") {
|
|
1182
|
+
const lighterNonWhite = harmonicPool.filter(
|
|
1183
|
+
(c) => c !== "#ffffff" && rgbSum(c) >= cardLum + MIN_DIST && manhattanRgb(c, card) >= MIN_DIST,
|
|
1184
|
+
);
|
|
1185
|
+
float = lighterNonWhite.length > 0
|
|
1186
|
+
? lighterNonWhite[0]!
|
|
1187
|
+
: deriveSurfaceRaised(tone, false, toneKey);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
return { canvas, well, card, float };
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1006
1194
|
function buildDynamicPaletteRulesCss(): string {
|
|
1007
1195
|
const depths = ["NORMAL", "LIGHTENED", "DARKENED"] as const;
|
|
1008
1196
|
const rules: string[] = [];
|
|
@@ -1017,8 +1205,8 @@ function buildDynamicPaletteRulesCss(): string {
|
|
|
1017
1205
|
const borderStrong = isDark ? "rgba(255, 255, 255, 0.16)" : "rgba(15, 23, 42, 0.14)";
|
|
1018
1206
|
const inputBorder = t.inputBorder ?? (isDark ? "rgba(255, 255, 255, 0.14)" : "rgba(15, 23, 42, 0.14)");
|
|
1019
1207
|
const dividerSubtle = t.dividerSubtle ?? (isDark ? "rgba(255, 255, 255, 0.07)" : "rgba(15, 23, 42, 0.06)");
|
|
1020
|
-
const
|
|
1021
|
-
rules.push(`:root[data-kit-palette="${seed.enumKey}"][data-kit-depth="${d}"] { --soma-surface-
|
|
1208
|
+
const harmonic = resolveHarmonicPaletteSurfaces(seed, d);
|
|
1209
|
+
rules.push(`:root[data-kit-palette="${seed.enumKey}"][data-kit-depth="${d}"] { --soma-surface-canvas: ${harmonic.canvas}; --soma-surface-card: ${harmonic.card}; --soma-surface-well: ${harmonic.well}; --soma-surface-float: ${harmonic.float}; --soma-surface-base: ${harmonic.card}; --soma-surface-sunken: ${harmonic.well}; --soma-surface-raised: ${harmonic.float}; --soma-text-primary: ${textPrimary}; --soma-text-secondary: ${textSecondary}; --soma-text-muted: ${textMuted}; --soma-text-link: ${t.primary}; --soma-border-hairline: ${borderHairline}; --soma-border-strong: ${borderStrong}; --soma-border-control: ${inputBorder}; --soma-border-divider: ${dividerSubtle}; --soma-c-primary: ${t.primary}; --soma-c-primary-soft: ${t.secBg}; --soma-c-primary-on-soft: ${t.secText}; --soma-c-primary-hover: ${t.hover}; --soma-c-primary-active: ${t.primary}; }`);
|
|
1022
1210
|
}
|
|
1023
1211
|
}
|
|
1024
1212
|
return rules.join("\n");
|
|
@@ -1097,13 +1285,7 @@ export function resolveNineDimThemeCss(theme: KitAppTheme): string {
|
|
|
1097
1285
|
}
|
|
1098
1286
|
|
|
1099
1287
|
const borderStrong = isDark ? "rgba(255, 255, 255, 0.16)" : "rgba(15, 23, 42, 0.14)";
|
|
1100
|
-
const
|
|
1101
|
-
? toneKey === "LIGHTENED"
|
|
1102
|
-
? "#182438"
|
|
1103
|
-
: toneKey === "DARKENED"
|
|
1104
|
-
? "#0a101b"
|
|
1105
|
-
: "#141d2c"
|
|
1106
|
-
: "#ffffff";
|
|
1288
|
+
const harmonic = resolveHarmonicPaletteSurfaces(seed, toneKey);
|
|
1107
1289
|
|
|
1108
1290
|
const cSuccess = isDark ? "#22c55e" : "#16a34a";
|
|
1109
1291
|
const cSuccessSoft = isDark ? "#052e16" : "#dcfce7";
|
|
@@ -1186,9 +1368,13 @@ export function resolveNineDimThemeCss(theme: KitAppTheme): string {
|
|
|
1186
1368
|
--soma-radius-card: ${radiusCard};
|
|
1187
1369
|
--soma-radius-control: ${radiusControl};
|
|
1188
1370
|
--soma-control-height: ${controlHeight};
|
|
1189
|
-
--soma-surface-
|
|
1190
|
-
--soma-surface-
|
|
1191
|
-
--soma-surface-
|
|
1371
|
+
--soma-surface-canvas: ${harmonic.canvas};
|
|
1372
|
+
--soma-surface-card: ${harmonic.card};
|
|
1373
|
+
--soma-surface-well: ${harmonic.well};
|
|
1374
|
+
--soma-surface-float: ${harmonic.float};
|
|
1375
|
+
--soma-surface-base: ${harmonic.card};
|
|
1376
|
+
--soma-surface-sunken: ${harmonic.well};
|
|
1377
|
+
--soma-surface-raised: ${harmonic.float};
|
|
1192
1378
|
--soma-text-primary: ${textPrimary};
|
|
1193
1379
|
--soma-text-secondary: ${textSecondary};
|
|
1194
1380
|
--soma-text-muted: ${textMuted};
|
|
@@ -1272,6 +1458,15 @@ export function resolveNineDimThemeCss(theme: KitAppTheme): string {
|
|
|
1272
1458
|
[data-kit-layout-header="true"] { position: sticky; top: 0; z-index: 40; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 0.5px solid var(--soma-border-hairline); background-color: color-mix(in srgb, var(--soma-surface-base) 85%, transparent); }
|
|
1273
1459
|
[data-kit-layout-header="true"] a:not([class*="font-semibold"]):hover { background-color: var(--soma-surface-sunken); border-radius: var(--soma-radius-control); }
|
|
1274
1460
|
[data-kit-layout-footer="true"] { border-top: 0.5px solid var(--soma-border-hairline); background-color: var(--soma-surface-sunken); }
|
|
1461
|
+
[data-soma-host] > main.bg-surface-sunken, [data-soma-host] > div.bg-surface-sunken, [data-soma-host] [data-kit-frame-canvas="true"], [data-soma-host] .min-h-screen.bg-surface-sunken, [data-soma-host] [data-soma-id="frame__root"].bg-surface-sunken, [data-soma-host] [data-soma-id$="frame__header"].bg-surface-sunken { background-color: var(--soma-surface-canvas); }
|
|
1462
|
+
[data-soma-host] :is(section, aside, article, [role="region"], .bg-surface, .bg-surface-raised) :is(section, aside, article, [role="region"], [data-kit-card], .bg-surface:not(input):not(select):not(textarea):not(button):not([role="combobox"]):not([role="spinbutton"]):not([role="switch"]):not(td):not(tr)) { --soma-surface-base: var(--soma-surface-well); background-color: var(--soma-surface-well); }
|
|
1463
|
+
[data-soma-host][data-kit-boundary="BORDERLESS_SHADOW"] :is(section, aside, article, [role="region"], .bg-surface, .bg-surface-raised) :is(section, aside, article, [role="region"], [data-kit-card], .bg-surface:not(input):not(select):not(textarea):not(button):not([role="combobox"]):not([role="spinbutton"]):not([role="switch"]):not(td):not(tr)) { background-color: var(--soma-surface-well); box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.04); }
|
|
1464
|
+
[data-soma-host] :is(section, aside, article, [role="region"], .bg-surface, .bg-surface-raised) :is(section, aside, article, [role="region"], [data-kit-card], .bg-surface:not(input):not(select):not(textarea):not(button):not([role="combobox"]):not([role="spinbutton"]):not([role="switch"]):not(td):not(tr)) :is(section, aside, article, [role="region"], [data-kit-card], .bg-surface:not(input):not(select):not(textarea):not(button):not([role="combobox"]):not([role="spinbutton"]):not([role="switch"]):not(td):not(tr)) { --soma-surface-base: var(--soma-surface-card); background-color: var(--soma-surface-card); }
|
|
1465
|
+
[data-soma-host] :is(.bg-surface, .bg-surface-raised, .bg-surface-sunken, section, aside, article, [role="region"]) :is(input, select, textarea, [role="combobox"], [role="spinbutton"]) { --soma-surface-base: var(--soma-surface-card); background-color: var(--soma-surface-card); border-color: var(--soma-border-control); }
|
|
1466
|
+
[data-soma-host] :is(.bg-surface-sunken:not(main):not(.min-h-screen):not([data-soma-id="frame__root"]), :is(section, aside, article, [role="region"], .bg-surface, .bg-surface-raised) :is(section, aside, article, [role="region"], [data-kit-card], .bg-surface:not(input):not(select):not(textarea):not(button):not([role="combobox"]):not([role="spinbutton"]):not([role="switch"]):not(td):not(tr))) :is(.bg-surface-sunken, table th) { --soma-surface-sunken: var(--soma-surface-canvas); background-color: var(--soma-surface-canvas); }
|
|
1467
|
+
[data-soma-host] :is(.bg-surface-sunken:not(main):not(.min-h-screen):not([data-soma-id="frame__root"]), :is(section, aside, article, [role="region"], .bg-surface, .bg-surface-raised) :is(section, aside, article, [role="region"], [data-kit-card], .bg-surface:not(input):not(select):not(textarea):not(button):not([role="combobox"]):not([role="spinbutton"]):not([role="switch"]):not(td):not(tr))) :is(kbd.bg-surface-sunken, span.bg-surface-sunken, code.bg-surface-sunken) { --soma-surface-sunken: var(--soma-surface-card); background-color: var(--soma-surface-card); }
|
|
1468
|
+
[data-soma-host] :is(.fixed.bg-surface-raised, .absolute.bg-surface-raised, [role="dialog"].bg-surface-raised, [role="alertdialog"].bg-surface-raised, [role="listbox"].bg-surface-raised, [role="menu"].bg-surface-raised, [data-kit-floating="true"]) { --soma-surface-raised: var(--soma-surface-float); --soma-surface-base: var(--soma-surface-float); background-color: var(--soma-surface-float); box-shadow: var(--soma-shadow-popover); }
|
|
1469
|
+
[data-soma-host] :is([role="dialog"], [role="alertdialog"]).bg-surface-raised { box-shadow: var(--soma-shadow-dialog); }
|
|
1275
1470
|
${buildDynamicPaletteRulesCss()}
|
|
1276
1471
|
:root[data-kit-boundary="BORDERLESS_SHADOW"], [data-soma-host][data-kit-boundary="BORDERLESS_SHADOW"] { --soma-border-hairline: transparent; --soma-border-strong: transparent; }
|
|
1277
1472
|
`;
|