Skip to content

Commit dd1d373

Browse files
committed
Update theme-palette.js
1 parent f8fa155 commit dd1d373

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

docs/assets/javascripts/theme-palette.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
id: "md3",
77
name: "MD3 默认",
88
primary: "#6750A4",
9-
accent: "#EFB8C8",
9+
accent: "#9C8DC4",
1010
},
1111
{
1212
id: "teal_purple",
@@ -120,6 +120,14 @@
120120
style.textContent = lines.join("\n");
121121
}
122122

123+
function applyDefaultAccentFromPrimary() {
124+
const p = getCssVar("--md-primary-fg-color");
125+
const pHex = rgbStringToHex(p) || (isHexColor(p) ? p : null);
126+
if (!pHex) return;
127+
const aHex = lightenHex(pHex, 0.35) || pHex;
128+
applyColors(pHex, aHex);
129+
}
130+
123131
function createHeaderButton() {
124132
const btn = document.createElement("button");
125133
btn.type = "button";
@@ -166,7 +174,10 @@
166174
const p = getCssVar("--md-primary-fg-color");
167175
const a = getCssVar("--md-accent-fg-color");
168176
const pHex = rgbStringToHex(p) || (isHexColor(p) ? p : null);
169-
const aHex = rgbStringToHex(a) || (isHexColor(a) ? a : null);
177+
let aHex = rgbStringToHex(a) || (isHexColor(a) ? a : null);
178+
179+
if (pHex && (!aHex || aHex.toUpperCase() === pHex.toUpperCase())) aHex = lightenHex(pHex, 0.35) || pHex;
180+
170181
if (pHex) primaryInput.value = pHex;
171182
if (aHex) accentInput.value = aHex;
172183
}
@@ -239,7 +250,7 @@
239250
accentText.textContent = "强调色";
240251
const accentInput = document.createElement("input");
241252
accentInput.type = "color";
242-
accentInput.value = "#EFB8C8";
253+
accentInput.value = "#9C8DC4";
243254
accentWrap.appendChild(accentText);
244255
accentWrap.appendChild(accentInput);
245256

@@ -317,7 +328,7 @@
317328
});
318329

319330
resetBtn.addEventListener("click", () => {
320-
clearStyleTag();
331+
applyDefaultAccentFromPrimary();
321332
requestAnimationFrame(() => {
322333
syncInputsToComputed(primaryInput, accentInput);
323334
});
@@ -327,6 +338,7 @@
327338
}
328339

329340
function mount() {
341+
applyDefaultAccentFromPrimary();
330342
if (document.querySelector(".theme-palette-overlay")) return;
331343
const { overlay, open } = createDialog();
332344
document.body.appendChild(overlay);

0 commit comments

Comments
 (0)