Skip to content

Commit 564ff15

Browse files
authored
Merge pull request #974 from 00zsq/master
chore: upgrade Vite to v7, fix header footer and customize layouts & …
2 parents c2ddb35 + d928dcf commit 564ff15

File tree

9 files changed

+635
-485
lines changed

9 files changed

+635
-485
lines changed

packages/omi-templates/index.html

Lines changed: 98 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,117 @@
11
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<link rel="icon" href="https://omi.cdn-go.cn/play/latest/assets/favicon.974a6ddb.ico">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>100+ OMI Tailwind Templates</title>
8-
</head>
9-
<body>
10-
<div id="app"></div>
11-
<script>
12-
document.addEventListener('DOMContentLoaded', function () {
13-
try {
14-
if (
15-
localStorage.theme === "dark" ||
16-
(!("theme" in localStorage) &&
17-
window.matchMedia("(prefers-color-scheme: dark)").matches)
18-
) {
19-
walkDOMAndToggleDark(document.body, false)
20-
document.documentElement.classList.add("dark");
21-
} else {
22-
walkDOMAndToggleDark(document.body, true)
23-
document.documentElement.classList.remove("dark");
24-
}
25-
} catch (_) { }
26-
})
27-
28-
29-
function toggleNodeDark(node, isDark) {
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<link rel="icon" href="https://omi.cdn-go.cn/play/latest/assets/favicon.974a6ddb.ico">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>100+ OMI Tailwind Templates</title>
9+
</head>
10+
11+
<body>
12+
<div id="app"></div>
13+
<script>
14+
document.addEventListener('DOMContentLoaded', function () {
15+
try {
3016
if (
31-
node instanceof HTMLElement &&
32-
node.tagName.toLowerCase().indexOf("-") !== -1
17+
localStorage.theme === "dark" ||
18+
(!("theme" in localStorage) &&
19+
window.matchMedia("(prefers-color-scheme: dark)").matches)
3320
) {
34-
if (isDark) {
35-
node.classList.remove("dark");
36-
} else {
37-
node.classList.add("dark");
38-
}
39-
40-
}
41-
}
42-
43-
function walkDOMAndToggleDark(rootNode, isDark) {
44-
if (isDark) {
45-
document.documentElement.classList.remove("dark");
46-
} else {
21+
walkDOMAndToggleDark(document.body, false)
4722
document.documentElement.classList.add("dark");
48-
}
49-
const treeWalker = document.createTreeWalker(
50-
rootNode,
51-
NodeFilter.SHOW_ELEMENT,
52-
null,
53-
false
54-
);
55-
56-
while (treeWalker.nextNode()) {
57-
const node = treeWalker.currentNode;
58-
toggleNodeDark(node, isDark);
59-
60-
// Check if the node has a shadow root
61-
if (node.shadowRoot) {
62-
walkDOMAndToggleDark(node.shadowRoot, isDark);
63-
}
64-
65-
// Check if the node has assigned nodes (for slots)
66-
if (node.assignedNodes) {
67-
node.assignedNodes().forEach((assignedNode) => {
68-
if (assignedNode.nodeType === Node.ELEMENT_NODE) {
69-
walkDOMAndToggleDark(assignedNode, isDark);
70-
}
71-
});
72-
}
73-
}
74-
}
75-
76-
function toogleDark() {
77-
if (document.documentElement.classList.contains("dark")) {
78-
localStorage.theme = "light";
23+
} else {
7924
walkDOMAndToggleDark(document.body, true)
8025
document.documentElement.classList.remove("dark");
26+
}
27+
} catch (_) { }
28+
})
29+
30+
31+
function toggleNodeDark(node, isDark) {
32+
if (
33+
node instanceof HTMLElement &&
34+
node.tagName.toLowerCase().indexOf("-") !== -1
35+
) {
36+
if (isDark) {
37+
node.classList.remove("dark");
8138
} else {
82-
localStorage.theme = "dark";
83-
walkDOMAndToggleDark(document.body, false)
84-
document.documentElement.classList.add("dark");
39+
node.classList.add("dark");
8540
}
41+
8642
}
43+
}
8744

88-
function setDarkMode() {
89-
localStorage.theme = "dark";
90-
walkDOMAndToggleDark(document.body, false)
45+
function walkDOMAndToggleDark(rootNode, isDark) {
46+
if (isDark) {
47+
document.documentElement.classList.remove("dark");
48+
} else {
9149
document.documentElement.classList.add("dark");
9250
}
51+
const treeWalker = document.createTreeWalker(
52+
rootNode,
53+
NodeFilter.SHOW_ELEMENT,
54+
null,
55+
false
56+
);
57+
58+
while (treeWalker.nextNode()) {
59+
const node = treeWalker.currentNode;
60+
toggleNodeDark(node, isDark);
61+
62+
// Check if the node has a shadow root
63+
if (node.shadowRoot) {
64+
walkDOMAndToggleDark(node.shadowRoot, isDark);
65+
}
9366

94-
function setLightMode() {
67+
// Check if the node has assigned nodes (for slots)
68+
if (node.assignedNodes) {
69+
node.assignedNodes().forEach((assignedNode) => {
70+
if (assignedNode.nodeType === Node.ELEMENT_NODE) {
71+
walkDOMAndToggleDark(assignedNode, isDark);
72+
}
73+
});
74+
}
75+
}
76+
}
77+
78+
function toogleDark() {
79+
if (document.documentElement.classList.contains("dark")) {
9580
localStorage.theme = "light";
9681
walkDOMAndToggleDark(document.body, true)
9782
document.documentElement.classList.remove("dark");
83+
} else {
84+
localStorage.theme = "dark";
85+
walkDOMAndToggleDark(document.body, false)
86+
document.documentElement.classList.add("dark");
9887
}
99-
100-
function refreshDark() {
101-
if (document.documentElement.classList.contains("dark")) {
102-
walkDOMAndToggleDark(document.body, false)
103-
} else {
104-
walkDOMAndToggleDark(document.body, true)
105-
}
88+
}
89+
90+
function setDarkMode() {
91+
localStorage.theme = "dark";
92+
walkDOMAndToggleDark(document.body, false)
93+
document.documentElement.classList.add("dark");
94+
}
95+
96+
function setLightMode() {
97+
localStorage.theme = "light";
98+
walkDOMAndToggleDark(document.body, true)
99+
document.documentElement.classList.remove("dark");
100+
}
101+
102+
function refreshDark() {
103+
if (document.documentElement.classList.contains("dark")) {
104+
walkDOMAndToggleDark(document.body, false)
105+
} else {
106+
walkDOMAndToggleDark(document.body, true)
106107
}
107-
108-
window.addEventListener('load', function() {
109-
refreshDark()
110-
})
111-
</script>
112-
<script type="module" src="/src/main.tsx"></script>
113-
</body>
114-
</html>
108+
}
109+
110+
window.addEventListener('load', function () {
111+
refreshDark()
112+
})
113+
</script>
114+
<script type="module" src="/src/main.tsx"></script>
115+
</body>
116+
117+
</html>

packages/omi-templates/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
"tailwindcss": "^4.0.0",
3939
"ts-node": "^10.9.1",
4040
"typescript": "^5.0.2",
41-
"vite": "^5.0.0"
41+
"vite": "^7.0.0"
4242
}
4343
}

0 commit comments

Comments
 (0)