karaltan commited on
Commit
562d697
·
verified ·
1 Parent(s): 1219817

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +343 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Mathcalculator
3
- emoji: 🏢
4
  colorFrom: blue
5
- colorTo: pink
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: mathcalculator
3
+ emoji: 🐳
4
  colorFrom: blue
5
+ colorTo: blue
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,343 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>MathMagic - Four Operations Calculator</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ .calculator-btn {
11
+ transition: all 0.2s ease;
12
+ transform: scale(1);
13
+ }
14
+ .calculator-btn:active {
15
+ transform: scale(0.95);
16
+ }
17
+ .operation-btn {
18
+ background: linear-gradient(135deg, #3b82f6, #1d4ed8);
19
+ }
20
+ .operation-btn:hover {
21
+ background: linear-gradient(135deg, #1d4ed8, #3b82f6);
22
+ }
23
+ .equals-btn {
24
+ background: linear-gradient(135deg, #10b981, #059669);
25
+ }
26
+ .equals-btn:hover {
27
+ background: linear-gradient(135deg, #059669, #10b981);
28
+ }
29
+ .clear-btn {
30
+ background: linear-gradient(135deg, #ef4444, #dc2626);
31
+ }
32
+ .clear-btn:hover {
33
+ background: linear-gradient(135deg, #dc2626, #ef4444);
34
+ }
35
+ .history-item {
36
+ transition: all 0.3s ease;
37
+ }
38
+ .history-item:hover {
39
+ background-color: rgba(255, 255, 255, 0.1);
40
+ transform: translateX(5px);
41
+ }
42
+ .display-text {
43
+ text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
44
+ }
45
+ @keyframes pulse {
46
+ 0% { opacity: 0.5; }
47
+ 50% { opacity: 1; }
48
+ 100% { opacity: 0.5; }
49
+ }
50
+ .pulse-animation {
51
+ animation: pulse 1.5s infinite;
52
+ }
53
+ </style>
54
+ </head>
55
+ <body class="bg-gray-900 text-white min-h-screen flex items-center justify-center p-4">
56
+ <div class="max-w-md w-full bg-gray-800 rounded-2xl overflow-hidden shadow-2xl">
57
+ <!-- Header -->
58
+ <div class="bg-gradient-to-r from-blue-600 to-purple-600 p-6 flex items-center justify-between">
59
+ <div>
60
+ <h1 class="text-2xl font-bold">MathMagic</h1>
61
+ <p class="text-blue-100 text-sm">Four Operations Calculator</p>
62
+ </div>
63
+ <div class="bg-white bg-opacity-20 p-2 rounded-full">
64
+ <i class="fas fa-calculator text-2xl"></i>
65
+ </div>
66
+ </div>
67
+
68
+ <!-- Display -->
69
+ <div class="p-6 bg-gray-700 relative">
70
+ <div class="bg-gray-800 rounded-xl p-4 min-h-24 flex flex-col justify-end">
71
+ <div id="history" class="text-gray-400 text-sm h-6 overflow-hidden whitespace-nowrap"></div>
72
+ <div id="display" class="display-text text-3xl font-semibold text-right overflow-x-auto">0</div>
73
+ </div>
74
+ <div id="error-message" class="absolute bottom-1 right-4 text-red-400 text-sm hidden">
75
+ <i class="fas fa-exclamation-circle mr-1"></i>
76
+ <span>Invalid input</span>
77
+ </div>
78
+ </div>
79
+
80
+ <!-- Calculator Body -->
81
+ <div class="grid grid-cols-4 gap-3 p-6">
82
+ <!-- First Row -->
83
+ <button onclick="clearAll()" class="clear-btn calculator-btn col-span-2 py-4 rounded-xl font-bold text-white shadow-md">
84
+ <i class="fas fa-eraser mr-2"></i>Clear
85
+ </button>
86
+ <button onclick="backspace()" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md">
87
+ <i class="fas fa-backspace"></i>
88
+ </button>
89
+ <button onclick="appendOperation('/')" class="operation-btn calculator-btn py-4 rounded-xl font-bold text-white shadow-md">
90
+ <i class="fas fa-divide"></i>
91
+ </button>
92
+
93
+ <!-- Number Rows -->
94
+ <button onclick="appendNumber('7')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">7</button>
95
+ <button onclick="appendNumber('8')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">8</button>
96
+ <button onclick="appendNumber('9')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">9</button>
97
+ <button onclick="appendOperation('*')" class="operation-btn calculator-btn py-4 rounded-xl font-bold text-white shadow-md">
98
+ <i class="fas fa-times"></i>
99
+ </button>
100
+
101
+ <button onclick="appendNumber('4')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">4</button>
102
+ <button onclick="appendNumber('5')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">5</button>
103
+ <button onclick="appendNumber('6')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">6</button>
104
+ <button onclick="appendOperation('-')" class="operation-btn calculator-btn py-4 rounded-xl font-bold text-white shadow-md">
105
+ <i class="fas fa-minus"></i>
106
+ </button>
107
+
108
+ <button onclick="appendNumber('1')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">1</button>
109
+ <button onclick="appendNumber('2')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">2</button>
110
+ <button onclick="appendNumber('3')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">3</button>
111
+ <button onclick="appendOperation('+')" class="operation-btn calculator-btn py-4 rounded-xl font-bold text-white shadow-md">
112
+ <i class="fas fa-plus"></i>
113
+ </button>
114
+
115
+ <!-- Last Row -->
116
+ <button onclick="appendNumber('0')" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">0</button>
117
+ <button onclick="appendDecimal()" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">.</button>
118
+ <button onclick="toggleSign()" class="calculator-btn bg-gray-600 py-4 rounded-xl font-bold text-white shadow-md hover:bg-gray-500">
119
+ <i class="fas fa-plus-minus"></i>
120
+ </button>
121
+ <button onclick="calculate()" class="equals-btn calculator-btn py-4 rounded-xl font-bold text-white shadow-md">
122
+ <i class="fas fa-equals"></i>
123
+ </button>
124
+ </div>
125
+
126
+ <!-- History Section -->
127
+ <div class="bg-gray-700 p-4 border-t border-gray-600 max-h-40 overflow-y-auto">
128
+ <div class="flex items-center justify-between text-gray-400 mb-2">
129
+ <h3 class="font-medium"><i class="fas fa-history mr-2"></i>History</h3>
130
+ <button onclick="clearHistory()" class="text-xs hover:text-white">
131
+ <i class="fas fa-trash-alt mr-1"></i>Clear
132
+ </button>
133
+ </div>
134
+ <div id="history-list" class="space-y-1">
135
+ <!-- History items will be added here -->
136
+ </div>
137
+ </div>
138
+ </div>
139
+
140
+ <script>
141
+ // Calculator state
142
+ let currentInput = '0';
143
+ let previousInput = '';
144
+ let operation = null;
145
+ let resetInput = false;
146
+ let calculationHistory = [];
147
+
148
+ // DOM elements
149
+ const display = document.getElementById('display');
150
+ const historyDisplay = document.getElementById('history');
151
+ const historyList = document.getElementById('history-list');
152
+ const errorMessage = document.getElementById('error-message');
153
+
154
+ // Update the display
155
+ function updateDisplay() {
156
+ display.textContent = currentInput;
157
+ historyDisplay.textContent = previousInput + (operation ? ` ${operation} ` : '');
158
+ }
159
+
160
+ // Append number to current input
161
+ function appendNumber(number) {
162
+ if (currentInput === '0' || resetInput) {
163
+ currentInput = number;
164
+ resetInput = false;
165
+ } else {
166
+ currentInput += number;
167
+ }
168
+ updateDisplay();
169
+ }
170
+
171
+ // Append decimal point
172
+ function appendDecimal() {
173
+ if (resetInput) {
174
+ currentInput = '0.';
175
+ resetInput = false;
176
+ } else if (!currentInput.includes('.')) {
177
+ currentInput += '.';
178
+ }
179
+ updateDisplay();
180
+ }
181
+
182
+ // Toggle positive/negative
183
+ function toggleSign() {
184
+ currentInput = (parseFloat(currentInput) * -1).toString();
185
+ updateDisplay();
186
+ }
187
+
188
+ // Handle operations
189
+ function appendOperation(op) {
190
+ // If there's a previous operation waiting, calculate it first
191
+ if (operation && !resetInput) {
192
+ calculate();
193
+ }
194
+
195
+ previousInput = currentInput;
196
+ operation = op;
197
+ resetInput = true;
198
+ updateDisplay();
199
+ }
200
+
201
+ // Calculate the result
202
+ function calculate() {
203
+ hideError();
204
+
205
+ if (operation === null || resetInput) return;
206
+
207
+ const prev = parseFloat(previousInput);
208
+ const current = parseFloat(currentInput);
209
+
210
+ if (isNaN(prev) || isNaN(current)) {
211
+ showError();
212
+ return;
213
+ }
214
+
215
+ let result;
216
+ switch (operation) {
217
+ case '+':
218
+ result = prev + current;
219
+ break;
220
+ case '-':
221
+ result = prev - current;
222
+ break;
223
+ case '*':
224
+ result = prev * current;
225
+ break;
226
+ case '/':
227
+ if (current === 0) {
228
+ showError("Can't divide by zero");
229
+ return;
230
+ }
231
+ result = prev / current;
232
+ break;
233
+ default:
234
+ return;
235
+ }
236
+
237
+ // Add to history
238
+ const historyItem = `${previousInput} ${operation} ${currentInput} = ${result}`;
239
+ calculationHistory.unshift(historyItem);
240
+ updateHistory();
241
+
242
+ currentInput = result.toString();
243
+ operation = null;
244
+ resetInput = true;
245
+ updateDisplay();
246
+ }
247
+
248
+ // Clear everything
249
+ function clearAll() {
250
+ currentInput = '0';
251
+ previousInput = '';
252
+ operation = null;
253
+ hideError();
254
+ updateDisplay();
255
+ }
256
+
257
+ // Backspace function
258
+ function backspace() {
259
+ if (currentInput.length === 1 || (currentInput.length === 2 && currentInput.startsWith('-'))) {
260
+ currentInput = '0';
261
+ } else {
262
+ currentInput = currentInput.slice(0, -1);
263
+ }
264
+ updateDisplay();
265
+ }
266
+
267
+ // Show error message
268
+ function showError(message = "Invalid input") {
269
+ errorMessage.querySelector('span').textContent = message;
270
+ errorMessage.classList.remove('hidden');
271
+ display.classList.add('text-red-400');
272
+ setTimeout(() => {
273
+ display.classList.remove('text-red-400');
274
+ }, 1000);
275
+ }
276
+
277
+ // Hide error message
278
+ function hideError() {
279
+ errorMessage.classList.add('hidden');
280
+ display.classList.remove('text-red-400');
281
+ }
282
+
283
+ // Update history list
284
+ function updateHistory() {
285
+ historyList.innerHTML = '';
286
+ calculationHistory.slice(0, 5).forEach(item => {
287
+ const historyElement = document.createElement('div');
288
+ historyElement.className = 'history-item bg-gray-600 bg-opacity-50 p-2 rounded cursor-pointer';
289
+ historyElement.textContent = item;
290
+ historyElement.onclick = function() {
291
+ // When clicking a history item, load the result
292
+ const parts = item.split(' = ');
293
+ if (parts.length === 2) {
294
+ currentInput = parts[1];
295
+ resetInput = true;
296
+ updateDisplay();
297
+ }
298
+ };
299
+ historyList.appendChild(historyElement);
300
+ });
301
+ }
302
+
303
+ // Clear history
304
+ function clearHistory() {
305
+ calculationHistory = [];
306
+ updateHistory();
307
+
308
+ // Add a temporary message
309
+ const emptyMessage = document.createElement('div');
310
+ emptyMessage.className = 'text-center text-gray-400 py-2 pulse-animation';
311
+ emptyMessage.innerHTML = '<i class="fas fa-history mr-2"></i>History is empty';
312
+ historyList.appendChild(emptyMessage);
313
+
314
+ setTimeout(() => {
315
+ if (calculationHistory.length === 0 && historyList.contains(emptyMessage)) {
316
+ historyList.removeChild(emptyMessage);
317
+ }
318
+ }, 2000);
319
+ }
320
+
321
+ // Keyboard support
322
+ document.addEventListener('keydown', function(event) {
323
+ if (/[0-9]/.test(event.key)) {
324
+ appendNumber(event.key);
325
+ } else if (event.key === '.') {
326
+ appendDecimal();
327
+ } else if (event.key === '+' || event.key === '-' || event.key === '*' || event.key === '/') {
328
+ appendOperation(event.key);
329
+ } else if (event.key === 'Enter' || event.key === '=') {
330
+ calculate();
331
+ } else if (event.key === 'Escape') {
332
+ clearAll();
333
+ } else if (event.key === 'Backspace') {
334
+ backspace();
335
+ }
336
+ });
337
+
338
+ // Initialize
339
+ updateDisplay();
340
+ clearHistory();
341
+ </script>
342
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=karaltan/mathcalculator" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
343
+ </html>