@birimengo/calculator 1.0.1 → 1.0.2
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/dist/index.es.js +173 -191
- package/dist/index.umd.js +5 -5
- package/package.json +3 -2
package/dist/index.es.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import le, { useState as
|
|
2
|
-
import { Calculator as ie, Clock as ue, Zap as
|
|
3
|
-
var A = { exports: {} },
|
|
1
|
+
import le, { useState as O, useCallback as b, memo as U, useEffect as ce } from "react";
|
|
2
|
+
import { Calculator as ie, Clock as ue, Zap as me, PlusCircle as de, MinusCircle as fe, RotateCw as pe, Trash2 as he, Percent as xe, RotateCcw as be, Delete as Ee, Divide as ye, X as je, Minus as ge, Plus as Ne, Equal as _e } from "lucide-react";
|
|
3
|
+
var A = { exports: {} }, T = {};
|
|
4
4
|
var H;
|
|
5
|
-
function
|
|
6
|
-
if (H) return
|
|
5
|
+
function Re() {
|
|
6
|
+
if (H) return T;
|
|
7
7
|
H = 1;
|
|
8
8
|
var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), a = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
9
|
-
function c(i,
|
|
10
|
-
var
|
|
11
|
-
if (n !== void 0 && (
|
|
9
|
+
function c(i, l, n) {
|
|
10
|
+
var p = null;
|
|
11
|
+
if (n !== void 0 && (p = "" + n), l.key !== void 0 && (p = "" + l.key), "key" in l) {
|
|
12
12
|
n = {};
|
|
13
|
-
for (var
|
|
14
|
-
|
|
15
|
-
} else n =
|
|
16
|
-
return
|
|
13
|
+
for (var y in l)
|
|
14
|
+
y !== "key" && (n[y] = l[y]);
|
|
15
|
+
} else n = l;
|
|
16
|
+
return l = n.ref, {
|
|
17
17
|
$$typeof: r,
|
|
18
18
|
type: i,
|
|
19
|
-
key:
|
|
20
|
-
ref:
|
|
19
|
+
key: p,
|
|
20
|
+
ref: l !== void 0 ? l : null,
|
|
21
21
|
props: n
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return T.Fragment = a, T.jsx = c, T.jsxs = c, T;
|
|
25
25
|
}
|
|
26
|
-
var
|
|
26
|
+
var S = {};
|
|
27
27
|
var Q;
|
|
28
|
-
function
|
|
28
|
+
function ke() {
|
|
29
29
|
return Q || (Q = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
30
30
|
function r(e) {
|
|
31
31
|
if (e == null) return null;
|
|
@@ -33,7 +33,7 @@ function Ce() {
|
|
|
33
33
|
return e.$$typeof === se ? null : e.displayName || e.name || null;
|
|
34
34
|
if (typeof e == "string") return e;
|
|
35
35
|
switch (e) {
|
|
36
|
-
case
|
|
36
|
+
case v:
|
|
37
37
|
return "Fragment";
|
|
38
38
|
case $:
|
|
39
39
|
return "Profiler";
|
|
@@ -41,7 +41,7 @@ function Ce() {
|
|
|
41
41
|
return "StrictMode";
|
|
42
42
|
case x:
|
|
43
43
|
return "Suspense";
|
|
44
|
-
case
|
|
44
|
+
case C:
|
|
45
45
|
return "SuspenseList";
|
|
46
46
|
case ae:
|
|
47
47
|
return "Activity";
|
|
@@ -56,12 +56,12 @@ function Ce() {
|
|
|
56
56
|
return e.displayName || "Context";
|
|
57
57
|
case F:
|
|
58
58
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
59
|
-
case
|
|
59
|
+
case o:
|
|
60
60
|
var s = e.render;
|
|
61
61
|
return e = e.displayName, e || (e = s.displayName || s.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
62
62
|
case te:
|
|
63
63
|
return s = e.displayName || null, s !== null ? s : r(e.type) || "Memo";
|
|
64
|
-
case
|
|
64
|
+
case z:
|
|
65
65
|
s = e._payload, e = e._init;
|
|
66
66
|
try {
|
|
67
67
|
return r(e(s));
|
|
@@ -82,17 +82,17 @@ function Ce() {
|
|
|
82
82
|
}
|
|
83
83
|
if (s) {
|
|
84
84
|
s = console;
|
|
85
|
-
var u = s.error,
|
|
85
|
+
var u = s.error, d = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
86
86
|
return u.call(
|
|
87
87
|
s,
|
|
88
88
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
89
|
-
|
|
89
|
+
d
|
|
90
90
|
), a(e);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
function i(e) {
|
|
94
|
-
if (e ===
|
|
95
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
94
|
+
if (e === v) return "<>";
|
|
95
|
+
if (typeof e == "object" && e !== null && e.$$typeof === z)
|
|
96
96
|
return "<...>";
|
|
97
97
|
try {
|
|
98
98
|
var s = r(e);
|
|
@@ -101,21 +101,21 @@ function Ce() {
|
|
|
101
101
|
return "<...>";
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
var e =
|
|
104
|
+
function l() {
|
|
105
|
+
var e = I.A;
|
|
106
106
|
return e === null ? null : e.getOwner();
|
|
107
107
|
}
|
|
108
108
|
function n() {
|
|
109
109
|
return Error("react-stack-top-frame");
|
|
110
110
|
}
|
|
111
|
-
function
|
|
111
|
+
function p(e) {
|
|
112
112
|
if (J.call(e, "key")) {
|
|
113
113
|
var s = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
114
114
|
if (s && s.isReactWarning) return !1;
|
|
115
115
|
}
|
|
116
116
|
return e.key !== void 0;
|
|
117
117
|
}
|
|
118
|
-
function
|
|
118
|
+
function y(e, s) {
|
|
119
119
|
function u() {
|
|
120
120
|
V || (V = !0, console.error(
|
|
121
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)",
|
|
@@ -127,23 +127,23 @@ function Ce() {
|
|
|
127
127
|
configurable: !0
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function k() {
|
|
131
131
|
var e = r(this.type);
|
|
132
132
|
return B[e] || (B[e] = !0, console.error(
|
|
133
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
134
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
135
135
|
}
|
|
136
|
-
function
|
|
136
|
+
function w(e, s, u, d, P, L) {
|
|
137
137
|
var f = u.ref;
|
|
138
138
|
return e = {
|
|
139
|
-
$$typeof:
|
|
139
|
+
$$typeof: h,
|
|
140
140
|
type: e,
|
|
141
141
|
key: s,
|
|
142
142
|
props: u,
|
|
143
|
-
_owner:
|
|
143
|
+
_owner: d
|
|
144
144
|
}, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
|
|
145
145
|
enumerable: !1,
|
|
146
|
-
get:
|
|
146
|
+
get: k
|
|
147
147
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
148
148
|
configurable: !1,
|
|
149
149
|
enumerable: !1,
|
|
@@ -166,101 +166,101 @@ function Ce() {
|
|
|
166
166
|
value: L
|
|
167
167
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function g(e, s, u, d, P, L) {
|
|
170
170
|
var f = s.children;
|
|
171
171
|
if (f !== void 0)
|
|
172
|
-
if (
|
|
172
|
+
if (d)
|
|
173
173
|
if (ne(f)) {
|
|
174
|
-
for (
|
|
175
|
-
|
|
174
|
+
for (d = 0; d < f.length; d++)
|
|
175
|
+
N(f[d]);
|
|
176
176
|
Object.freeze && Object.freeze(f);
|
|
177
177
|
} else
|
|
178
178
|
console.error(
|
|
179
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
180
|
);
|
|
181
|
-
else
|
|
181
|
+
else N(f);
|
|
182
182
|
if (J.call(s, "key")) {
|
|
183
183
|
f = r(e);
|
|
184
|
-
var
|
|
184
|
+
var R = Object.keys(s).filter(function(oe) {
|
|
185
185
|
return oe !== "key";
|
|
186
186
|
});
|
|
187
|
-
|
|
187
|
+
d = 0 < R.length ? "{key: someKey, " + R.join(": ..., ") + ": ...}" : "{key: someKey}", Z[f + d] || (R = 0 < R.length ? "{" + R.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
188
188
|
`A props object containing a "key" prop is being spread into JSX:
|
|
189
189
|
let props = %s;
|
|
190
190
|
<%s {...props} />
|
|
191
191
|
React keys must be passed directly to JSX without using spread:
|
|
192
192
|
let props = %s;
|
|
193
193
|
<%s key={someKey} {...props} />`,
|
|
194
|
-
|
|
194
|
+
d,
|
|
195
195
|
f,
|
|
196
|
-
|
|
196
|
+
R,
|
|
197
197
|
f
|
|
198
|
-
), Z[f +
|
|
198
|
+
), Z[f + d] = !0);
|
|
199
199
|
}
|
|
200
|
-
if (f = null, u !== void 0 && (c(u), f = "" + u),
|
|
200
|
+
if (f = null, u !== void 0 && (c(u), f = "" + u), p(s) && (c(s.key), f = "" + s.key), "key" in s) {
|
|
201
201
|
u = {};
|
|
202
202
|
for (var W in s)
|
|
203
203
|
W !== "key" && (u[W] = s[W]);
|
|
204
204
|
} else u = s;
|
|
205
|
-
return f &&
|
|
205
|
+
return f && y(
|
|
206
206
|
u,
|
|
207
207
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
208
|
-
),
|
|
208
|
+
), w(
|
|
209
209
|
e,
|
|
210
210
|
f,
|
|
211
211
|
u,
|
|
212
|
-
|
|
212
|
+
l(),
|
|
213
213
|
P,
|
|
214
214
|
L
|
|
215
215
|
);
|
|
216
216
|
}
|
|
217
|
-
function
|
|
218
|
-
|
|
217
|
+
function N(e) {
|
|
218
|
+
_(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === z && (e._payload.status === "fulfilled" ? _(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
219
219
|
}
|
|
220
|
-
function
|
|
221
|
-
return typeof e == "object" && e !== null && e.$$typeof ===
|
|
220
|
+
function _(e) {
|
|
221
|
+
return typeof e == "object" && e !== null && e.$$typeof === h;
|
|
222
222
|
}
|
|
223
|
-
var
|
|
223
|
+
var j = le, h = /* @__PURE__ */ Symbol.for("react.transitional.element"), M = /* @__PURE__ */ Symbol.for("react.portal"), v = /* @__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"), o = /* @__PURE__ */ Symbol.for("react.forward_ref"), x = /* @__PURE__ */ Symbol.for("react.suspense"), C = /* @__PURE__ */ Symbol.for("react.suspense_list"), te = /* @__PURE__ */ Symbol.for("react.memo"), z = /* @__PURE__ */ Symbol.for("react.lazy"), ae = /* @__PURE__ */ Symbol.for("react.activity"), se = /* @__PURE__ */ Symbol.for("react.client.reference"), I = j.__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
224
|
return null;
|
|
225
225
|
};
|
|
226
|
-
|
|
226
|
+
j = {
|
|
227
227
|
react_stack_bottom_frame: function(e) {
|
|
228
228
|
return e();
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
|
-
var V, B = {}, G =
|
|
232
|
-
|
|
231
|
+
var V, B = {}, G = j.react_stack_bottom_frame.bind(
|
|
232
|
+
j,
|
|
233
233
|
n
|
|
234
234
|
)(), X = q(i(n)), Z = {};
|
|
235
|
-
|
|
236
|
-
var
|
|
237
|
-
return
|
|
235
|
+
S.Fragment = v, S.jsx = function(e, s, u) {
|
|
236
|
+
var d = 1e4 > I.recentlyCreatedOwnerStacks++;
|
|
237
|
+
return g(
|
|
238
238
|
e,
|
|
239
239
|
s,
|
|
240
240
|
u,
|
|
241
241
|
!1,
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
d ? Error("react-stack-top-frame") : G,
|
|
243
|
+
d ? q(i(e)) : X
|
|
244
244
|
);
|
|
245
|
-
},
|
|
246
|
-
var
|
|
247
|
-
return
|
|
245
|
+
}, S.jsxs = function(e, s, u) {
|
|
246
|
+
var d = 1e4 > I.recentlyCreatedOwnerStacks++;
|
|
247
|
+
return g(
|
|
248
248
|
e,
|
|
249
249
|
s,
|
|
250
250
|
u,
|
|
251
251
|
!0,
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
d ? Error("react-stack-top-frame") : G,
|
|
253
|
+
d ? q(i(e)) : X
|
|
254
254
|
);
|
|
255
255
|
};
|
|
256
|
-
})()),
|
|
256
|
+
})()), S;
|
|
257
257
|
}
|
|
258
258
|
var K;
|
|
259
|
-
function
|
|
260
|
-
return K || (K = 1, process.env.NODE_ENV === "production" ? A.exports =
|
|
259
|
+
function we() {
|
|
260
|
+
return K || (K = 1, process.env.NODE_ENV === "production" ? A.exports = Re() : A.exports = ke()), A.exports;
|
|
261
261
|
}
|
|
262
|
-
var t =
|
|
263
|
-
const
|
|
262
|
+
var t = we();
|
|
263
|
+
const E = {
|
|
264
264
|
// Basic operations
|
|
265
265
|
add: (r, a) => r + a,
|
|
266
266
|
subtract: (r, a) => r - a,
|
|
@@ -294,98 +294,98 @@ const y = {
|
|
|
294
294
|
// Evaluate expression
|
|
295
295
|
evaluate: (r) => {
|
|
296
296
|
const a = [], c = [];
|
|
297
|
-
for (r.forEach((
|
|
298
|
-
if (!
|
|
299
|
-
a.push(parseFloat(
|
|
297
|
+
for (r.forEach((l) => {
|
|
298
|
+
if (!E.isOperator(l))
|
|
299
|
+
a.push(parseFloat(l));
|
|
300
300
|
else {
|
|
301
|
-
for (; c.length > 0 &&
|
|
301
|
+
for (; c.length > 0 && E.isOperator(c[c.length - 1]) && E.getPrecedence(c[c.length - 1]) >= E.getPrecedence(l); )
|
|
302
302
|
a.push(c.pop());
|
|
303
|
-
c.push(
|
|
303
|
+
c.push(l);
|
|
304
304
|
}
|
|
305
305
|
}); c.length > 0; )
|
|
306
306
|
a.push(c.pop());
|
|
307
307
|
const i = [];
|
|
308
|
-
return a.forEach((
|
|
309
|
-
if (!
|
|
310
|
-
i.push(
|
|
308
|
+
return a.forEach((l) => {
|
|
309
|
+
if (!E.isOperator(l))
|
|
310
|
+
i.push(l);
|
|
311
311
|
else {
|
|
312
|
-
const n = i.pop(),
|
|
313
|
-
switch (
|
|
312
|
+
const n = i.pop(), p = i.pop();
|
|
313
|
+
switch (l) {
|
|
314
314
|
case "+":
|
|
315
|
-
i.push(
|
|
315
|
+
i.push(p + n);
|
|
316
316
|
break;
|
|
317
317
|
case "-":
|
|
318
|
-
i.push(
|
|
318
|
+
i.push(p - n);
|
|
319
319
|
break;
|
|
320
320
|
case "×":
|
|
321
|
-
i.push(
|
|
321
|
+
i.push(p * n);
|
|
322
322
|
break;
|
|
323
323
|
case "÷":
|
|
324
|
-
i.push(n !== 0 ?
|
|
324
|
+
i.push(n !== 0 ? p / n : "Error");
|
|
325
325
|
break;
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
}), i[0];
|
|
329
329
|
}
|
|
330
|
-
},
|
|
331
|
-
const [r, a] =
|
|
332
|
-
a((x) =>
|
|
333
|
-
}, [
|
|
334
|
-
a((
|
|
335
|
-
}, [
|
|
330
|
+
}, ve = () => {
|
|
331
|
+
const [r, a] = O("0"), [c, i] = O([]), [l, n] = O(!0), [p, y] = O(0), k = b((o) => {
|
|
332
|
+
a((x) => l || x === "0" || x === "Error" ? (n(!1), o) : x.length < 12 ? x + o : x);
|
|
333
|
+
}, [l]), w = b(() => {
|
|
334
|
+
a((o) => l || o === "0" || o === "Error" ? (n(!1), "0.") : !o.includes(".") && o.length < 12 ? o + "." : o);
|
|
335
|
+
}, [l]), g = b((o) => {
|
|
336
336
|
i((x) => {
|
|
337
|
-
const
|
|
338
|
-
return r !== "Error" &&
|
|
337
|
+
const C = [...x];
|
|
338
|
+
return r !== "Error" && C.push(r), C.push(o), C;
|
|
339
339
|
}), n(!0);
|
|
340
|
-
}, [r]),
|
|
340
|
+
}, [r]), N = b(() => {
|
|
341
341
|
if (r !== "Error") {
|
|
342
|
-
const
|
|
343
|
-
a(
|
|
342
|
+
const o = [...c, r], x = E.evaluate(o);
|
|
343
|
+
a(E.formatNumber(x)), i([]), n(!0);
|
|
344
344
|
}
|
|
345
|
-
}, [r, c]),
|
|
345
|
+
}, [r, c]), _ = b(() => {
|
|
346
346
|
a("0"), i([]), n(!0);
|
|
347
|
-
}, []),
|
|
347
|
+
}, []), j = b(() => {
|
|
348
348
|
a("0"), n(!0);
|
|
349
|
-
}, []),
|
|
350
|
-
a((
|
|
349
|
+
}, []), h = b(() => {
|
|
350
|
+
a((o) => o.length > 1 && o !== "Error" ? o.slice(0, -1) : "0");
|
|
351
351
|
}, []), M = b(() => {
|
|
352
|
-
a((
|
|
353
|
-
if (
|
|
354
|
-
const x =
|
|
355
|
-
return
|
|
352
|
+
a((o) => {
|
|
353
|
+
if (o !== "Error") {
|
|
354
|
+
const x = E.percentage(parseFloat(o));
|
|
355
|
+
return E.formatNumber(x);
|
|
356
356
|
}
|
|
357
|
-
return
|
|
357
|
+
return o;
|
|
358
358
|
});
|
|
359
|
-
}, []),
|
|
360
|
-
a((
|
|
361
|
-
if (
|
|
362
|
-
const x =
|
|
363
|
-
return
|
|
359
|
+
}, []), v = b(() => {
|
|
360
|
+
a((o) => {
|
|
361
|
+
if (o !== "Error" && o !== "0") {
|
|
362
|
+
const x = E.toggleSign(parseFloat(o));
|
|
363
|
+
return E.formatNumber(x);
|
|
364
364
|
}
|
|
365
|
-
return
|
|
365
|
+
return o;
|
|
366
366
|
});
|
|
367
367
|
}, []), D = b(() => {
|
|
368
|
-
r !== "Error" && (
|
|
368
|
+
r !== "Error" && (y((o) => o + parseFloat(r)), n(!0));
|
|
369
369
|
}, [r]), $ = b(() => {
|
|
370
|
-
r !== "Error" && (
|
|
370
|
+
r !== "Error" && (y((o) => o - parseFloat(r)), n(!0));
|
|
371
371
|
}, [r]), F = b(() => {
|
|
372
|
-
a(
|
|
373
|
-
}, [
|
|
374
|
-
|
|
372
|
+
a(E.formatNumber(p)), n(!0);
|
|
373
|
+
}, [p]), Y = b(() => {
|
|
374
|
+
y(0);
|
|
375
375
|
}, []);
|
|
376
376
|
return {
|
|
377
377
|
display: r,
|
|
378
378
|
expression: c,
|
|
379
|
-
memory:
|
|
380
|
-
handleNumber:
|
|
381
|
-
handleDecimal:
|
|
382
|
-
handleOperator:
|
|
383
|
-
handleEquals:
|
|
384
|
-
handleClear:
|
|
385
|
-
handleClearEntry:
|
|
386
|
-
handleBackspace:
|
|
379
|
+
memory: p,
|
|
380
|
+
handleNumber: k,
|
|
381
|
+
handleDecimal: w,
|
|
382
|
+
handleOperator: g,
|
|
383
|
+
handleEquals: N,
|
|
384
|
+
handleClear: _,
|
|
385
|
+
handleClearEntry: j,
|
|
386
|
+
handleBackspace: h,
|
|
387
387
|
handlePercentage: M,
|
|
388
|
-
handleToggleSign:
|
|
388
|
+
handleToggleSign: v,
|
|
389
389
|
handleMemoryAdd: D,
|
|
390
390
|
handleMemorySubtract: $,
|
|
391
391
|
handleMemoryRecall: F,
|
|
@@ -396,9 +396,9 @@ const y = {
|
|
|
396
396
|
expression: a,
|
|
397
397
|
memory: c
|
|
398
398
|
}) => {
|
|
399
|
-
const [i,
|
|
399
|
+
const [i, l] = O(/* @__PURE__ */ new Date());
|
|
400
400
|
return ce(() => {
|
|
401
|
-
const n = setInterval(() =>
|
|
401
|
+
const n = setInterval(() => l(/* @__PURE__ */ new Date()), 1e3);
|
|
402
402
|
return () => clearInterval(n);
|
|
403
403
|
}, []), /* @__PURE__ */ t.jsxs("div", { className: "bg-card rounded-xl p-6 shadow-inner border border-custom", children: [
|
|
404
404
|
/* @__PURE__ */ t.jsxs("div", { className: "flex justify-between items-center mb-4 text-sm text-secondary", children: [
|
|
@@ -420,24 +420,24 @@ const y = {
|
|
|
420
420
|
a.length > 0 && /* @__PURE__ */ t.jsx("div", { className: "text-right text-sm text-secondary mb-2 font-mono", children: a.join(" ") }),
|
|
421
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
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(
|
|
423
|
+
/* @__PURE__ */ t.jsx(me, { className: "w-3 h-3" }),
|
|
424
424
|
/* @__PURE__ */ t.jsx("span", { className: "font-mono", children: r !== "Error" ? parseInt(r).toString(2).slice(0, 16) : "ERROR" })
|
|
425
425
|
] }) })
|
|
426
426
|
] });
|
|
427
427
|
});
|
|
428
428
|
ee.displayName = "Display";
|
|
429
|
-
const
|
|
429
|
+
const m = U(({
|
|
430
430
|
children: r,
|
|
431
431
|
onClick: a,
|
|
432
432
|
type: c = "number",
|
|
433
433
|
size: i = "normal",
|
|
434
|
-
className:
|
|
434
|
+
className: l = ""
|
|
435
435
|
}) => {
|
|
436
436
|
const n = {
|
|
437
437
|
small: "px-3 py-2 text-sm",
|
|
438
438
|
normal: "px-4 py-3 text-base",
|
|
439
439
|
large: "px-6 py-4 text-lg"
|
|
440
|
-
},
|
|
440
|
+
}, p = {
|
|
441
441
|
number: "bg-button-number text-primary",
|
|
442
442
|
operator: "bg-button-operator text-white",
|
|
443
443
|
function: "bg-button-function text-primary",
|
|
@@ -450,82 +450,61 @@ const d = U(({
|
|
|
450
450
|
onClick: a,
|
|
451
451
|
className: `
|
|
452
452
|
${n[i]}
|
|
453
|
-
${
|
|
453
|
+
${p[c]}
|
|
454
454
|
rounded-lg font-semibold transition-all duration-200
|
|
455
455
|
active:scale-95 shadow-sm hover:shadow-md
|
|
456
|
-
${
|
|
456
|
+
${l}
|
|
457
457
|
`,
|
|
458
458
|
children: r
|
|
459
459
|
}
|
|
460
460
|
);
|
|
461
461
|
});
|
|
462
|
-
|
|
462
|
+
m.displayName = "Button";
|
|
463
463
|
const re = U(({
|
|
464
464
|
onNumber: r,
|
|
465
465
|
onDecimal: a,
|
|
466
466
|
onOperator: c,
|
|
467
467
|
onEquals: i,
|
|
468
|
-
onClear:
|
|
468
|
+
onClear: l,
|
|
469
469
|
onClearEntry: n,
|
|
470
|
-
onBackspace:
|
|
471
|
-
onPercentage:
|
|
472
|
-
onToggleSign:
|
|
473
|
-
onMemoryAdd:
|
|
474
|
-
onMemorySubtract:
|
|
475
|
-
onMemoryRecall:
|
|
476
|
-
onMemoryClear:
|
|
470
|
+
onBackspace: p,
|
|
471
|
+
onPercentage: y,
|
|
472
|
+
onToggleSign: k,
|
|
473
|
+
onMemoryAdd: w,
|
|
474
|
+
onMemorySubtract: g,
|
|
475
|
+
onMemoryRecall: N,
|
|
476
|
+
onMemoryClear: _
|
|
477
477
|
}) => {
|
|
478
|
-
const
|
|
478
|
+
const j = [7, 8, 9, 4, 5, 6, 1, 2, 3, 0];
|
|
479
479
|
return /* @__PURE__ */ t.jsxs("div", { className: "grid grid-cols-5 gap-2", children: [
|
|
480
|
-
/* @__PURE__ */ t.jsx(
|
|
481
|
-
/* @__PURE__ */ t.jsx(
|
|
482
|
-
/* @__PURE__ */ t.jsx(
|
|
483
|
-
/* @__PURE__ */ t.jsx(
|
|
484
|
-
/* @__PURE__ */ t.jsx(
|
|
485
|
-
/* @__PURE__ */ t.jsx(
|
|
486
|
-
/* @__PURE__ */ t.jsx(
|
|
487
|
-
/* @__PURE__ */ t.jsx(
|
|
488
|
-
/* @__PURE__ */ t.jsxs(
|
|
489
|
-
/* @__PURE__ */ t.jsx(
|
|
480
|
+
/* @__PURE__ */ t.jsx(m, { type: "memory", onClick: w, size: "small", children: /* @__PURE__ */ t.jsx(de, { className: "w-4 h-4" }) }),
|
|
481
|
+
/* @__PURE__ */ t.jsx(m, { type: "memory", onClick: g, size: "small", children: /* @__PURE__ */ t.jsx(fe, { className: "w-4 h-4" }) }),
|
|
482
|
+
/* @__PURE__ */ t.jsx(m, { type: "memory", onClick: N, size: "small", children: /* @__PURE__ */ t.jsx(pe, { className: "w-4 h-4" }) }),
|
|
483
|
+
/* @__PURE__ */ t.jsx(m, { type: "memory", onClick: _, size: "small", children: /* @__PURE__ */ t.jsx(he, { className: "w-4 h-4" }) }),
|
|
484
|
+
/* @__PURE__ */ t.jsx(m, { type: "function", onClick: n, size: "small", children: "CE" }),
|
|
485
|
+
/* @__PURE__ */ t.jsx(m, { type: "function", onClick: k, size: "small", children: "±" }),
|
|
486
|
+
/* @__PURE__ */ t.jsx(m, { type: "function", onClick: y, size: "small", children: /* @__PURE__ */ t.jsx(xe, { className: "w-4 h-4" }) }),
|
|
487
|
+
/* @__PURE__ */ t.jsx(m, { type: "function", onClick: l, size: "small", children: /* @__PURE__ */ t.jsx(be, { className: "w-4 h-4" }) }),
|
|
488
|
+
/* @__PURE__ */ t.jsxs(m, { type: "function", onClick: p, size: "small", children: [
|
|
489
|
+
/* @__PURE__ */ t.jsx(Ee, { className: "w-4 h-4" }),
|
|
490
490
|
" "
|
|
491
491
|
] }),
|
|
492
|
-
/* @__PURE__ */ t.jsx(
|
|
493
|
-
|
|
494
|
-
/* @__PURE__ */ t.jsx(
|
|
495
|
-
|
|
496
|
-
/* @__PURE__ */ t.jsx(
|
|
497
|
-
|
|
498
|
-
/* @__PURE__ */ t.jsx(
|
|
499
|
-
/* @__PURE__ */ t.jsx(
|
|
500
|
-
/* @__PURE__ */ t.jsx(
|
|
501
|
-
/* @__PURE__ */ t.jsx(
|
|
492
|
+
/* @__PURE__ */ t.jsx(m, { type: "operator", onClick: () => c("÷"), size: "small", children: /* @__PURE__ */ t.jsx(ye, { className: "w-4 h-4" }) }),
|
|
493
|
+
j.slice(0, 3).map((h) => /* @__PURE__ */ t.jsx(m, { onClick: () => r(h.toString()), children: h }, h)),
|
|
494
|
+
/* @__PURE__ */ t.jsx(m, { type: "operator", onClick: () => c("×"), children: /* @__PURE__ */ t.jsx(je, { className: "w-4 h-4" }) }),
|
|
495
|
+
j.slice(3, 6).map((h) => /* @__PURE__ */ t.jsx(m, { onClick: () => r(h.toString()), children: h }, h)),
|
|
496
|
+
/* @__PURE__ */ t.jsx(m, { type: "operator", onClick: () => c("-"), children: /* @__PURE__ */ t.jsx(ge, { className: "w-4 h-4" }) }),
|
|
497
|
+
j.slice(6, 9).map((h) => /* @__PURE__ */ t.jsx(m, { onClick: () => r(h.toString()), children: h }, h)),
|
|
498
|
+
/* @__PURE__ */ t.jsx(m, { type: "operator", onClick: () => c("+"), children: /* @__PURE__ */ t.jsx(Ne, { className: "w-4 h-4" }) }),
|
|
499
|
+
/* @__PURE__ */ t.jsx(m, { type: "number", onClick: a, className: "col-span-2", children: "." }),
|
|
500
|
+
/* @__PURE__ */ t.jsx(m, { type: "number", onClick: () => r("0"), className: "col-span-2", children: "0" }),
|
|
501
|
+
/* @__PURE__ */ t.jsx(m, { type: "equals", onClick: i, className: "col-span-1", children: /* @__PURE__ */ t.jsx(_e, { className: "w-5 h-5" }) })
|
|
502
502
|
] });
|
|
503
503
|
});
|
|
504
504
|
re.displayName = "Keypad";
|
|
505
|
-
const
|
|
506
|
-
const r =
|
|
507
|
-
|
|
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
|
-
] }),
|
|
505
|
+
const Se = () => {
|
|
506
|
+
const r = ve();
|
|
507
|
+
return /* @__PURE__ */ t.jsxs("div", { className: "max-w-md w-full mx-auto p-4", children: [
|
|
529
508
|
/* @__PURE__ */ t.jsx(
|
|
530
509
|
ee,
|
|
531
510
|
{
|
|
@@ -553,12 +532,15 @@ const Ae = () => {
|
|
|
553
532
|
}
|
|
554
533
|
) }),
|
|
555
534
|
/* @__PURE__ */ t.jsx("div", { className: "mt-4 text-xs text-center text-secondary", children: /* @__PURE__ */ t.jsxs("p", { children: [
|
|
556
|
-
"
|
|
535
|
+
"Memory: ",
|
|
557
536
|
r.memory
|
|
558
537
|
] }) })
|
|
559
|
-
] })
|
|
538
|
+
] });
|
|
560
539
|
};
|
|
561
540
|
export {
|
|
562
|
-
|
|
563
|
-
Se as
|
|
541
|
+
m as Button,
|
|
542
|
+
Se as Calculator,
|
|
543
|
+
ee as Display,
|
|
544
|
+
re as Keypad,
|
|
545
|
+
ve as useCalculator
|
|
564
546
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(E,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):(E=typeof globalThis<"u"?globalThis:E||self,i(E.Calculator={},E.React,E.LucideReact))})(this,(function(E,i,b){"use strict";var A={exports:{}},w={};var X;function ae(){if(X)return w;X=1;var r=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function c(u,o,n){var h=null;if(n!==void 0&&(h=""+n),o.key!==void 0&&(h=""+o.key),"key"in o){n={};for(var g in o)g!=="key"&&(n[g]=o[g])}else n=o;return o=n.ref,{$$typeof:r,type:u,key:h,ref:o!==void 0?o:null,props:n}}return w.Fragment=a,w.jsx=c,w.jsxs=c,w}var T={};var Z;function se(){return Z||(Z=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 I:return"Profiler";case z: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 Y:return"Portal";case W:return e.displayName||"Context";case L:return(e._context.displayName||"Context")+".Consumer";case l: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 U: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===U)return"<...>";try{var s=r(e);return s?"<"+s+">":"<...>"}catch{return"<...>"}}function o(){var e=B.A;return e===null?null:e.getOwner()}function n(){return Error("react-stack-top-frame")}function h(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 R(){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 S(e,s,m,f,M,V){var p=m.ref;return e={$$typeof:x,type:e,key:s,props:m,_owner:f},(p!==void 0?p:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:R}):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:V}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function C(e,s,m,f,M,V){var p=s.children;if(p!==void 0)if(f)if(ue(p)){for(f=0;f<p.length;f++)N(p[f]);Object.freeze&&Object.freeze(p)}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 N(p);if(K.call(s,"key")){p=r(e);var v=Object.keys(s).filter(function(me){return me!=="key"});f=0<v.length?"{key: someKey, "+v.join(": ..., ")+": ...}":"{key: someKey}",te[p+f]||(v=0<v.length?"{"+v.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,f,
|
|
6
|
+
<%s key={someKey} {...props} />`,f,p,v,p),te[p+f]=!0)}if(p=null,m!==void 0&&(c(m),p=""+m),h(s)&&(c(s.key),p=""+s.key),"key"in s){m={};for(var G in s)G!=="key"&&(m[G]=s[G])}else m=s;return p&&g(m,typeof e=="function"?e.displayName||e.name||"Unknown":e),S(e,p,m,o(),M,V)}function N(e){_(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===U&&(e._payload.status==="fulfilled"?_(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function _(e){return typeof e=="object"&&e!==null&&e.$$typeof===x}var k=i,x=Symbol.for("react.transitional.element"),Y=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),z=Symbol.for("react.strict_mode"),I=Symbol.for("react.profiler"),L=Symbol.for("react.consumer"),W=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),y=Symbol.for("react.suspense"),P=Symbol.for("react.suspense_list"),oe=Symbol.for("react.memo"),U=Symbol.for("react.lazy"),ce=Symbol.for("react.activity"),ie=Symbol.for("react.client.reference"),B=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,K=Object.prototype.hasOwnProperty,ue=Array.isArray,J=console.createTask?console.createTask:function(){return null};k={react_stack_bottom_frame:function(e){return e()}};var q,$={},ee=k.react_stack_bottom_frame.bind(k,n)(),re=J(u(n)),te={};T.Fragment=O,T.jsx=function(e,s,m){var f=1e4>B.recentlyCreatedOwnerStacks++;return C(e,s,m,!1,f?Error("react-stack-top-frame"):ee,f?J(u(e)):re)},T.jsxs=function(e,s,m){var f=1e4>B.recentlyCreatedOwnerStacks++;return C(e,s,m,!0,f?Error("react-stack-top-frame"):ee,f?J(u(e)):re)}})()),T}var H;function ne(){return H||(H=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(o=>{if(!j.isOperator(o))a.push(parseFloat(o));else{for(;c.length>0&&j.isOperator(c[c.length-1])&&j.getPrecedence(c[c.length-1])>=j.getPrecedence(o);)a.push(c.pop());c.push(o)}});c.length>0;)a.push(c.pop());const u=[];return a.forEach(o=>{if(!j.isOperator(o))u.push(o);else{const n=u.pop(),h=u.pop();switch(o){case"+":u.push(h+n);break;case"-":u.push(h-n);break;case"×":u.push(h*n);break;case"÷":u.push(n!==0?h/n:"Error");break}}}),u[0]}},Q=()=>{const[r,a]=i.useState("0"),[c,u]=i.useState([]),[o,n]=i.useState(!0),[h,g]=i.useState(0),R=i.useCallback(l=>{a(y=>o||y==="0"||y==="Error"?(n(!1),l):y.length<12?y+l:y)},[o]),S=i.useCallback(()=>{a(l=>o||l==="0"||l==="Error"?(n(!1),"0."):!l.includes(".")&&l.length<12?l+".":l)},[o]),C=i.useCallback(l=>{u(y=>{const P=[...y];return r!=="Error"&&P.push(r),P.push(l),P}),n(!0)},[r]),N=i.useCallback(()=>{if(r!=="Error"){const l=[...c,r],y=j.evaluate(l);a(j.formatNumber(y)),u([]),n(!0)}},[r,c]),_=i.useCallback(()=>{a("0"),u([]),n(!0)},[]),k=i.useCallback(()=>{a("0"),n(!0)},[]),x=i.useCallback(()=>{a(l=>l.length>1&&l!=="Error"?l.slice(0,-1):"0")},[]),Y=i.useCallback(()=>{a(l=>{if(l!=="Error"){const y=j.percentage(parseFloat(l));return j.formatNumber(y)}return l})},[]),O=i.useCallback(()=>{a(l=>{if(l!=="Error"&&l!=="0"){const y=j.toggleSign(parseFloat(l));return j.formatNumber(y)}return l})},[]),z=i.useCallback(()=>{r!=="Error"&&(g(l=>l+parseFloat(r)),n(!0))},[r]),I=i.useCallback(()=>{r!=="Error"&&(g(l=>l-parseFloat(r)),n(!0))},[r]),L=i.useCallback(()=>{a(j.formatNumber(h)),n(!0)},[h]),W=i.useCallback(()=>{g(0)},[]);return{display:r,expression:c,memory:h,handleNumber:R,handleDecimal:S,handleOperator:C,handleEquals:N,handleClear:_,handleClearEntry:k,handleBackspace:x,handlePercentage:Y,handleToggleSign:O,handleMemoryAdd:z,handleMemorySubtract:I,handleMemoryRecall:L,handleMemoryClear:W}},D=i.memo(({value:r,expression:a,memory:c})=>{const[u,o]=i.useState(new Date);return i.useEffect(()=>{const n=setInterval(()=>o(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(b.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(b.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(b.Zap,{className:"w-3 h-3"}),t.jsx("span",{className:"font-mono",children:r!=="Error"?parseInt(r).toString(2).slice(0,16):"ERROR"})]})})]})});D.displayName="Display";const d=i.memo(({children:r,onClick:a,type:c="number",size:u="normal",className:o=""})=>{const n={small:"px-3 py-2 text-sm",normal:"px-4 py-3 text-base",large:"px-6 py-4 text-lg"},h={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
7
|
${n[u]}
|
|
8
|
-
${
|
|
8
|
+
${h[c]}
|
|
9
9
|
rounded-lg font-semibold transition-all duration-200
|
|
10
10
|
active:scale-95 shadow-sm hover:shadow-md
|
|
11
|
-
${
|
|
12
|
-
`,children:r})});d.displayName="Button";const
|
|
11
|
+
${o}
|
|
12
|
+
`,children:r})});d.displayName="Button";const F=i.memo(({onNumber:r,onDecimal:a,onOperator:c,onEquals:u,onClear:o,onClearEntry:n,onBackspace:h,onPercentage:g,onToggleSign:R,onMemoryAdd:S,onMemorySubtract:C,onMemoryRecall:N,onMemoryClear:_})=>{const k=[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:S,size:"small",children:t.jsx(b.PlusCircle,{className:"w-4 h-4"})}),t.jsx(d,{type:"memory",onClick:C,size:"small",children:t.jsx(b.MinusCircle,{className:"w-4 h-4"})}),t.jsx(d,{type:"memory",onClick:N,size:"small",children:t.jsx(b.RotateCw,{className:"w-4 h-4"})}),t.jsx(d,{type:"memory",onClick:_,size:"small",children:t.jsx(b.Trash2,{className:"w-4 h-4"})}),t.jsx(d,{type:"function",onClick:n,size:"small",children:"CE"}),t.jsx(d,{type:"function",onClick:R,size:"small",children:"±"}),t.jsx(d,{type:"function",onClick:g,size:"small",children:t.jsx(b.Percent,{className:"w-4 h-4"})}),t.jsx(d,{type:"function",onClick:o,size:"small",children:t.jsx(b.RotateCcw,{className:"w-4 h-4"})}),t.jsxs(d,{type:"function",onClick:h,size:"small",children:[t.jsx(b.Delete,{className:"w-4 h-4"})," "]}),t.jsx(d,{type:"operator",onClick:()=>c("÷"),size:"small",children:t.jsx(b.Divide,{className:"w-4 h-4"})}),k.slice(0,3).map(x=>t.jsx(d,{onClick:()=>r(x.toString()),children:x},x)),t.jsx(d,{type:"operator",onClick:()=>c("×"),children:t.jsx(b.X,{className:"w-4 h-4"})}),k.slice(3,6).map(x=>t.jsx(d,{onClick:()=>r(x.toString()),children:x},x)),t.jsx(d,{type:"operator",onClick:()=>c("-"),children:t.jsx(b.Minus,{className:"w-4 h-4"})}),k.slice(6,9).map(x=>t.jsx(d,{onClick:()=>r(x.toString()),children:x},x)),t.jsx(d,{type:"operator",onClick:()=>c("+"),children:t.jsx(b.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(b.Equal,{className:"w-5 h-5"})})]})});F.displayName="Keypad";const le=()=>{const r=Q();return t.jsxs("div",{className:"max-w-md w-full mx-auto p-4",children:[t.jsx(D,{value:r.display,expression:r.expression,memory:r.memory}),t.jsx("div",{className:"mt-6",children:t.jsx(F,{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:["Memory: ",r.memory]})})]})};E.Button=d,E.Calculator=le,E.Display=D,E.Keypad=F,E.useCalculator=Q,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
|
|
1
2
|
{
|
|
2
3
|
"name": "@birimengo/calculator",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A beautiful calculator component with memory functions
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "A beautiful calculator component with memory functions",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"module": "dist/index.es.js",
|
|
7
8
|
"unpkg": "dist/index.umd.js",
|