Repository navigation
Expand file tree
/
Copy paththeme.js
More file actions
46 lines (41 loc) · 1.5 KB
/
Copy paththeme.js
File metadata and controls
46 lines (41 loc) · 1.5 KB
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
/* ============================================
🐍 پایتونباز آرکید — تم
============================================ */
PB.theme = (() => {
function current() {
const state = PB.store.get();
return state.settings.theme === "light" ? "light" : "dark";
}
function apply(theme) {
const prev = document.documentElement.getAttribute("data-theme");
document.documentElement.setAttribute("data-theme", theme);
// فقط وقتی تم واقعاً تغییر کرده مستقیم بنویس؛
// تو toggle ذخیرهسازی اصلی رو PB.store.update انجام میده
if (prev !== theme) {
try {
localStorage.setItem(PB.store.THEME_KEY, theme);
} catch (_) { /* ignore */ }
}
}
function toggle() {
const next = current() === "dark" ? "light" : "dark";
apply(next);
// همزمان در store هم ذخیره کن
PB.store.update((s) => {
s.settings.theme = next;
});
return next;
}
function init() {
// اول از localStorage اختصاصی، بعد از store
let theme = null;
try {
theme = localStorage.getItem(PB.store.THEME_KEY);
} catch (_) { /* ignore */ }
if (!theme) {
theme = PB.store.get().settings.theme;
}
apply(theme === "light" ? "light" : "dark");
}
return { current, apply, toggle, init };
})();