-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
141 lines (124 loc) · 3.22 KB
/
index.js
File metadata and controls
141 lines (124 loc) · 3.22 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { slideVars } from "./src/index.ts";
import "./src/logo.ts";
// Tab switching
document.querySelectorAll(".tab-button").forEach((button) => {
button.addEventListener("click", () => {
const tab = button.dataset.tab;
// Update buttons
document.querySelectorAll(".tab-button").forEach((b) => {
b.classList.remove("active");
b.setAttribute("aria-selected", "false");
});
button.classList.add("active");
button.setAttribute("aria-selected", "true");
// Update content
document.querySelectorAll(".tab-content").forEach((c) => {
c.classList.remove("active");
c.setAttribute("hidden", "");
});
const activeTab = document.getElementById(`${tab}-tab`);
activeTab.classList.add("active");
activeTab.removeAttribute("hidden");
// Switch demo after a small delay to ensure DOM is updated
requestAnimationFrame(() => {
setTimeout(() => switchDemo(tab), 10);
});
});
});
let currentInstance = null;
function switchDemo(tab) {
// Destroy existing instance
if (currentInstance) {
slideVars.destroy();
}
if (tab === "auto") {
// Auto-detection demo (with one manual just for fun)
slideVars.init(
{
"--shadow-size": {
type: "slider",
min: 3,
max: 30,
default: 10,
unit: "px",
},
},
{
auto: true,
filterVariables: ["--arc-"],
}
);
} else {
// Manual configuration demo
slideVars.init({
"--width": {
type: "slider",
min: 50,
max: 400,
default: 100,
unit: "px",
scope: "#manual-demo",
},
"--height": {
type: "slider",
min: 50,
max: 400,
default: 100,
unit: "px",
scope: "#manual-demo",
},
"--bg": {
type: "color",
default: "#667eea",
scope: "#manual-demo",
},
"--radius": {
type: "slider",
min: 0,
max: 200,
default: 0,
unit: "px",
scope: "#manual-demo",
},
});
}
}
// Initialize with auto-detection
switchDemo("auto");
// Update live CSS values
function updateLiveValues() {
const liveValues = document.querySelectorAll(".live-value");
liveValues.forEach((span) => {
const varName = span.dataset.var;
if (varName) {
// Try to read from the appropriate scope
let value = "";
// Check if variable is in manual demo
if (!value) {
const manualDemo = document.getElementById("manual-demo");
if (manualDemo) {
value = getComputedStyle(manualDemo).getPropertyValue(varName).trim();
}
}
// Fall back to :root / body
if (!value) {
value = getComputedStyle(document.documentElement)
.getPropertyValue(varName)
.trim();
}
span.textContent = value || "inherit";
}
});
}
// Update on initialization
setTimeout(updateLiveValues, 100);
// Watch for style changes on body element
const observer = new MutationObserver(() => {
updateLiveValues();
});
observer.observe(document.body, {
attributes: true,
attributeFilter: ["style"],
});
// Also update periodically as a fallback
setInterval(updateLiveValues, 200);