-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
345 lines (318 loc) · 16.9 KB
/
index.html
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, orientation=portrait, maximum-scale=1.0, user-scalable=no">
<meta name="screen-orientation" content="portrait">
<meta name="x5-orientation" content="portrait">
<title>K-Map Solver</title>
<meta name="description"
content="A lightweight, dependency-free Karnaugh map solver with truth table visualization and 2-4 variable support. Features color-coded term grouping with wraparound highlighting. Works offline and includes light/dark themes for enhanced usability.">
<meta property="og:title" content="K-Map Solver">
<meta property="og:description"
content="A lightweight, dependency-free Karnaugh map solver with truth table visualization and 2-4 variable support. Features color-coded term grouping with wraparound highlighting. Works offline and includes light/dark themes for enhanced usability.">
<meta property="og:type" content="website">
<meta property="og:image" content="https://kmap.robonxt.xyz/assets/logo/kmap-logo-v1.jpeg">
<meta property="og:url" content="https://kmap.robonxt.xyz">
<link rel="icon" type="image/x-icon" href="assets/icons/favicon.ico">
<link rel="icon" type="image/svg+xml" href="assets/icons/favicon.svg" />
<link rel="icon" type="image/png" sizes="192x192" href="assets/icons/android-chrome-192.png">
<link rel="icon" type="image/png" sizes="512x512" href="assets/icons/android-chrome-512.png">
<link rel="apple-touch-icon" href="assets/icons/apple-touch-icon.png">
<meta name="msapplication-TileImage" content="assets/icons/mstile.png">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="theme-color" content="#ffffff">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" href="styles.css">
<script>
// Register service worker for offline functionality
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('sw.js')
.then(registration => {
console.log('Service Worker registered successfully');
})
.catch(error => {
console.warn('Service Worker registration failed:', error);
});
});
}
</script>
</head>
<body>
<div class="container">
<div class="popup-overlay" id="info-popup">
<div class="popup-wrapper">
<button class="close-btn svg-button" id="close-popup-btn" aria-label="Close">
<svg viewBox="0 0 24 24">
<path d="M6 6l12 12M6 18L18 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
</svg>
</button>
<div class="popup-content" id="info-content">
<h2>K-Map Solver Guide</h2>
<p>A K-map helps simplify Boolean expressions by grouping similar terms. This tool provides an
interactive way to build and solve K-maps, automatically finding the simplest solution.</p>
<h3>Quick Start</h3>
<ol>
<li><strong>Choose Variables</strong> (2-4)
<ul>
<li>Select from dropdown</li>
<li>Grid adjusts automatically</li>
</ul>
</li>
<li><strong>Set Values</strong>
<ul>
<li>Click cells to toggle: 0 → 1 → X
<ul><li>A blank cell (ㅤ) is 0</li></ul>
</li>
<li>X = "don't care" condition</li>
<li>Quick buttons: Set All 1, 0 (Clear)</li>
</ul>
</li>
<li><strong>View Solution</strong>
<ul>
<li>Updates in real-time</li>
<li>Copy button for easy sharing</li>
<li>Multiple solutions when available</li>
</ul>
</li>
</ol>
<h3>Reading Solutions</h3>
<ul>
<li>A = variable is 1 (true)</li>
<li>A̅ = variable is 0 (false).
</li>
<li>Example: A̅BC̅ means A=0, B=1, C=0</li>
</ul>
<h3>Features</h3>
<ul>
<li>Switch between K-map and Truth Table views</li>
<li>Toggle Gray/Binary layouts (3-4 vars)</li>
<li>Hide zeros in cells for cleaner display</li>
<li>Light/Dark theme support</li>
<li>Color-coded grouping</li>
<li>Mobile-friendly design</li>
<li>Progressive Web App (PWA) support:
<ul>
<li>Works offline</li>
<li>Installable on mobile and desktop</li>
<li>App-like experience</li>
<li><a href="pwa-check.html">Check PWA Status</a></li>
</ul>
</li>
</ul>
<p><a href="https://github.com/robonxt/web-kmap" target="_blank">View Source on GitHub</a></p>
</div>
</div>
</div>
<div class="header-bar-container">
<div class="header-tab-menu">
<button class="hamburger-menu svg-button" id="hamburger-menu-btn" aria-label="Menu">
<svg viewBox="0 0 24 24">
<path d="M3 12h18M3 6h18M3 18h18" stroke="currentColor" stroke-width="2"
stroke-linecap="round" />
</svg>
</button>
<div class="tabs-wrapper" id="tabs-wrapper">
<button class="tab-btn active" id="kmap-tab-btn" data-tab="kmap">K-Map</button>
<button class="tab-btn" id="truthtable-tab-btn" data-tab="truthtable">Truth Table</button>
<div class="slider-bg" id="slider-bg"></div>
</div>
</div>
<div class="header-controls">
<!-- <button class="svg-button" id="hide-zeros-btn" title="Toggle zero visibility">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<ellipse cx="12" cy="12" rx="7" ry="10" />
<line x1="1" y1="1" x2="23" y2="23" />
</svg>
</button> -->
<button class="svg-button" id="theme-toggle" aria-label="Toggle theme">
<svg class="light-theme-icon" viewBox="0 0 24 24">
<circle cx="12" cy="12" r="5" fill="none" stroke="currentColor" stroke-width="2" />
<path
d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
fill="none" />
</svg>
<svg class="dark-theme-icon" viewBox="0 0 24 24">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
</svg>
</button>
<button class="svg-button info-btn" id="info-btn" aria-label="Show Information">
<svg viewBox="0 0 24 24">
<circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2" />
<circle cx="12" cy="8" r="1" fill="currentColor" />
<path d="M12 11v7" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
</svg>
</button>
</div>
</div>
<div class="solution-container">
<div class="solution-header">
<h3>Answer</h3><select id="solution-select" class="solution-select"></select>
</div>
<div class="solution-toolbar">
<div id="solution"></div>
<button id="copy-solution" class="svg-button" title="Copy to clipboard">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
</svg>
</button>
</div>
</div>
<div class="control-container">
<select id="var-select" class="var-select" title="Select number of variables">
<option value="4">4 Vars</option>
<option value="3">3 Vars</option>
<option value="2">2 Vars</option>
</select>
<button id="toggle-layout-btn" class="svg-button gray-layout" aria-label="Toggle Layout"
title="Switch Layout">
<svg class="gray-layout-icon" viewBox="0 0 24 24">
<rect x="4" y="4" width="7" height="7" fill="none" stroke="currentColor" stroke-width="2" />
<rect x="13" y="13" width="7" height="7" fill="none" stroke="currentColor" stroke-width="2" />
<path d="M17 7l3-3-3-3M7 17l-3 3 3 3" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" fill="none" />
</svg>
<svg class="binary-layout-icon" viewBox="0 0 24 24">
<rect x="4" y="13" width="7" height="7" fill="none" stroke="currentColor" stroke-width="2" />
<rect x="13" y="4" width="7" height="7" fill="none" stroke="currentColor" stroke-width="2" />
<path d="M7 7l-3-3 3-3M17 17l3 3-3 3" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" fill="none" />
</svg>
<span class="layout-text">CD/AB</span>
</button>
<button class="svg-button" id="all-one-btn">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<path d="M20 6L9 17l-5-5" />
</svg>
All 1
</button>
<button class="svg-button" id="all-zero-btn">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<path d="M3 6h18" />
<path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2" />
</svg>
Clear
</button>
</div>
<div class="tab-content-container active" id="kmap">
<div class="kmap-grid" id="kmap-grid"></div>
</div>
<div class="tab-content-container" id="truthtable">
<table class="truth-table">
<thead>
<tr>
<th>#</th>
<th>A</th>
<th>B</th>
<th class="var-c">C</th>
<th class="var-d">D</th>
<th>Output</th>
</tr>
</thead>
<tbody id="truth-table-body"></tbody>
</table>
</div>
</div>
<script src="kmap-solver.js" defer></script>
<script src="kmap-interface.js" defer></script>
<script>
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
new KMapInterface();
// Add hamburger menu toggle
const hamburgerBtn = document.getElementById('hamburger-menu-btn');
const tabsWrapper = document.getElementById('tabs-wrapper');
const sliderBg = document.getElementById('slider-bg');
const tabBtns = document.querySelectorAll('.tab-btn');
// Info popup functionality
const infoBtn = document.getElementById('info-btn');
const closeBtn = document.getElementById('close-popup-btn');
const infoPopup = document.getElementById('info-popup');
// Function to update slider position
function updateSlider(activeTab) {
// if (window.innerWidth > 400 && sliderBg && activeTab) {
if (sliderBg && activeTab) {
const tabWidth = activeTab.offsetWidth;
const tabLeft = activeTab.offsetLeft;
sliderBg.style.width = `${tabWidth}px`;
sliderBg.style.transform = `translateX(${tabLeft}px)`;
}
}
if (hamburgerBtn && tabsWrapper) {
hamburgerBtn.addEventListener('click', () => {
tabsWrapper.classList.toggle('show');
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!tabsWrapper.contains(e.target) && !hamburgerBtn.contains(e.target)) {
tabsWrapper.classList.remove('show');
}
});
// Update slider when switching tabs
tabBtns.forEach(btn => {
btn.addEventListener('click', () => {
tabsWrapper.classList.remove('show');
setTimeout(() => updateSlider(btn), 0);
});
});
}
// Initial slider position
const initialActiveTab = document.querySelector('.tab-btn.active');
updateSlider(initialActiveTab);
// Info popup functionality
infoBtn.addEventListener('click', () => infoPopup.classList.add('active'));
closeBtn.addEventListener('click', () => infoPopup.classList.remove('active'));
infoPopup.addEventListener('click', (e) => {
if (e.target === e.currentTarget) e.currentTarget.classList.remove('active');
});
// Theme handling
const themeToggle = document.getElementById('theme-toggle');
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
const prefersLightScheme = window.matchMedia('(prefers-color-scheme: light)');
// Initialize theme
function initializeTheme() {
const storedTheme = localStorage.getItem('theme');
let theme = 'light'; // Default theme
if (storedTheme) {
theme = storedTheme;
} else if (prefersLightScheme.matches) {
theme = 'light';
} else if (prefersDarkScheme.matches) {
theme = 'dark';
}
document.body.setAttribute('data-theme', theme);
themeToggle.setAttribute('data-theme', theme);
}
// Initialize theme on load
initializeTheme();
// Handle theme toggle click
themeToggle.addEventListener('click', () => {
const currentTheme = document.body.getAttribute('data-theme');
// Switch TO the theme that matches the visible icon
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
// console.log(`Switching to ${newTheme} theme`);
document.body.setAttribute('data-theme', newTheme);
themeToggle.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
});
// Handle system theme changes
prefersLightScheme.addEventListener('change', (e) => {
if (!localStorage.getItem('theme')) {
const theme = e.matches ? 'light' : 'dark';
document.body.setAttribute('data-theme', theme);
themeToggle.setAttribute('data-theme', theme);
}
});
});
</script>
</body>
</html>