@birimengo/calculator 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/index.es.js +564 -0
- package/dist/index.umd.js +12 -0
- package/dist/vite.svg +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# React + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
+
|
|
10
|
+
## Expanding the ESLint configuration
|
|
11
|
+
|
|
12
|
+
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
import le, { useState as j, useCallback as b, memo as U, useEffect as ce } from "react";
|
|
2
|
+
import { Calculator as ie, Clock as ue, Zap as de, PlusCircle as me, MinusCircle as fe, RotateCw as he, Trash2 as pe, Percent as xe, RotateCcw as be, Delete as ye, Divide as ge, X as Ee, Minus as je, Plus as Ne, Equal as ke, Cloud as we, Moon as _e, Sun as Re } from "lucide-react";
|
|
3
|
+
var A = { exports: {} }, S = {};
|
|
4
|
+
var H;
|
|
5
|
+
function ve() {
|
|
6
|
+
if (H) return S;
|
|
7
|
+
H = 1;
|
|
8
|
+
var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), a = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
9
|
+
function c(i, o, n) {
|
|
10
|
+
var h = null;
|
|
11
|
+
if (n !== void 0 && (h = "" + n), o.key !== void 0 && (h = "" + o.key), "key" in o) {
|
|
12
|
+
n = {};
|
|
13
|
+
for (var g in o)
|
|
14
|
+
g !== "key" && (n[g] = o[g]);
|
|
15
|
+
} else n = o;
|
|
16
|
+
return o = n.ref, {
|
|
17
|
+
$$typeof: r,
|
|
18
|
+
type: i,
|
|
19
|
+
key: h,
|
|
20
|
+
ref: o !== void 0 ? o : null,
|
|
21
|
+
props: n
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return S.Fragment = a, S.jsx = c, S.jsxs = c, S;
|
|
25
|
+
}
|
|
26
|
+
var O = {};
|
|
27
|
+
var Q;
|
|
28
|
+
function Ce() {
|
|
29
|
+
return Q || (Q = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
30
|
+
function r(e) {
|
|
31
|
+
if (e == null) return null;
|
|
32
|
+
if (typeof e == "function")
|
|
33
|
+
return e.$$typeof === se ? null : e.displayName || e.name || null;
|
|
34
|
+
if (typeof e == "string") return e;
|
|
35
|
+
switch (e) {
|
|
36
|
+
case C:
|
|
37
|
+
return "Fragment";
|
|
38
|
+
case $:
|
|
39
|
+
return "Profiler";
|
|
40
|
+
case D:
|
|
41
|
+
return "StrictMode";
|
|
42
|
+
case x:
|
|
43
|
+
return "Suspense";
|
|
44
|
+
case T:
|
|
45
|
+
return "SuspenseList";
|
|
46
|
+
case ae:
|
|
47
|
+
return "Activity";
|
|
48
|
+
}
|
|
49
|
+
if (typeof e == "object")
|
|
50
|
+
switch (typeof e.tag == "number" && console.error(
|
|
51
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
52
|
+
), e.$$typeof) {
|
|
53
|
+
case M:
|
|
54
|
+
return "Portal";
|
|
55
|
+
case Y:
|
|
56
|
+
return e.displayName || "Context";
|
|
57
|
+
case F:
|
|
58
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
59
|
+
case l:
|
|
60
|
+
var s = e.render;
|
|
61
|
+
return e = e.displayName, e || (e = s.displayName || s.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
62
|
+
case te:
|
|
63
|
+
return s = e.displayName || null, s !== null ? s : r(e.type) || "Memo";
|
|
64
|
+
case I:
|
|
65
|
+
s = e._payload, e = e._init;
|
|
66
|
+
try {
|
|
67
|
+
return r(e(s));
|
|
68
|
+
} catch {
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function a(e) {
|
|
74
|
+
return "" + e;
|
|
75
|
+
}
|
|
76
|
+
function c(e) {
|
|
77
|
+
try {
|
|
78
|
+
a(e);
|
|
79
|
+
var s = !1;
|
|
80
|
+
} catch {
|
|
81
|
+
s = !0;
|
|
82
|
+
}
|
|
83
|
+
if (s) {
|
|
84
|
+
s = console;
|
|
85
|
+
var u = s.error, m = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
86
|
+
return u.call(
|
|
87
|
+
s,
|
|
88
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
89
|
+
m
|
|
90
|
+
), a(e);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function i(e) {
|
|
94
|
+
if (e === C) return "<>";
|
|
95
|
+
if (typeof e == "object" && e !== null && e.$$typeof === I)
|
|
96
|
+
return "<...>";
|
|
97
|
+
try {
|
|
98
|
+
var s = r(e);
|
|
99
|
+
return s ? "<" + s + ">" : "<...>";
|
|
100
|
+
} catch {
|
|
101
|
+
return "<...>";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function o() {
|
|
105
|
+
var e = z.A;
|
|
106
|
+
return e === null ? null : e.getOwner();
|
|
107
|
+
}
|
|
108
|
+
function n() {
|
|
109
|
+
return Error("react-stack-top-frame");
|
|
110
|
+
}
|
|
111
|
+
function h(e) {
|
|
112
|
+
if (J.call(e, "key")) {
|
|
113
|
+
var s = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
114
|
+
if (s && s.isReactWarning) return !1;
|
|
115
|
+
}
|
|
116
|
+
return e.key !== void 0;
|
|
117
|
+
}
|
|
118
|
+
function g(e, s) {
|
|
119
|
+
function u() {
|
|
120
|
+
V || (V = !0, console.error(
|
|
121
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
122
|
+
s
|
|
123
|
+
));
|
|
124
|
+
}
|
|
125
|
+
u.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
126
|
+
get: u,
|
|
127
|
+
configurable: !0
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function R() {
|
|
131
|
+
var e = r(this.type);
|
|
132
|
+
return B[e] || (B[e] = !0, console.error(
|
|
133
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
134
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
135
|
+
}
|
|
136
|
+
function v(e, s, u, m, P, L) {
|
|
137
|
+
var f = u.ref;
|
|
138
|
+
return e = {
|
|
139
|
+
$$typeof: p,
|
|
140
|
+
type: e,
|
|
141
|
+
key: s,
|
|
142
|
+
props: u,
|
|
143
|
+
_owner: m
|
|
144
|
+
}, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
|
|
145
|
+
enumerable: !1,
|
|
146
|
+
get: R
|
|
147
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
148
|
+
configurable: !1,
|
|
149
|
+
enumerable: !1,
|
|
150
|
+
writable: !0,
|
|
151
|
+
value: 0
|
|
152
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
153
|
+
configurable: !1,
|
|
154
|
+
enumerable: !1,
|
|
155
|
+
writable: !0,
|
|
156
|
+
value: null
|
|
157
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
158
|
+
configurable: !1,
|
|
159
|
+
enumerable: !1,
|
|
160
|
+
writable: !0,
|
|
161
|
+
value: P
|
|
162
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
163
|
+
configurable: !1,
|
|
164
|
+
enumerable: !1,
|
|
165
|
+
writable: !0,
|
|
166
|
+
value: L
|
|
167
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
168
|
+
}
|
|
169
|
+
function N(e, s, u, m, P, L) {
|
|
170
|
+
var f = s.children;
|
|
171
|
+
if (f !== void 0)
|
|
172
|
+
if (m)
|
|
173
|
+
if (ne(f)) {
|
|
174
|
+
for (m = 0; m < f.length; m++)
|
|
175
|
+
k(f[m]);
|
|
176
|
+
Object.freeze && Object.freeze(f);
|
|
177
|
+
} else
|
|
178
|
+
console.error(
|
|
179
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
180
|
+
);
|
|
181
|
+
else k(f);
|
|
182
|
+
if (J.call(s, "key")) {
|
|
183
|
+
f = r(e);
|
|
184
|
+
var _ = Object.keys(s).filter(function(oe) {
|
|
185
|
+
return oe !== "key";
|
|
186
|
+
});
|
|
187
|
+
m = 0 < _.length ? "{key: someKey, " + _.join(": ..., ") + ": ...}" : "{key: someKey}", Z[f + m] || (_ = 0 < _.length ? "{" + _.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
188
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
189
|
+
let props = %s;
|
|
190
|
+
<%s {...props} />
|
|
191
|
+
React keys must be passed directly to JSX without using spread:
|
|
192
|
+
let props = %s;
|
|
193
|
+
<%s key={someKey} {...props} />`,
|
|
194
|
+
m,
|
|
195
|
+
f,
|
|
196
|
+
_,
|
|
197
|
+
f
|
|
198
|
+
), Z[f + m] = !0);
|
|
199
|
+
}
|
|
200
|
+
if (f = null, u !== void 0 && (c(u), f = "" + u), h(s) && (c(s.key), f = "" + s.key), "key" in s) {
|
|
201
|
+
u = {};
|
|
202
|
+
for (var W in s)
|
|
203
|
+
W !== "key" && (u[W] = s[W]);
|
|
204
|
+
} else u = s;
|
|
205
|
+
return f && g(
|
|
206
|
+
u,
|
|
207
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
208
|
+
), v(
|
|
209
|
+
e,
|
|
210
|
+
f,
|
|
211
|
+
u,
|
|
212
|
+
o(),
|
|
213
|
+
P,
|
|
214
|
+
L
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
function k(e) {
|
|
218
|
+
w(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === I && (e._payload.status === "fulfilled" ? w(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
219
|
+
}
|
|
220
|
+
function w(e) {
|
|
221
|
+
return typeof e == "object" && e !== null && e.$$typeof === p;
|
|
222
|
+
}
|
|
223
|
+
var E = le, p = /* @__PURE__ */ Symbol.for("react.transitional.element"), M = /* @__PURE__ */ Symbol.for("react.portal"), C = /* @__PURE__ */ Symbol.for("react.fragment"), D = /* @__PURE__ */ Symbol.for("react.strict_mode"), $ = /* @__PURE__ */ Symbol.for("react.profiler"), F = /* @__PURE__ */ Symbol.for("react.consumer"), Y = /* @__PURE__ */ Symbol.for("react.context"), l = /* @__PURE__ */ Symbol.for("react.forward_ref"), x = /* @__PURE__ */ Symbol.for("react.suspense"), T = /* @__PURE__ */ Symbol.for("react.suspense_list"), te = /* @__PURE__ */ Symbol.for("react.memo"), I = /* @__PURE__ */ Symbol.for("react.lazy"), ae = /* @__PURE__ */ Symbol.for("react.activity"), se = /* @__PURE__ */ Symbol.for("react.client.reference"), z = E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, ne = Array.isArray, q = console.createTask ? console.createTask : function() {
|
|
224
|
+
return null;
|
|
225
|
+
};
|
|
226
|
+
E = {
|
|
227
|
+
react_stack_bottom_frame: function(e) {
|
|
228
|
+
return e();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var V, B = {}, G = E.react_stack_bottom_frame.bind(
|
|
232
|
+
E,
|
|
233
|
+
n
|
|
234
|
+
)(), X = q(i(n)), Z = {};
|
|
235
|
+
O.Fragment = C, O.jsx = function(e, s, u) {
|
|
236
|
+
var m = 1e4 > z.recentlyCreatedOwnerStacks++;
|
|
237
|
+
return N(
|
|
238
|
+
e,
|
|
239
|
+
s,
|
|
240
|
+
u,
|
|
241
|
+
!1,
|
|
242
|
+
m ? Error("react-stack-top-frame") : G,
|
|
243
|
+
m ? q(i(e)) : X
|
|
244
|
+
);
|
|
245
|
+
}, O.jsxs = function(e, s, u) {
|
|
246
|
+
var m = 1e4 > z.recentlyCreatedOwnerStacks++;
|
|
247
|
+
return N(
|
|
248
|
+
e,
|
|
249
|
+
s,
|
|
250
|
+
u,
|
|
251
|
+
!0,
|
|
252
|
+
m ? Error("react-stack-top-frame") : G,
|
|
253
|
+
m ? q(i(e)) : X
|
|
254
|
+
);
|
|
255
|
+
};
|
|
256
|
+
})()), O;
|
|
257
|
+
}
|
|
258
|
+
var K;
|
|
259
|
+
function Te() {
|
|
260
|
+
return K || (K = 1, process.env.NODE_ENV === "production" ? A.exports = ve() : A.exports = Ce()), A.exports;
|
|
261
|
+
}
|
|
262
|
+
var t = Te();
|
|
263
|
+
const y = {
|
|
264
|
+
// Basic operations
|
|
265
|
+
add: (r, a) => r + a,
|
|
266
|
+
subtract: (r, a) => r - a,
|
|
267
|
+
multiply: (r, a) => r * a,
|
|
268
|
+
divide: (r, a) => a !== 0 ? r / a : "Error",
|
|
269
|
+
// Format number for display
|
|
270
|
+
formatNumber: (r) => {
|
|
271
|
+
if (r === "Error") return "Error";
|
|
272
|
+
const a = r.toString();
|
|
273
|
+
return a.length > 12 ? parseFloat(r).toExponential(6) : a;
|
|
274
|
+
},
|
|
275
|
+
// Calculate percentage
|
|
276
|
+
percentage: (r) => r / 100,
|
|
277
|
+
// Toggle sign
|
|
278
|
+
toggleSign: (r) => -r,
|
|
279
|
+
// Check if value is an operator
|
|
280
|
+
isOperator: (r) => ["+", "-", "×", "÷"].includes(r),
|
|
281
|
+
// Get operator precedence
|
|
282
|
+
getPrecedence: (r) => {
|
|
283
|
+
switch (r) {
|
|
284
|
+
case "+":
|
|
285
|
+
case "-":
|
|
286
|
+
return 1;
|
|
287
|
+
case "×":
|
|
288
|
+
case "÷":
|
|
289
|
+
return 2;
|
|
290
|
+
default:
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
// Evaluate expression
|
|
295
|
+
evaluate: (r) => {
|
|
296
|
+
const a = [], c = [];
|
|
297
|
+
for (r.forEach((o) => {
|
|
298
|
+
if (!y.isOperator(o))
|
|
299
|
+
a.push(parseFloat(o));
|
|
300
|
+
else {
|
|
301
|
+
for (; c.length > 0 && y.isOperator(c[c.length - 1]) && y.getPrecedence(c[c.length - 1]) >= y.getPrecedence(o); )
|
|
302
|
+
a.push(c.pop());
|
|
303
|
+
c.push(o);
|
|
304
|
+
}
|
|
305
|
+
}); c.length > 0; )
|
|
306
|
+
a.push(c.pop());
|
|
307
|
+
const i = [];
|
|
308
|
+
return a.forEach((o) => {
|
|
309
|
+
if (!y.isOperator(o))
|
|
310
|
+
i.push(o);
|
|
311
|
+
else {
|
|
312
|
+
const n = i.pop(), h = i.pop();
|
|
313
|
+
switch (o) {
|
|
314
|
+
case "+":
|
|
315
|
+
i.push(h + n);
|
|
316
|
+
break;
|
|
317
|
+
case "-":
|
|
318
|
+
i.push(h - n);
|
|
319
|
+
break;
|
|
320
|
+
case "×":
|
|
321
|
+
i.push(h * n);
|
|
322
|
+
break;
|
|
323
|
+
case "÷":
|
|
324
|
+
i.push(n !== 0 ? h / n : "Error");
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}), i[0];
|
|
329
|
+
}
|
|
330
|
+
}, Se = () => {
|
|
331
|
+
const [r, a] = j("0"), [c, i] = j([]), [o, n] = j(!0), [h, g] = j(0), R = b((l) => {
|
|
332
|
+
a((x) => o || x === "0" || x === "Error" ? (n(!1), l) : x.length < 12 ? x + l : x);
|
|
333
|
+
}, [o]), v = b(() => {
|
|
334
|
+
a((l) => o || l === "0" || l === "Error" ? (n(!1), "0.") : !l.includes(".") && l.length < 12 ? l + "." : l);
|
|
335
|
+
}, [o]), N = b((l) => {
|
|
336
|
+
i((x) => {
|
|
337
|
+
const T = [...x];
|
|
338
|
+
return r !== "Error" && T.push(r), T.push(l), T;
|
|
339
|
+
}), n(!0);
|
|
340
|
+
}, [r]), k = b(() => {
|
|
341
|
+
if (r !== "Error") {
|
|
342
|
+
const l = [...c, r], x = y.evaluate(l);
|
|
343
|
+
a(y.formatNumber(x)), i([]), n(!0);
|
|
344
|
+
}
|
|
345
|
+
}, [r, c]), w = b(() => {
|
|
346
|
+
a("0"), i([]), n(!0);
|
|
347
|
+
}, []), E = b(() => {
|
|
348
|
+
a("0"), n(!0);
|
|
349
|
+
}, []), p = b(() => {
|
|
350
|
+
a((l) => l.length > 1 && l !== "Error" ? l.slice(0, -1) : "0");
|
|
351
|
+
}, []), M = b(() => {
|
|
352
|
+
a((l) => {
|
|
353
|
+
if (l !== "Error") {
|
|
354
|
+
const x = y.percentage(parseFloat(l));
|
|
355
|
+
return y.formatNumber(x);
|
|
356
|
+
}
|
|
357
|
+
return l;
|
|
358
|
+
});
|
|
359
|
+
}, []), C = b(() => {
|
|
360
|
+
a((l) => {
|
|
361
|
+
if (l !== "Error" && l !== "0") {
|
|
362
|
+
const x = y.toggleSign(parseFloat(l));
|
|
363
|
+
return y.formatNumber(x);
|
|
364
|
+
}
|
|
365
|
+
return l;
|
|
366
|
+
});
|
|
367
|
+
}, []), D = b(() => {
|
|
368
|
+
r !== "Error" && (g((l) => l + parseFloat(r)), n(!0));
|
|
369
|
+
}, [r]), $ = b(() => {
|
|
370
|
+
r !== "Error" && (g((l) => l - parseFloat(r)), n(!0));
|
|
371
|
+
}, [r]), F = b(() => {
|
|
372
|
+
a(y.formatNumber(h)), n(!0);
|
|
373
|
+
}, [h]), Y = b(() => {
|
|
374
|
+
g(0);
|
|
375
|
+
}, []);
|
|
376
|
+
return {
|
|
377
|
+
display: r,
|
|
378
|
+
expression: c,
|
|
379
|
+
memory: h,
|
|
380
|
+
handleNumber: R,
|
|
381
|
+
handleDecimal: v,
|
|
382
|
+
handleOperator: N,
|
|
383
|
+
handleEquals: k,
|
|
384
|
+
handleClear: w,
|
|
385
|
+
handleClearEntry: E,
|
|
386
|
+
handleBackspace: p,
|
|
387
|
+
handlePercentage: M,
|
|
388
|
+
handleToggleSign: C,
|
|
389
|
+
handleMemoryAdd: D,
|
|
390
|
+
handleMemorySubtract: $,
|
|
391
|
+
handleMemoryRecall: F,
|
|
392
|
+
handleMemoryClear: Y
|
|
393
|
+
};
|
|
394
|
+
}, ee = U(({
|
|
395
|
+
value: r,
|
|
396
|
+
expression: a,
|
|
397
|
+
memory: c
|
|
398
|
+
}) => {
|
|
399
|
+
const [i, o] = j(/* @__PURE__ */ new Date());
|
|
400
|
+
return ce(() => {
|
|
401
|
+
const n = setInterval(() => o(/* @__PURE__ */ new Date()), 1e3);
|
|
402
|
+
return () => clearInterval(n);
|
|
403
|
+
}, []), /* @__PURE__ */ t.jsxs("div", { className: "bg-card rounded-xl p-6 shadow-inner border border-custom", children: [
|
|
404
|
+
/* @__PURE__ */ t.jsxs("div", { className: "flex justify-between items-center mb-4 text-sm text-secondary", children: [
|
|
405
|
+
/* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
406
|
+
/* @__PURE__ */ t.jsx(ie, { className: "w-4 h-4" }),
|
|
407
|
+
/* @__PURE__ */ t.jsx("span", { children: "Standard" })
|
|
408
|
+
] }),
|
|
409
|
+
/* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-4", children: [
|
|
410
|
+
c !== 0 && /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-1 text-purple-600 dark:text-purple-400", children: [
|
|
411
|
+
/* @__PURE__ */ t.jsx("span", { className: "text-xs", children: "M" }),
|
|
412
|
+
/* @__PURE__ */ t.jsx("span", { children: c })
|
|
413
|
+
] }),
|
|
414
|
+
/* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-1", children: [
|
|
415
|
+
/* @__PURE__ */ t.jsx(ue, { className: "w-3 h-3" }),
|
|
416
|
+
/* @__PURE__ */ t.jsx("span", { children: i.toLocaleTimeString() })
|
|
417
|
+
] })
|
|
418
|
+
] })
|
|
419
|
+
] }),
|
|
420
|
+
a.length > 0 && /* @__PURE__ */ t.jsx("div", { className: "text-right text-sm text-secondary mb-2 font-mono", children: a.join(" ") }),
|
|
421
|
+
/* @__PURE__ */ t.jsx("div", { className: "text-right", children: /* @__PURE__ */ t.jsx("div", { className: "text-5xl font-bold text-primary font-mono truncate", children: r }) }),
|
|
422
|
+
/* @__PURE__ */ t.jsx("div", { className: "flex justify-end mt-2", children: /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-1 text-xs text-secondary opacity-60", children: [
|
|
423
|
+
/* @__PURE__ */ t.jsx(de, { className: "w-3 h-3" }),
|
|
424
|
+
/* @__PURE__ */ t.jsx("span", { className: "font-mono", children: r !== "Error" ? parseInt(r).toString(2).slice(0, 16) : "ERROR" })
|
|
425
|
+
] }) })
|
|
426
|
+
] });
|
|
427
|
+
});
|
|
428
|
+
ee.displayName = "Display";
|
|
429
|
+
const d = U(({
|
|
430
|
+
children: r,
|
|
431
|
+
onClick: a,
|
|
432
|
+
type: c = "number",
|
|
433
|
+
size: i = "normal",
|
|
434
|
+
className: o = ""
|
|
435
|
+
}) => {
|
|
436
|
+
const n = {
|
|
437
|
+
small: "px-3 py-2 text-sm",
|
|
438
|
+
normal: "px-4 py-3 text-base",
|
|
439
|
+
large: "px-6 py-4 text-lg"
|
|
440
|
+
}, h = {
|
|
441
|
+
number: "bg-button-number text-primary",
|
|
442
|
+
operator: "bg-button-operator text-white",
|
|
443
|
+
function: "bg-button-function text-primary",
|
|
444
|
+
equals: "bg-button-equals text-white col-span-2",
|
|
445
|
+
memory: "bg-button-memory text-white text-sm"
|
|
446
|
+
};
|
|
447
|
+
return /* @__PURE__ */ t.jsx(
|
|
448
|
+
"button",
|
|
449
|
+
{
|
|
450
|
+
onClick: a,
|
|
451
|
+
className: `
|
|
452
|
+
${n[i]}
|
|
453
|
+
${h[c]}
|
|
454
|
+
rounded-lg font-semibold transition-all duration-200
|
|
455
|
+
active:scale-95 shadow-sm hover:shadow-md
|
|
456
|
+
${o}
|
|
457
|
+
`,
|
|
458
|
+
children: r
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
});
|
|
462
|
+
d.displayName = "Button";
|
|
463
|
+
const re = U(({
|
|
464
|
+
onNumber: r,
|
|
465
|
+
onDecimal: a,
|
|
466
|
+
onOperator: c,
|
|
467
|
+
onEquals: i,
|
|
468
|
+
onClear: o,
|
|
469
|
+
onClearEntry: n,
|
|
470
|
+
onBackspace: h,
|
|
471
|
+
onPercentage: g,
|
|
472
|
+
onToggleSign: R,
|
|
473
|
+
onMemoryAdd: v,
|
|
474
|
+
onMemorySubtract: N,
|
|
475
|
+
onMemoryRecall: k,
|
|
476
|
+
onMemoryClear: w
|
|
477
|
+
}) => {
|
|
478
|
+
const E = [7, 8, 9, 4, 5, 6, 1, 2, 3, 0];
|
|
479
|
+
return /* @__PURE__ */ t.jsxs("div", { className: "grid grid-cols-5 gap-2", children: [
|
|
480
|
+
/* @__PURE__ */ t.jsx(d, { type: "memory", onClick: v, size: "small", children: /* @__PURE__ */ t.jsx(me, { className: "w-4 h-4" }) }),
|
|
481
|
+
/* @__PURE__ */ t.jsx(d, { type: "memory", onClick: N, size: "small", children: /* @__PURE__ */ t.jsx(fe, { className: "w-4 h-4" }) }),
|
|
482
|
+
/* @__PURE__ */ t.jsx(d, { type: "memory", onClick: k, size: "small", children: /* @__PURE__ */ t.jsx(he, { className: "w-4 h-4" }) }),
|
|
483
|
+
/* @__PURE__ */ t.jsx(d, { type: "memory", onClick: w, size: "small", children: /* @__PURE__ */ t.jsx(pe, { className: "w-4 h-4" }) }),
|
|
484
|
+
/* @__PURE__ */ t.jsx(d, { type: "function", onClick: n, size: "small", children: "CE" }),
|
|
485
|
+
/* @__PURE__ */ t.jsx(d, { type: "function", onClick: R, size: "small", children: "±" }),
|
|
486
|
+
/* @__PURE__ */ t.jsx(d, { type: "function", onClick: g, size: "small", children: /* @__PURE__ */ t.jsx(xe, { className: "w-4 h-4" }) }),
|
|
487
|
+
/* @__PURE__ */ t.jsx(d, { type: "function", onClick: o, size: "small", children: /* @__PURE__ */ t.jsx(be, { className: "w-4 h-4" }) }),
|
|
488
|
+
/* @__PURE__ */ t.jsxs(d, { type: "function", onClick: h, size: "small", children: [
|
|
489
|
+
/* @__PURE__ */ t.jsx(ye, { className: "w-4 h-4" }),
|
|
490
|
+
" "
|
|
491
|
+
] }),
|
|
492
|
+
/* @__PURE__ */ t.jsx(d, { type: "operator", onClick: () => c("÷"), size: "small", children: /* @__PURE__ */ t.jsx(ge, { className: "w-4 h-4" }) }),
|
|
493
|
+
E.slice(0, 3).map((p) => /* @__PURE__ */ t.jsx(d, { onClick: () => r(p.toString()), children: p }, p)),
|
|
494
|
+
/* @__PURE__ */ t.jsx(d, { type: "operator", onClick: () => c("×"), children: /* @__PURE__ */ t.jsx(Ee, { className: "w-4 h-4" }) }),
|
|
495
|
+
E.slice(3, 6).map((p) => /* @__PURE__ */ t.jsx(d, { onClick: () => r(p.toString()), children: p }, p)),
|
|
496
|
+
/* @__PURE__ */ t.jsx(d, { type: "operator", onClick: () => c("-"), children: /* @__PURE__ */ t.jsx(je, { className: "w-4 h-4" }) }),
|
|
497
|
+
E.slice(6, 9).map((p) => /* @__PURE__ */ t.jsx(d, { onClick: () => r(p.toString()), children: p }, p)),
|
|
498
|
+
/* @__PURE__ */ t.jsx(d, { type: "operator", onClick: () => c("+"), children: /* @__PURE__ */ t.jsx(Ne, { className: "w-4 h-4" }) }),
|
|
499
|
+
/* @__PURE__ */ t.jsx(d, { type: "number", onClick: a, className: "col-span-2", children: "." }),
|
|
500
|
+
/* @__PURE__ */ t.jsx(d, { type: "number", onClick: () => r("0"), className: "col-span-2", children: "0" }),
|
|
501
|
+
/* @__PURE__ */ t.jsx(d, { type: "equals", onClick: i, className: "col-span-1", children: /* @__PURE__ */ t.jsx(ke, { className: "w-5 h-5" }) })
|
|
502
|
+
] });
|
|
503
|
+
});
|
|
504
|
+
re.displayName = "Keypad";
|
|
505
|
+
const Ae = () => {
|
|
506
|
+
const r = Se(), [a, c] = j("light"), i = () => {
|
|
507
|
+
c((n) => n === "light" ? "dark" : n === "dark" ? "ocean" : "light"), document.body.className = `theme-${a === "light" ? "dark" : a === "dark" ? "ocean" : "light"}`;
|
|
508
|
+
};
|
|
509
|
+
j(() => {
|
|
510
|
+
document.body.className = "theme-light";
|
|
511
|
+
}, []);
|
|
512
|
+
const o = {
|
|
513
|
+
light: /* @__PURE__ */ t.jsx(Re, { className: "w-5 h-5 text-yellow-500" }),
|
|
514
|
+
dark: /* @__PURE__ */ t.jsx(_e, { className: "w-5 h-5 text-blue-400" }),
|
|
515
|
+
ocean: /* @__PURE__ */ t.jsx(we, { className: "w-5 h-5 text-cyan-400" })
|
|
516
|
+
};
|
|
517
|
+
return /* @__PURE__ */ t.jsx("div", { className: "min-h-screen bg-[var(--bg-primary)] flex items-center justify-center p-4 transition-colors duration-300", children: /* @__PURE__ */ t.jsxs("div", { className: "max-w-md w-full bg-card rounded-2xl shadow-2xl p-6 border border-custom", children: [
|
|
518
|
+
/* @__PURE__ */ t.jsxs("div", { className: "flex justify-between items-center mb-4", children: [
|
|
519
|
+
/* @__PURE__ */ t.jsx("h1", { className: "text-2xl font-bold text-primary", children: "Calculator" }),
|
|
520
|
+
/* @__PURE__ */ t.jsx(
|
|
521
|
+
"button",
|
|
522
|
+
{
|
|
523
|
+
onClick: i,
|
|
524
|
+
className: "p-2 rounded-lg bg-card border border-custom hover:opacity-80 transition-opacity",
|
|
525
|
+
children: o[a]
|
|
526
|
+
}
|
|
527
|
+
)
|
|
528
|
+
] }),
|
|
529
|
+
/* @__PURE__ */ t.jsx(
|
|
530
|
+
ee,
|
|
531
|
+
{
|
|
532
|
+
value: r.display,
|
|
533
|
+
expression: r.expression,
|
|
534
|
+
memory: r.memory
|
|
535
|
+
}
|
|
536
|
+
),
|
|
537
|
+
/* @__PURE__ */ t.jsx("div", { className: "mt-6", children: /* @__PURE__ */ t.jsx(
|
|
538
|
+
re,
|
|
539
|
+
{
|
|
540
|
+
onNumber: r.handleNumber,
|
|
541
|
+
onDecimal: r.handleDecimal,
|
|
542
|
+
onOperator: r.handleOperator,
|
|
543
|
+
onEquals: r.handleEquals,
|
|
544
|
+
onClear: r.handleClear,
|
|
545
|
+
onClearEntry: r.handleClearEntry,
|
|
546
|
+
onBackspace: r.handleBackspace,
|
|
547
|
+
onPercentage: r.handlePercentage,
|
|
548
|
+
onToggleSign: r.handleToggleSign,
|
|
549
|
+
onMemoryAdd: r.handleMemoryAdd,
|
|
550
|
+
onMemorySubtract: r.handleMemorySubtract,
|
|
551
|
+
onMemoryRecall: r.handleMemoryRecall,
|
|
552
|
+
onMemoryClear: r.handleMemoryClear
|
|
553
|
+
}
|
|
554
|
+
) }),
|
|
555
|
+
/* @__PURE__ */ t.jsx("div", { className: "mt-4 text-xs text-center text-secondary", children: /* @__PURE__ */ t.jsxs("p", { children: [
|
|
556
|
+
"Standalone Calculator App | Memory: ",
|
|
557
|
+
r.memory
|
|
558
|
+
] }) })
|
|
559
|
+
] }) });
|
|
560
|
+
};
|
|
561
|
+
export {
|
|
562
|
+
Ae as Calculator,
|
|
563
|
+
Se as useCalculator
|
|
564
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function(k,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react","lucide-react"],i):(k=typeof globalThis<"u"?globalThis:k||self,i(k.CalculatorModule={},k.React,k.LucideReact))})(this,(function(k,i,p){"use strict";var A={exports:{}},v={};var B;function ae(){if(B)return v;B=1;var r=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function c(u,l,n){var x=null;if(n!==void 0&&(x=""+n),l.key!==void 0&&(x=""+l.key),"key"in l){n={};for(var g in l)g!=="key"&&(n[g]=l[g])}else n=l;return l=n.ref,{$$typeof:r,type:u,key:x,ref:l!==void 0?l:null,props:n}}return v.Fragment=a,v.jsx=c,v.jsxs=c,v}var T={};var G;function se(){return G||(G=1,process.env.NODE_ENV!=="production"&&(function(){function r(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ie?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case O:return"Fragment";case Y:return"Profiler";case F:return"StrictMode";case y:return"Suspense";case P:return"SuspenseList";case ce:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case D:return"Portal";case z:return e.displayName||"Context";case I:return(e._context.displayName||"Context")+".Consumer";case o:var s=e.render;return e=e.displayName,e||(e=s.displayName||s.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case oe:return s=e.displayName||null,s!==null?s:r(e.type)||"Memo";case L:s=e._payload,e=e._init;try{return r(e(s))}catch{}}return null}function a(e){return""+e}function c(e){try{a(e);var s=!1}catch{s=!0}if(s){s=console;var m=s.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return m.call(s,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),a(e)}}function u(e){if(e===O)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===L)return"<...>";try{var s=r(e);return s?"<"+s+">":"<...>"}catch{return"<...>"}}function l(){var e=W.A;return e===null?null:e.getOwner()}function n(){return Error("react-stack-top-frame")}function x(e){if(K.call(e,"key")){var s=Object.getOwnPropertyDescriptor(e,"key").get;if(s&&s.isReactWarning)return!1}return e.key!==void 0}function g(e,s){function m(){q||(q=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",s))}m.isReactWarning=!0,Object.defineProperty(e,"key",{get:m,configurable:!0})}function S(){var e=r(this.type);return $[e]||($[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function R(e,s,m,f,M,J){var h=m.ref;return e={$$typeof:b,type:e,key:s,props:m,_owner:f},(h!==void 0?h:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:S}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:M}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function N(e,s,m,f,M,J){var h=s.children;if(h!==void 0)if(f)if(ue(h)){for(f=0;f<h.length;f++)C(h[f]);Object.freeze&&Object.freeze(h)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else C(h);if(K.call(s,"key")){h=r(e);var _=Object.keys(s).filter(function(me){return me!=="key"});f=0<_.length?"{key: someKey, "+_.join(": ..., ")+": ...}":"{key: someKey}",te[h+f]||(_=0<_.length?"{"+_.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,f,h,_,h),te[h+f]=!0)}if(h=null,m!==void 0&&(c(m),h=""+m),x(s)&&(c(s.key),h=""+s.key),"key"in s){m={};for(var V in s)V!=="key"&&(m[V]=s[V])}else m=s;return h&&g(m,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,h,m,l(),M,J)}function C(e){w(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===L&&(e._payload.status==="fulfilled"?w(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function w(e){return typeof e=="object"&&e!==null&&e.$$typeof===b}var E=i,b=Symbol.for("react.transitional.element"),D=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),F=Symbol.for("react.strict_mode"),Y=Symbol.for("react.profiler"),I=Symbol.for("react.consumer"),z=Symbol.for("react.context"),o=Symbol.for("react.forward_ref"),y=Symbol.for("react.suspense"),P=Symbol.for("react.suspense_list"),oe=Symbol.for("react.memo"),L=Symbol.for("react.lazy"),ce=Symbol.for("react.activity"),ie=Symbol.for("react.client.reference"),W=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,K=Object.prototype.hasOwnProperty,ue=Array.isArray,U=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(e){return e()}};var q,$={},ee=E.react_stack_bottom_frame.bind(E,n)(),re=U(u(n)),te={};T.Fragment=O,T.jsx=function(e,s,m){var f=1e4>W.recentlyCreatedOwnerStacks++;return N(e,s,m,!1,f?Error("react-stack-top-frame"):ee,f?U(u(e)):re)},T.jsxs=function(e,s,m){var f=1e4>W.recentlyCreatedOwnerStacks++;return N(e,s,m,!0,f?Error("react-stack-top-frame"):ee,f?U(u(e)):re)}})()),T}var X;function ne(){return X||(X=1,process.env.NODE_ENV==="production"?A.exports=ae():A.exports=se()),A.exports}var t=ne();const j={add:(r,a)=>r+a,subtract:(r,a)=>r-a,multiply:(r,a)=>r*a,divide:(r,a)=>a!==0?r/a:"Error",formatNumber:r=>{if(r==="Error")return"Error";const a=r.toString();return a.length>12?parseFloat(r).toExponential(6):a},percentage:r=>r/100,toggleSign:r=>-r,isOperator:r=>["+","-","×","÷"].includes(r),getPrecedence:r=>{switch(r){case"+":case"-":return 1;case"×":case"÷":return 2;default:return 0}},evaluate:r=>{const a=[],c=[];for(r.forEach(l=>{if(!j.isOperator(l))a.push(parseFloat(l));else{for(;c.length>0&&j.isOperator(c[c.length-1])&&j.getPrecedence(c[c.length-1])>=j.getPrecedence(l);)a.push(c.pop());c.push(l)}});c.length>0;)a.push(c.pop());const u=[];return a.forEach(l=>{if(!j.isOperator(l))u.push(l);else{const n=u.pop(),x=u.pop();switch(l){case"+":u.push(x+n);break;case"-":u.push(x-n);break;case"×":u.push(x*n);break;case"÷":u.push(n!==0?x/n:"Error");break}}}),u[0]}},Z=()=>{const[r,a]=i.useState("0"),[c,u]=i.useState([]),[l,n]=i.useState(!0),[x,g]=i.useState(0),S=i.useCallback(o=>{a(y=>l||y==="0"||y==="Error"?(n(!1),o):y.length<12?y+o:y)},[l]),R=i.useCallback(()=>{a(o=>l||o==="0"||o==="Error"?(n(!1),"0."):!o.includes(".")&&o.length<12?o+".":o)},[l]),N=i.useCallback(o=>{u(y=>{const P=[...y];return r!=="Error"&&P.push(r),P.push(o),P}),n(!0)},[r]),C=i.useCallback(()=>{if(r!=="Error"){const o=[...c,r],y=j.evaluate(o);a(j.formatNumber(y)),u([]),n(!0)}},[r,c]),w=i.useCallback(()=>{a("0"),u([]),n(!0)},[]),E=i.useCallback(()=>{a("0"),n(!0)},[]),b=i.useCallback(()=>{a(o=>o.length>1&&o!=="Error"?o.slice(0,-1):"0")},[]),D=i.useCallback(()=>{a(o=>{if(o!=="Error"){const y=j.percentage(parseFloat(o));return j.formatNumber(y)}return o})},[]),O=i.useCallback(()=>{a(o=>{if(o!=="Error"&&o!=="0"){const y=j.toggleSign(parseFloat(o));return j.formatNumber(y)}return o})},[]),F=i.useCallback(()=>{r!=="Error"&&(g(o=>o+parseFloat(r)),n(!0))},[r]),Y=i.useCallback(()=>{r!=="Error"&&(g(o=>o-parseFloat(r)),n(!0))},[r]),I=i.useCallback(()=>{a(j.formatNumber(x)),n(!0)},[x]),z=i.useCallback(()=>{g(0)},[]);return{display:r,expression:c,memory:x,handleNumber:S,handleDecimal:R,handleOperator:N,handleEquals:C,handleClear:w,handleClearEntry:E,handleBackspace:b,handlePercentage:D,handleToggleSign:O,handleMemoryAdd:F,handleMemorySubtract:Y,handleMemoryRecall:I,handleMemoryClear:z}},H=i.memo(({value:r,expression:a,memory:c})=>{const[u,l]=i.useState(new Date);return i.useEffect(()=>{const n=setInterval(()=>l(new Date),1e3);return()=>clearInterval(n)},[]),t.jsxs("div",{className:"bg-card rounded-xl p-6 shadow-inner border border-custom",children:[t.jsxs("div",{className:"flex justify-between items-center mb-4 text-sm text-secondary",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(p.Calculator,{className:"w-4 h-4"}),t.jsx("span",{children:"Standard"})]}),t.jsxs("div",{className:"flex items-center gap-4",children:[c!==0&&t.jsxs("div",{className:"flex items-center gap-1 text-purple-600 dark:text-purple-400",children:[t.jsx("span",{className:"text-xs",children:"M"}),t.jsx("span",{children:c})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(p.Clock,{className:"w-3 h-3"}),t.jsx("span",{children:u.toLocaleTimeString()})]})]})]}),a.length>0&&t.jsx("div",{className:"text-right text-sm text-secondary mb-2 font-mono",children:a.join(" ")}),t.jsx("div",{className:"text-right",children:t.jsx("div",{className:"text-5xl font-bold text-primary font-mono truncate",children:r})}),t.jsx("div",{className:"flex justify-end mt-2",children:t.jsxs("div",{className:"flex items-center gap-1 text-xs text-secondary opacity-60",children:[t.jsx(p.Zap,{className:"w-3 h-3"}),t.jsx("span",{className:"font-mono",children:r!=="Error"?parseInt(r).toString(2).slice(0,16):"ERROR"})]})})]})});H.displayName="Display";const d=i.memo(({children:r,onClick:a,type:c="number",size:u="normal",className:l=""})=>{const n={small:"px-3 py-2 text-sm",normal:"px-4 py-3 text-base",large:"px-6 py-4 text-lg"},x={number:"bg-button-number text-primary",operator:"bg-button-operator text-white",function:"bg-button-function text-primary",equals:"bg-button-equals text-white col-span-2",memory:"bg-button-memory text-white text-sm"};return t.jsx("button",{onClick:a,className:`
|
|
7
|
+
${n[u]}
|
|
8
|
+
${x[c]}
|
|
9
|
+
rounded-lg font-semibold transition-all duration-200
|
|
10
|
+
active:scale-95 shadow-sm hover:shadow-md
|
|
11
|
+
${l}
|
|
12
|
+
`,children:r})});d.displayName="Button";const Q=i.memo(({onNumber:r,onDecimal:a,onOperator:c,onEquals:u,onClear:l,onClearEntry:n,onBackspace:x,onPercentage:g,onToggleSign:S,onMemoryAdd:R,onMemorySubtract:N,onMemoryRecall:C,onMemoryClear:w})=>{const E=[7,8,9,4,5,6,1,2,3,0];return t.jsxs("div",{className:"grid grid-cols-5 gap-2",children:[t.jsx(d,{type:"memory",onClick:R,size:"small",children:t.jsx(p.PlusCircle,{className:"w-4 h-4"})}),t.jsx(d,{type:"memory",onClick:N,size:"small",children:t.jsx(p.MinusCircle,{className:"w-4 h-4"})}),t.jsx(d,{type:"memory",onClick:C,size:"small",children:t.jsx(p.RotateCw,{className:"w-4 h-4"})}),t.jsx(d,{type:"memory",onClick:w,size:"small",children:t.jsx(p.Trash2,{className:"w-4 h-4"})}),t.jsx(d,{type:"function",onClick:n,size:"small",children:"CE"}),t.jsx(d,{type:"function",onClick:S,size:"small",children:"±"}),t.jsx(d,{type:"function",onClick:g,size:"small",children:t.jsx(p.Percent,{className:"w-4 h-4"})}),t.jsx(d,{type:"function",onClick:l,size:"small",children:t.jsx(p.RotateCcw,{className:"w-4 h-4"})}),t.jsxs(d,{type:"function",onClick:x,size:"small",children:[t.jsx(p.Delete,{className:"w-4 h-4"})," "]}),t.jsx(d,{type:"operator",onClick:()=>c("÷"),size:"small",children:t.jsx(p.Divide,{className:"w-4 h-4"})}),E.slice(0,3).map(b=>t.jsx(d,{onClick:()=>r(b.toString()),children:b},b)),t.jsx(d,{type:"operator",onClick:()=>c("×"),children:t.jsx(p.X,{className:"w-4 h-4"})}),E.slice(3,6).map(b=>t.jsx(d,{onClick:()=>r(b.toString()),children:b},b)),t.jsx(d,{type:"operator",onClick:()=>c("-"),children:t.jsx(p.Minus,{className:"w-4 h-4"})}),E.slice(6,9).map(b=>t.jsx(d,{onClick:()=>r(b.toString()),children:b},b)),t.jsx(d,{type:"operator",onClick:()=>c("+"),children:t.jsx(p.Plus,{className:"w-4 h-4"})}),t.jsx(d,{type:"number",onClick:a,className:"col-span-2",children:"."}),t.jsx(d,{type:"number",onClick:()=>r("0"),className:"col-span-2",children:"0"}),t.jsx(d,{type:"equals",onClick:u,className:"col-span-1",children:t.jsx(p.Equal,{className:"w-5 h-5"})})]})});Q.displayName="Keypad";const le=()=>{const r=Z(),[a,c]=i.useState("light"),u=()=>{c(n=>n==="light"?"dark":n==="dark"?"ocean":"light"),document.body.className=`theme-${a==="light"?"dark":a==="dark"?"ocean":"light"}`};i.useState(()=>{document.body.className="theme-light"},[]);const l={light:t.jsx(p.Sun,{className:"w-5 h-5 text-yellow-500"}),dark:t.jsx(p.Moon,{className:"w-5 h-5 text-blue-400"}),ocean:t.jsx(p.Cloud,{className:"w-5 h-5 text-cyan-400"})};return t.jsx("div",{className:"min-h-screen bg-[var(--bg-primary)] flex items-center justify-center p-4 transition-colors duration-300",children:t.jsxs("div",{className:"max-w-md w-full bg-card rounded-2xl shadow-2xl p-6 border border-custom",children:[t.jsxs("div",{className:"flex justify-between items-center mb-4",children:[t.jsx("h1",{className:"text-2xl font-bold text-primary",children:"Calculator"}),t.jsx("button",{onClick:u,className:"p-2 rounded-lg bg-card border border-custom hover:opacity-80 transition-opacity",children:l[a]})]}),t.jsx(H,{value:r.display,expression:r.expression,memory:r.memory}),t.jsx("div",{className:"mt-6",children:t.jsx(Q,{onNumber:r.handleNumber,onDecimal:r.handleDecimal,onOperator:r.handleOperator,onEquals:r.handleEquals,onClear:r.handleClear,onClearEntry:r.handleClearEntry,onBackspace:r.handleBackspace,onPercentage:r.handlePercentage,onToggleSign:r.handleToggleSign,onMemoryAdd:r.handleMemoryAdd,onMemorySubtract:r.handleMemorySubtract,onMemoryRecall:r.handleMemoryRecall,onMemoryClear:r.handleMemoryClear})}),t.jsx("div",{className:"mt-4 text-xs text-center text-secondary",children:t.jsxs("p",{children:["Standalone Calculator App | Memory: ",r.memory]})})]})})};k.Calculator=le,k.useCalculator=Z,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@birimengo/calculator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A beautiful calculator component with memory functions and multiple themes",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"unpkg": "dist/index.umd.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "vite",
|
|
16
|
+
"build": "vite build -c vite.lib.config.js",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"preview": "vite preview"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"react",
|
|
22
|
+
"calculator",
|
|
23
|
+
"component",
|
|
24
|
+
"ui",
|
|
25
|
+
"math",
|
|
26
|
+
"memory-calculator",
|
|
27
|
+
"bizcore"
|
|
28
|
+
],
|
|
29
|
+
"author": "Your Name <your.email@example.com>",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/birimengo/calculator.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/birimengo/calculator/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/birimengo/calculator#readme",
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": ">=18.0.0",
|
|
41
|
+
"react-dom": ">=18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"lucide-react": "^0.577.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@eslint/js": "^9.29.0",
|
|
48
|
+
"@tailwindcss/vite": "^4.2.1",
|
|
49
|
+
"@types/react": "^19.1.8",
|
|
50
|
+
"@types/react-dom": "^19.1.6",
|
|
51
|
+
"@vitejs/plugin-react-swc": "^3.11.0",
|
|
52
|
+
"autoprefixer": "^10.4.21",
|
|
53
|
+
"eslint": "^9.29.0",
|
|
54
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
55
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
56
|
+
"globals": "^16.2.0",
|
|
57
|
+
"postcss": "^8.5.3",
|
|
58
|
+
"react": "^19.1.0",
|
|
59
|
+
"react-dom": "^19.1.0",
|
|
60
|
+
"tailwindcss": "^4.2.1",
|
|
61
|
+
"vite": "^7.0.0"
|
|
62
|
+
}
|
|
63
|
+
}
|