Compare commits

..

32 Commits

Author SHA1 Message Date
matmoul a24142cd72 docs: remove obsolete temporary README file 2026-05-16 05:23:42 +02:00
matmoul 4df99d0738 docs: update README for default demo and command aliases 2026-05-16 05:01:17 +02:00
matmoul 1cef2d2d6a fix(calc-02): reorder display buttons in portrait layout 2026-05-16 04:44:18 +02:00
matmoul 442a97d573 fix: reorder calc display buttons in portrait layout 2026-05-16 04:34:20 +02:00
matmoul 44ce67c5cc docs: align calc-02 visual portrait tables 2026-05-16 04:20:22 +02:00
matmoul a7411243de fix: reorder display buttons in calc-02 sample 2026-05-16 04:14:28 +02:00
matmoul f8de4e1709 docs: update project memory for calc-02 UI and command notes 2026-05-16 04:10:19 +02:00
matmoul 003d4fde1b feat(calc-02): add shared popup menus for mode and constants
Refactor the calc-02 demo to use a single popup menu component for angle mode and constants, align the menus to their trigger buttons, and update the README/project notes to reflect the portrait-first demo layout and constant API.
2026-05-16 04:04:01 +02:00
matmoul e5f50aee0a fix: reorder calc-02 display buttons 2026-05-16 03:44:20 +02:00
matmoul 6a7a60a9bc fix: align calc menus with trigger width 2026-05-16 03:41:25 +02:00
matmoul a37ed59b40 fix: reorder calc-02 display buttons 2026-05-16 03:37:04 +02:00
matmoul c09fdc7e0f refactor(calc-02): simplify display and button styling
Remove layered shadows and pressed-state transforms from the calculator UI, and update the stack copy icon markup and active feedback to match the new flat design.
2026-05-16 03:21:49 +02:00
matmoul 849170ea49 docs: update calc-02 portrait visual reference
Move the portrait layout documentation to samples/calc-02/visual-portrait.md and refresh the project memory note to point to the new reference.
2026-05-16 03:11:00 +02:00
matmoul 0100da80bb fix(calc-02): adjust keypad grid sizing 2026-05-16 03:02:43 +02:00
matmoul e1fd730db5 fix: remove panel border from calc sample 2026-05-16 02:48:59 +02:00
matmoul ba53f51bf7 refactor(samples): simplify calc-02 background styling 2026-05-16 02:48:00 +02:00
matmoul 534bbc0afb feat: add dynamic constant management to the calculator core 2026-05-16 02:23:20 +02:00
matmoul 2504716c64 fix: tighten calc stack display layout
Reorder the stack cell grid so the copy button sits beside the label and reduce spacing to better align the value column.
2026-05-16 02:04:47 +02:00
matmoul 6c8c032f7a fix: stabilize calculator display sizing 2026-05-16 02:02:45 +02:00
matmoul d8d0556822 style: tighten calculator sample layout spacing 2026-05-16 01:48:52 +02:00
matmoul 426fd326a5 fix(calc-02): simplify button spacing and menu background 2026-05-16 01:43:00 +02:00
matmoul 5364208491 feat(calc-02): refine display button layout and icon styling 2026-05-16 01:38:53 +02:00
matmoul 1e703bebe8 fix(calc-02): adjust display button layout and enter key spacing 2026-05-16 01:28:30 +02:00
matmoul 54797f9dd9 refactor(samples/calc-02): simplify layout to portrait-only single column
Remove the responsive two-column desktop arrangement and make the calculator stack vertically with a 4-column display button row that preserves alignment. Also align the display buttons with the shared base button styling.
2026-05-16 01:16:47 +02:00
matmoul 75bf6d69df fix(calc-02): align display buttons in a grid
Wrap the display controls in a dedicated grid container, add a spacer for the missing cell, and simplify the button styling so the layout stays consistent across sizes.
2026-05-16 01:08:11 +02:00
matmoul 256e9f2b33 refactor(calc-02): move display buttons into their own grid area 2026-05-16 01:01:14 +02:00
matmoul 77fb671dcf fix: use typographic operator symbols in calculator keypad 2026-05-16 00:37:16 +02:00
matmoul ae11cb8007 fix: tighten calculator layout for full-screen mobile sizing 2026-05-16 00:33:58 +02:00
matmoul ba7fc8b4d6 fix: right-align calculator display text 2026-05-16 00:02:10 +02:00
matmoul b45cfe8091 feat: add root command and fix calc-02 exponent shortcuts 2026-05-15 23:05:43 +02:00
matmoul cb45efff43 feat: add root operation to RPN calculator 2026-05-15 22:58:21 +02:00
matmoul 4e8155b5f0 fix(calc-02): tighten calculator layout and panel styling
Wrap the display and control buttons in a shared display block so the
stack and button panels align as a single unit. Reduce corner radii and
adjust gaps/padding across the calculator to better fit the updated
portrait and desktop layouts.
2026-05-15 22:35:19 +02:00
9 changed files with 400 additions and 341 deletions
+8 -6
View File
@@ -1,6 +1,8 @@
# Project memory
- RPN calculator JS project.
- Read `.memory/state.md` for current state.
- Keep names and commands in English.
- Update memory files based on events: engine, demo, API, commands, exports, docs, or tasks.
# State
- Core engine: `src/rpn-calculator.js`
- Reference demo: `samples/calc-02/` (portrait-first HP48GX layout, compact mode/constants popups; Const button comes before Mode in the display row)
- Important UI behavior: mode button shows the current angle mode; keyboard focus stays on the hidden input on desktop; clipboard paste is supported
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`, `listConstants`, `setConstant`, `removeConstant`, `hasConstant`
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
- Commands: arithmetic, stack, trigonometry, constants `pi` and `e`; arithmetic includes `root`; constants can be added or removed dynamically through the core API
- Exports: browser `window.RpnCalculator`, CommonJS `module.exports`
+4 -5
View File
@@ -1,9 +1,8 @@
# State
- Core engine: `src/rpn-calculator.js`
- Active demo: `samples/calc-02/` responsive HP48GX layout with HP48-like X-line editing; display-adjacent button row stays in 4 columns
- Mode button shows the current angle mode only; selecting a mode uses a popup menu
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`
- Default demo: `samples/dev/` classic browser demo; `samples/calc-02/` remains the portrait-first HP48GX-inspired reference
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`, `listConstants`, `setConstant`, `removeConstant`, `hasConstant`
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
- Commands: arithmetic, stack, trigonometry, constants `pi` and `e`
- Demo actions: keyboard focus is kept on the hidden input on desktop so typing keeps working; the keypad layout places Enter in the bottom-left, ± in the former Enter position, and Esc before Clear for safety; paste parses clipboard text as a number before pushing it to the stack; Ctrl+V is supported via the hidden input paste event; backspace is ignored when the stack is empty; operation errors are shown as an overlay bar on top of the calculator with a shorter timeout and darker red
- Commands: arithmetic, stack, trigonometry, constants `pi`, `e`, `phi`, `g`, and `c`; arithmetic includes `root` with `y√x`, `yroot`, and `nroot` aliases; constants can be added or removed dynamically through the core API
- Demo behavior: `samples/dev/` keeps hidden input focus on desktop and supports clipboard paste; `samples/calc-02/` uses compact mode/constants popups, a 4-column display-adjacent row, stack selection/move mode, and paste through the hidden input
- Exports: browser `window.RpnCalculator`, CommonJS `module.exports`
+34 -26
View File
@@ -1,30 +1,28 @@
# RPN Virtual Calculator
A browser-friendly RPN calculator built around a small, generic JavaScript API.
A browser-friendly RPN calculator built around a small JavaScript API.
## Overview
This project provides:
- a reusable JavaScript RPN engine in `src/rpn-calculator.js`
- a browser demo in `samples/dev/`
- a command system centralized in a single operation dictionary
- a small public API focused on stack operations and generic command dispatch
- a classic browser demo in `samples/dev/`
- a portrait-first HP48GX-inspired demo in `samples/calc-02/`
- a centralized command system with aliases
- a compact public API focused on stack operations, editing, and command dispatch
The main class is `RpnCalculator`.
## Project structure
- `src/rpn-calculator.js`: calculator engine
- `samples/dev/index.html`: active browser demo entry point
- `samples/dev/index.html`: browser demo entry point
- `samples/dev/index.css`: demo styles
- `samples/dev/index.js`: demo UI and keyboard logic
- `samples/calc-01/index.html`: active browser demo entry point
- `samples/calc-01/index.css`: demo styles
- `samples/calc-01/index.js`: demo UI and keyboard logic
- `samples/calc-02/index.html`: new responsive HP48GX-style demo entry point
- `samples/calc-02/index.css`: new responsive demo styles
- `samples/calc-02/index.js`: new demo UI and keyboard logic
- `samples/calc-02/index.html`: portrait-first HP48GX-style demo entry point
- `samples/calc-02/index.css`: portrait-first demo styles
- `samples/calc-02/index.js`: portrait-first HP48GX-style demo UI and keyboard logic
- `samples/calc-XX/`: placeholder name for future demo variants
## Public API
@@ -45,6 +43,10 @@ Instance helpers also available:
- `getOperationsByCategory()`
- `getConstants()`
- `listConstants()`
- `setConstant(name, value)`
- `removeConstant(name)`
- `hasConstant(name)`
Static helpers also available:
@@ -64,10 +66,10 @@ State exposed on instances:
```js README.md
const calc = new RpnCalculator({
maxSize: 2048,
base: 10,
angleMode: 'deg',
enabledCommands: ['add', 'sub', 'mul', 'div']
maxSize: 2048,
base: 10,
angleMode: 'deg',
enabledCommands: ['add', 'sub', 'mul', 'div']
});
```
@@ -84,6 +86,10 @@ Available constants:
- `pi`
- `e`
- `phi`
- `g`
- `c`
- plus any user-defined constants added through the engine API
They can be used through `command(...)`:
@@ -110,6 +116,7 @@ calc.command('e');
- `div` alias: `/`
- `mod` alias: `%`
- `pow` aliases: `^`, `y^x`
- `root` aliases: `y√x`, `yroot`, `nroot`
- `sqr`
- `neg`
- `sqrt` alias: `sqrt(x)`
@@ -134,6 +141,7 @@ calc.command('e');
- `sqrt` accepts alias `sqrt(x)`
- `recip` accepts alias `1/x`
- `div` and `recip` throw `Division by zero` when needed
- `root` computes the y-th root as `x^(1/y)` and throws `Invalid input for root` for invalid inputs
- `sqrt` throws `Invalid input for sqrt` for negative values
- `asin` and `acos` throw explicit domain errors outside `[-1, 1]`
- `log` throws `Invalid input for log` for values `<= 0`
@@ -187,10 +195,10 @@ console.log(calc.pop()); // 5
```html README.md
<script src="./src/rpn-calculator.js"></script>
<script>
const calc = new RpnCalculator({ angleMode: 'deg' });
calc.push(9);
calc.command('sqrt');
console.log(calc.pop());
const calc = new RpnCalculator({ angleMode: 'deg' });
calc.push(9);
calc.command('sqrt');
console.log(calc.pop());
</script>
```
@@ -232,7 +240,7 @@ console.log(calc.pop()); // 0.5
## Demo
The active demo lives in `samples/dev/`.
The default demo lives in `samples/dev/`.
Main UI features:
@@ -242,7 +250,12 @@ Main UI features:
- angle mode selector for `deg`, `rad`, and `grad`
- status pills for `inputValue` and `isEditing`
- grouped panels for `Stack`, `Arithmetic`, `Trigonometry`, and `Constants`
- error display area
- keyboard-friendly hidden input on desktop
## Calc 02 demo
`samples/calc-02/` is a portrait-first HP48GX-inspired demo.
It keeps the display-adjacent button row aligned in four columns, uses compact popup menus for mode and constants, and supports clipboard paste plus the `y√x` root operation.
The demo loads the engine from:
@@ -268,11 +281,6 @@ The current demo supports:
The demo also implements stack selection and stack-item move mode in its UI layer using the public calculator methods.
It keeps the calculator screen focused and updates the visible stack window as the selection moves.
## Calc 02 demo
`samples/calc-02/` is a new responsive HP48GX-inspired demo.
It adapts its layout to the browser window and switches between the supplied portrait and landscape arrangements.
## Exports
`RpnCalculator` is exposed in both environments:
+158 -196
View File
@@ -1,3 +1,4 @@
:root {
--bg0: #10151e;
--bg1: #1b2432;
@@ -37,82 +38,94 @@ body {
min-height: 100vh;
font-family: Arial, sans-serif;
color: var(--buttonText);
background:
radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 32%),
linear-gradient(180deg, var(--bg1), var(--bg0));
background: var(--bg0);
}
.app-shell {
min-height: 100vh;
display: grid;
place-items: center;
padding: clamp(12px, 2vw, 28px);
align-items: start;
justify-items: center;
padding: 0;
}
.calculator {
width: min(100vw - 24px, 1120px);
height: min(100vh - 24px, 900px);
width: 100%;
height: auto;
display: grid;
gap: clamp(10px, 1.4vw, 18px);
padding: clamp(12px, 1.8vw, 18px);
border-radius: 28px;
background: linear-gradient(180deg, var(--panel2), var(--panel));
border: 1px solid var(--edge);
box-shadow: 0 26px 70px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
grid-template-columns: 1.3fr 0.9fr;
grid-template-rows: minmax(0, 0.62fr) min-content minmax(180px, 1fr) minmax(180px, 1fr);
align-content: start;
padding: 8px;
border-radius: 8px;
background: var(--panel);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
grid-template-columns: 1fr;
grid-template-rows: auto auto auto auto auto;
row-gap: 6px;
grid-template-areas:
"display functions"
"buttons functions"
"keypad functions"
"keypad trigo";
"display"
"display-buttons"
"keypad"
"functions"
"trigo";
}
.display-block,
.display-panel,
.display-buttons-panel,
.keypad-panel,
.functions-panel,
.trigo-panel,
.status-line {
border-radius: 18px;
.trigo-panel {
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.06);
background: rgba(6, 10, 16, 0.16);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
box-shadow: none;
}
.display-buttons-panel {
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.06);
background: rgba(6, 10, 16, 0.16);
box-shadow: none;
}
.display-block {
grid-area: display;
display: grid;
gap: 0;
align-self: start;
justify-items: stretch;
grid-template-rows: auto auto;
row-gap: 0;
}
.display-panel {
grid-area: display;
position: relative;
padding: clamp(12px, 1.5vw, 16px);
padding-bottom: clamp(4px, 0.6vw, 8px);
background: linear-gradient(180deg, var(--display), var(--display2));
width: 100%;
padding: 16px;
padding-bottom: 8px;
background: var(--display);
color: var(--displayText);
font-family: "Courier New", monospace;
overflow: hidden;
height: auto;
min-height: clamp(112px, 18vw, 124px);
max-height: none;
align-self: start;
box-sizing: border-box;
height: 138px;
min-height: 138px;
max-height: 138px;
margin-bottom: 0;
}
.display-grid {
height: 100%;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: repeat(4, minmax(0, 1fr));
grid-template-rows: repeat(4, minmax(0, auto));
align-content: start;
gap: 2px;
}
.stack-cell {
display: grid;
grid-template-columns: 2.2ch 1fr auto;
grid-template-columns: 2.2ch auto minmax(0, 1fr);
align-items: center;
gap: 12px;
font-size: clamp(18px, 3vw, 30px);
gap: 8px;
font-size: 20px;
line-height: 1;
min-height: 0;
padding-block: 0;
@@ -128,59 +141,85 @@ body {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: right;
justify-self: end;
font-size: 20px;
}
.display-buttons-panel {
grid-area: display-buttons;
padding: 8px;
align-self: start;
min-height: 0;
}
.display-buttons-panel {
grid-area: buttons;
padding: 8px;
.display-buttons-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
grid-template-rows: repeat(2, auto);
gap: 8px;
align-content: start;
align-items: stretch;
grid-auto-flow: row;
grid-auto-rows: auto;
background: linear-gradient(180deg, #242a33, #1a1f27);
border-color: rgba(255, 255, 255, 0.04);
margin-top: 0;
}
.display-button-spacer {
pointer-events: none;
visibility: hidden;
background: transparent;
border-color: transparent;
box-shadow: none;
}
.display-button {
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 3px 0 rgba(0, 0, 0, 0.34);
background-clip: padding-box;
background: linear-gradient(180deg, #3a414c, #252b34);
color: #e8edf3;
border-color: rgba(255, 255, 255, 0.05);
background: linear-gradient(180deg, var(--btnTop), var(--btnBottom));
color: #eef2f7;
box-shadow: none;
}
.display-button-offset {
grid-column-start: 2;
.display-button-symbol {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 1.2em;
font-size: 1.05em;
line-height: 1;
font-weight: 800;
transform: translateY(-0.01em);
}
.display-buttons-panel > button {
width: 100%;
.paste-symbol {
font-size: 1em;
}
.mode-menu {
.display-buttons-grid > button {
padding: 6px 8px;
}
.menu-popup {
position: fixed;
z-index: 20;
display: grid;
gap: 6px;
padding: 10px;
border-radius: 14px;
background: rgba(18, 24, 33, 0.98);
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
display: flex;
flex-direction: column;
gap: 4px;
padding: 6px;
border-radius: 6px;
background: rgba(16, 21, 30, 0.96);
border: 1px solid rgba(255, 255, 255, 0.12);
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(2px);
}
.mode-menu-item {
min-width: 120px;
.menu-popup-item {
width: 100%;
min-width: 0;
padding: 6px 10px;
border-radius: 5px;
background: linear-gradient(180deg, var(--btnAltTop), var(--btnAltBottom));
text-align: left;
font-weight: 700;
}
.mode-menu-item.is-active {
outline: 2px solid rgba(207, 224, 174, 0.7);
.menu-popup-item.is-active {
outline: 1px solid rgba(207, 224, 174, 0.7);
outline-offset: 0;
}
.key-escape {
@@ -188,33 +227,12 @@ body {
color: #eef2f7;
}
.display-button:nth-child(6) {
background: linear-gradient(180deg, #343b46, #20262e);
}
.display-button:nth-child(7) {
background: linear-gradient(180deg, #343b46, #20262e);
}
.keypad-panel {
grid-area: keypad;
padding: 10px;
}
.functions-panel {
grid-area: functions;
padding: 10px;
align-self: start;
min-height: 0;
padding-top: 10px;
}
.keypad-panel,
.functions-panel,
.trigo-panel {
grid-area: trigo;
padding: 10px;
padding: 8px;
align-self: start;
min-height: 0;
padding-top: 10px;
}
.status-bar {
@@ -256,35 +274,31 @@ body {
.trigo-grid {
display: grid;
gap: 8px;
grid-auto-rows: minmax(0, 1fr);
}
.keypad-grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
grid-template-rows: repeat(5, minmax(0, 1fr));
grid-template-rows: repeat(5, minmax(0, 1.7fr));
}
.functions-grid,
.trigo-grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.functions-grid,
.trigo-grid {
grid-template-rows: repeat(2, minmax(0, 1fr));
}
button {
border: 1px solid rgba(14, 18, 25, 0.85);
border-radius: 12px;
padding: 10px 8px;
border-radius: 8px;
padding: 8px 8px;
font: inherit;
font-weight: 700;
color: var(--btnText);
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
cursor: pointer;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 3px 0 rgba(0, 0, 0, 0.28);
transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
box-shadow: none;
transition: filter 120ms ease, opacity 120ms ease;
line-height: 1;
}
@@ -292,22 +306,28 @@ button:hover {
filter: brightness(1.06);
}
.display-button:hover {
filter: brightness(1.08);
}
button:active {
transform: translateY(2px);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 1px 0 rgba(0, 0, 0, 0.25);
transform: none;
box-shadow: none;
}
.display-button:active {
transform: translateY(2px);
.stack-copy-button:active {
animation: stack-copy-flash 140ms ease-out;
}
@keyframes stack-copy-flash {
0% {
opacity: 0.7;
}
50% {
opacity: 1;
}
100% {
opacity: 0.7;
}
}
.stack-copy-button {
padding: 4px;
border-radius: 999px;
min-width: 24px;
width: 24px;
height: 24px;
@@ -315,11 +335,12 @@ button:active {
place-items: center;
opacity: 0;
pointer-events: none;
transform: scale(0.9);
transform: scale(1);
background: transparent;
border: none;
box-shadow: none;
color: rgba(31, 42, 18, 0.58);
margin-left: 6px;
margin-left: 0;
}
.stack-cell:last-child {
@@ -327,9 +348,9 @@ button:active {
}
.stack-copy-button svg {
width: 13px;
height: 13px;
fill: currentColor;
width: 15px;
height: 15px;
fill: #0a0a0a;
display: block;
}
@@ -346,7 +367,7 @@ button:active {
}
.stack-copy-button:active {
transform: translateY(2px) scale(1);
transform: scale(1);
color: rgba(31, 42, 18, 0.95);
}
@@ -355,19 +376,30 @@ button:active {
outline-offset: 2px;
}
.key-default {
background: linear-gradient(180deg, var(--btnTop), var(--btnBottom));
color: #eef2f7;
}
.key-accent {
background: linear-gradient(180deg, var(--btnAccentTop), var(--btnAccentBottom));
color: #eef2f7;
.keypad-grid > button {
min-height: 1.7em;
}
.key-alt {
background: linear-gradient(180deg, var(--btnAltTop), var(--btnAltBottom));
#keypadGrid > button {
min-height: calc(1.7em * 1.7);
padding-top: calc(8px * 1.7);
padding-bottom: calc(8px * 1.7);
}
#keypadGrid > button.key-default,
#keypadGrid > button.key-accent,
#keypadGrid > button.key-danger,
#keypadGrid > button.key-enter {
min-height: calc(1.7em * 1.7);
}
.key-accent {
background: linear-gradient(180deg, var(--btnAccentTop), var(--btnAccentBottom));
color: #eef2f7;
}
@@ -379,6 +411,7 @@ button:active {
.key-enter {
background: linear-gradient(180deg, var(--btnEnterTop), var(--btnEnterBottom));
color: #eef2f7;
padding-inline: 6px;
}
.hidden-input {
@@ -390,75 +423,4 @@ button:active {
pointer-events: none;
}
@media (orientation: portrait), (max-width: 860px) {
.calculator {
width: min(100vw - 16px, 760px);
height: auto;
min-height: calc(100vh - 16px);
grid-template-columns: 1fr;
grid-template-rows: minmax(160px, auto) auto minmax(220px, auto) auto auto;
grid-template-areas:
"display"
"buttons"
"keypad"
"functions"
"trigo";
}
.display-buttons-panel {
grid-template-columns: repeat(4, minmax(0, 1fr));
grid-template-rows: repeat(2, auto);
margin-top: 0;
}
.keypad-grid {
grid-template-rows: repeat(5, minmax(42px, 1fr));
}
.functions-grid,
.trigo-grid {
grid-auto-rows: minmax(0, 1fr);
grid-template-rows: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 520px) {
.app-shell {
padding: 8px;
}
.calculator {
width: 100%;
min-height: calc(100vh - 16px);
border-radius: 20px;
padding: 10px;
gap: 10px;
}
.display-panel {
padding: 10px;
padding-bottom: 8px;
}
.stack-cell {
font-size: clamp(16px, 5.2vw, 22px);
gap: 8px;
}
.stack-copy-button {
padding: 5px 7px;
min-width: 28px;
}
button {
border-radius: 10px;
padding: 8px 6px;
font-size: 13px;
line-height: 1;
}
.display-buttons-panel {
gap: 6px;
}
}
+21 -16
View File
@@ -9,28 +9,33 @@
<body>
<main class="app-shell">
<section class="calculator calculator-portrait" aria-label="HP48GX style RPN calculator">
<div class="display-panel">
<div class="status-bar" id="statusLine" aria-live="polite"></div>
<div class="display-frame">
<div class="display-grid">
<div class="stack-cell"><span class="stack-label">T:</span><span id="stackT" class="stack-value"></span><button type="button" class="stack-copy-button" data-copy-stack="T" aria-label="Copy T value"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 9V5.5A1.5 1.5 0 0 1 10.5 4h8A1.5 1.5 0 0 1 20 5.5v8A1.5 1.5 0 0 1 18.5 15H15v3.5A1.5 1.5 0 0 1 13.5 20h-8A1.5 1.5 0 0 1 4 18.5v-8A1.5 1.5 0 0 1 5.5 9H9Zm1.5-3a.5.5 0 0 0-.5.5V9h5.5a1.5 1.5 0 0 1 1.5 1.5V16h.5a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5h-8Z"/></svg></button></div>
<div class="stack-cell"><span class="stack-label">Z:</span><span id="stackZ" class="stack-value"></span><button type="button" class="stack-copy-button" data-copy-stack="Z" aria-label="Copy Z value"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 9V5.5A1.5 1.5 0 0 1 10.5 4h8A1.5 1.5 0 0 1 20 5.5v8A1.5 1.5 0 0 1 18.5 15H15v3.5A1.5 1.5 0 0 1 13.5 20h-8A1.5 1.5 0 0 1 4 18.5v-8A1.5 1.5 0 0 1 5.5 9H9Zm1.5-3a.5.5 0 0 0-.5.5V9h5.5a1.5 1.5 0 0 1 1.5 1.5V16h.5a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5h-8Z"/></svg></button></div>
<div class="stack-cell"><span class="stack-label">Y:</span><span id="stackY" class="stack-value"></span><button type="button" class="stack-copy-button" data-copy-stack="Y" aria-label="Copy Y value"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 9V5.5A1.5 1.5 0 0 1 10.5 4h8A1.5 1.5 0 0 1 20 5.5v8A1.5 1.5 0 0 1 18.5 15H15v3.5A1.5 1.5 0 0 1 13.5 20h-8A1.5 1.5 0 0 1 4 18.5v-8A1.5 1.5 0 0 1 5.5 9H9Zm1.5-3a.5.5 0 0 0-.5.5V9h5.5a1.5 1.5 0 0 1 1.5 1.5V16h.5a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5h-8Z"/></svg></button></div>
<div class="stack-cell"><span class="stack-label">X:</span><span id="stackX" class="stack-value"></span><button type="button" class="stack-copy-button" data-copy-stack="X" aria-label="Copy X value"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 9V5.5A1.5 1.5 0 0 1 10.5 4h8A1.5 1.5 0 0 1 20 5.5v8A1.5 1.5 0 0 1 18.5 15H15v3.5A1.5 1.5 0 0 1 13.5 20h-8A1.5 1.5 0 0 1 4 18.5v-8A1.5 1.5 0 0 1 5.5 9H9Zm1.5-3a.5.5 0 0 0-.5.5V9h5.5a1.5 1.5 0 0 1 1.5 1.5V16h.5a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5h-8Z"/></svg></button></div>
<div class="display-block">
<div class="display-panel">
<div class="status-bar" id="statusLine" aria-live="polite"></div>
<div class="display-frame">
<div class="display-grid">
<div class="stack-cell"><span class="stack-label">T:</span><button type="button" class="stack-copy-button" data-copy-stack="T" aria-label="Copy T value"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M15.5 4h-7A2.5 2.5 0 0 0 6 6.5V8H5.5A1.5 1.5 0 0 0 4 9.5v8A2.5 2.5 0 0 0 6.5 20H13a1 1 0 0 0 1-1v-1.5H17.5A2.5 2.5 0 0 0 20 15V6.5A2.5 2.5 0 0 0 17.5 4h-2Zm.5 2h1.5a.5.5 0 0 1 .5.5V14a.5.5 0 0 1-.5.5H13V6.5A2.5 2.5 0 0 0 15.5 6Zm-1.5 12H6.5a.5.5 0 0 1-.5-.5v-8a.5.5 0 0 1 .5-.5h7.5V18Zm-1.5-8h-4V8.5A.5.5 0 0 1 9 8h4a.5.5 0 0 1 .5.5V10Z"/></svg></button><span id="stackT" class="stack-value"></span></div>
<div class="stack-cell"><span class="stack-label">Z:</span><button type="button" class="stack-copy-button" data-copy-stack="Z" aria-label="Copy Z value"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M15.5 4h-7A2.5 2.5 0 0 0 6 6.5V8H5.5A1.5 1.5 0 0 0 4 9.5v8A2.5 2.5 0 0 0 6.5 20H13a1 1 0 0 0 1-1v-1.5H17.5A2.5 2.5 0 0 0 20 15V6.5A2.5 2.5 0 0 0 17.5 4h-2Zm.5 2h1.5a.5.5 0 0 1 .5.5V14a.5.5 0 0 1-.5.5H13V6.5A2.5 2.5 0 0 0 15.5 6Zm-1.5 12H6.5a.5.5 0 0 1-.5-.5v-8a.5.5 0 0 1 .5-.5h7.5V18Zm-1.5-8h-4V8.5A.5.5 0 0 1 9 8h4a.5.5 0 0 1 .5.5V10Z"/></svg></button><span id="stackZ" class="stack-value"></span></div>
<div class="stack-cell"><span class="stack-label">Y:</span><button type="button" class="stack-copy-button" data-copy-stack="Y" aria-label="Copy Y value"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M15.5 4h-7A2.5 2.5 0 0 0 6 6.5V8H5.5A1.5 1.5 0 0 0 4 9.5v8A2.5 2.5 0 0 0 6.5 20H13a1 1 0 0 0 1-1v-1.5H17.5A2.5 2.5 0 0 0 20 15V6.5A2.5 2.5 0 0 0 17.5 4h-2Zm.5 2h1.5a.5.5 0 0 1 .5.5V14a.5.5 0 0 1-.5.5H13V6.5A2.5 2.5 0 0 0 15.5 6Zm-1.5 12H6.5a.5.5 0 0 1-.5-.5v-8a.5.5 0 0 1 .5-.5h7.5V18Zm-1.5-8h-4V8.5A.5.5 0 0 1 9 8h4a.5.5 0 0 1 .5.5V10Z"/></svg></button><span id="stackY" class="stack-value"></span></div>
<div class="stack-cell"><span class="stack-label">X:</span><button type="button" class="stack-copy-button" data-copy-stack="X" aria-label="Copy X value"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M15.5 4h-7A2.5 2.5 0 0 0 6 6.5V8H5.5A1.5 1.5 0 0 0 4 9.5v8A2.5 2.5 0 0 0 6.5 20H13a1 1 0 0 0 1-1v-1.5H17.5A2.5 2.5 0 0 0 20 15V6.5A2.5 2.5 0 0 0 17.5 4h-2Zm.5 2h1.5a.5.5 0 0 1 .5.5V14a.5.5 0 0 1-.5.5H13V6.5A2.5 2.5 0 0 0 15.5 6Zm-1.5 12H6.5a.5.5 0 0 1-.5-.5v-8a.5.5 0 0 1 .5-.5h7.5V18Zm-1.5-8h-4V8.5A.5.5 0 0 1 9 8h4a.5.5 0 0 1 .5.5V10Z"/></svg></button><span id="stackX" class="stack-value"></span></div>
</div>
</div>
</div>
</div>
<div class="display-buttons-panel">
<button id="modeButton" class="display-button">Mode</button>
<button id="pasteButton" class="display-button"></button>
<button id="upButton" class="display-button"></button>
<button id="constButton" class="display-button">π</button>
<button id="leftButton" class="display-button display-button-offset"></button>
<button id="downButton" class="display-button"></button>
<button id="rightButton" class="display-button"></button>
<div class="display-buttons-grid">
<button id="constButton" class="display-button">π</button>
<button id="pasteButton" class="display-button"><span class="display-button-symbol paste-symbol"></span></button>
<button id="upButton" class="display-button"><span class="display-button-symbol arrow-symbol"></span></button>
<button id="modeButton" class="display-button">Mode</button>
<div class="display-button-spacer"></div>
<button id="leftButton" class="display-button display-button-offset"><span class="display-button-symbol arrow-symbol"></span></button>
<button id="downButton" class="display-button"><span class="display-button-symbol arrow-symbol"></span></button>
<button id="rightButton" class="display-button"><span class="display-button-symbol arrow-symbol"></span></button>
</div>
</div>
<div class="keypad-panel">
<div class="keypad-grid" id="keypadGrid"></div>
</div>
+70 -72
View File
@@ -37,15 +37,15 @@ const keypadKeys = [
{ label: '7', input: '7', className: 'key-default' },
{ label: '8', input: '8', className: 'key-default' },
{ label: '9', input: '9', className: 'key-default' },
{ label: '/', action: 'div', className: 'key-accent' },
{ label: '÷', action: 'div', className: 'key-accent' },
{ label: '4', input: '4', className: 'key-default' },
{ label: '5', input: '5', className: 'key-default' },
{ label: '6', input: '6', className: 'key-default' },
{ label: '*', action: 'mul', className: 'key-accent' },
{ label: '×', action: 'mul', className: 'key-accent' },
{ label: '1', input: '1', className: 'key-default' },
{ label: '2', input: '2', className: 'key-default' },
{ label: '3', input: '3', className: 'key-default' },
{ label: '-', action: 'sub', className: 'key-accent' },
{ label: '', action: 'sub', className: 'key-accent' },
{ label: '0', input: '0', className: 'key-default' },
{ label: '.', input: '.', className: 'key-default' },
{ label: '±', action: 'neg', className: 'key-default' },
@@ -58,7 +58,7 @@ const functionKeys = [
{ label: '1/x', action: 'recip', className: 'key-default' },
{ label: '%', action: 'mod', className: 'key-default' },
{ label: '√x', action: 'sqrt', className: 'key-default' },
{ label: 'y√x', action: 'pow', className: 'key-default' },
{ label: 'y√x', action: 'root', className: 'key-default' },
{ label: '10ˣ', action: 'pow10', className: 'key-default' },
{ label: '', spacer: true },
{ label: 'log', action: 'log', className: 'key-default' },
@@ -78,7 +78,6 @@ const trigoKeys = [
{ label: '', spacer: true },
];
const isTouchDevice = window.matchMedia('(pointer: coarse)').matches || 'ontouchstart' in window;
function focusInput() {
@@ -229,7 +228,6 @@ function execute(name) {
} else if (calc.isValidIndex(0)) {
calc.remove(0);
}
} else if (name === 'swap') {
pushEditingValueIfNeeded();
if (calc.isValidIndex(1)) {
@@ -243,11 +241,17 @@ function execute(name) {
}
} else if (name === 'pow10') {
pushEditingValueIfNeeded();
const exponent = calc.stack[0];
calc.remove(0);
calc.push(10);
calc.push(exponent);
calc.command('pow');
} else if (name === 'exp') {
pushEditingValueIfNeeded();
const exponent = calc.stack[0];
calc.remove(0);
calc.push(Math.E);
calc.push(exponent);
calc.command('pow');
} else {
pushEditingValueIfNeeded();
@@ -334,41 +338,49 @@ function handleKeyboard(event) {
}
const modeOptions = ['deg', 'rad', 'grad'];
let modeMenuEl = null;
let activeMenuEl = null;
function closeModeMenu() {
if (modeMenuEl) {
modeMenuEl.remove();
modeMenuEl = null;
if (activeMenuEl) {
activeMenuEl.remove();
activeMenuEl = null;
}
}
function openMenu(anchorButton, items, onSelect) {
const rect = anchorButton.getBoundingClientRect();
const menu = document.createElement('div');
menu.className = 'menu-popup';
menu.style.top = `${rect.bottom + 6 + window.scrollY}px`;
menu.style.left = `${rect.left + window.scrollX}px`;
menu.style.minWidth = `${rect.width}px`;
for (const item of items) {
const button = document.createElement('button');
button.type = 'button';
button.className = `menu-popup-item${item.active ? ' is-active' : ''}`;
button.textContent = item.label;
button.addEventListener('click', () => onSelect(item.value));
menu.appendChild(button);
}
document.body.appendChild(menu);
return menu;
}
function toggleModeMenu() {
if (modeMenuEl) {
if (activeMenuEl) {
closeModeMenu();
return;
}
closeConstMenu();
const rect = modeButton.getBoundingClientRect();
modeMenuEl = document.createElement('div');
modeMenuEl.className = 'mode-menu';
modeMenuEl.style.top = `${rect.bottom + 6 + window.scrollY}px`;
modeOptions.forEach((mode) => {
const button = document.createElement('button');
button.type = 'button';
button.className = `mode-menu-item${mode === calc.angleMode ? ' is-active' : ''}`;
button.textContent = mode;
button.addEventListener('click', () => {
calc.angleMode = mode;
render();
closeModeMenu();
});
modeMenuEl.appendChild(button);
activeMenuEl = openMenu(modeButton, modeOptions.map((mode) => ({
label: mode,
value: mode,
active: mode === calc.angleMode,
})), (mode) => {
calc.angleMode = mode;
render();
closeModeMenu();
});
document.body.appendChild(modeMenuEl);
const menuRect = modeMenuEl.getBoundingClientRect();
const maxLeft = Math.max(8, window.innerWidth - menuRect.width - 8);
modeMenuEl.style.left = `${Math.max(8, Math.min(maxLeft, rect.left + window.scrollX))}px`;
}
modeButton.addEventListener('click', (event) => {
@@ -379,6 +391,7 @@ modeButton.addEventListener('click', (event) => {
window.addEventListener('resize', () => {
closeModeMenu();
closeConstMenu();
render();
});
window.addEventListener('scroll', () => {
closeModeMenu();
@@ -392,10 +405,8 @@ window.addEventListener('click', (event) => {
if (label) copyStackValue(label);
return;
}
if (modeMenuEl && !event.target.closest('.mode-menu') && event.target !== modeButton) {
if (activeMenuEl && !event.target.closest('.menu-popup') && event.target !== modeButton && event.target !== constButton) {
closeModeMenu();
}
if (constMenuEl && !event.target.closest('.mode-menu') && event.target !== constButton) {
closeConstMenu();
}
});
@@ -418,52 +429,43 @@ hiddenInput.addEventListener('paste', (event) => {
upButton.addEventListener('click', () => {});
const constants = [
{ label: 'π', value: Math.PI },
{ label: 'e', value: Math.E },
{ label: 'φ', value: (1 + Math.sqrt(5)) / 2 },
{ label: 'g', value: 9.80665 },
{ label: 'c', value: 299792458 },
];
const constantLabels = {
pi: 'π',
e: 'e',
phi: 'φ',
g: 'g',
c: 'c',
};
const constantOrder = ['pi', 'e', 'phi', 'g', 'c'];
let constMenuEl = null;
function closeConstMenu() {
if (constMenuEl) {
constMenuEl.remove();
constMenuEl = null;
if (activeMenuEl) {
activeMenuEl.remove();
activeMenuEl = null;
}
}
function toggleConstMenu() {
if (constMenuEl) {
if (activeMenuEl) {
closeConstMenu();
return;
}
closeModeMenu();
const rect = constButton.getBoundingClientRect();
constMenuEl = document.createElement('div');
constMenuEl.className = 'mode-menu';
constMenuEl.style.top = `${rect.bottom + 6 + window.scrollY}px`;
constants.forEach((constant) => {
const button = document.createElement('button');
button.type = 'button';
button.className = 'mode-menu-item';
button.textContent = constant.label;
button.addEventListener('click', () => {
pushEditingValueIfNeeded();
calc.push(constant.value);
render();
clearStatus();
closeConstMenu();
focusInput();
});
constMenuEl.appendChild(button);
const availableConstants = calc.listConstants();
const keys = [...constantOrder, ...Object.keys(availableConstants).filter((name) => !constantOrder.includes(name))]
.filter((name) => Object.prototype.hasOwnProperty.call(availableConstants, name));
activeMenuEl = openMenu(constButton, keys.map((name) => ({
label: constantLabels[name] ?? name,
value: name,
})), (name) => {
pushEditingValueIfNeeded();
calc.push(availableConstants[name]);
render();
clearStatus();
closeConstMenu();
focusInput();
});
document.body.appendChild(constMenuEl);
const menuRect = constMenuEl.getBoundingClientRect();
const desiredLeft = rect.right + window.scrollX - menuRect.width;
constMenuEl.style.left = `${Math.max(8, desiredLeft)}px`;
}
constButton.addEventListener('click', (event) => {
@@ -472,7 +474,6 @@ constButton.addEventListener('click', (event) => {
});
leftButton.addEventListener('click', () => {});
downButton.addEventListener('click', () => {
if (!calc.isEditing && calc.isValidIndex(0)) {
const value = calc.stack[0];
@@ -484,19 +485,16 @@ downButton.addEventListener('click', () => {
}
});
rightButton.addEventListener('click', () => {
execute('swap');
});
window.addEventListener('keydown', handleKeyboard, { capture: true });
window.addEventListener('load', focusInput);
window.addEventListener('pageshow', focusInput);
window.addEventListener('focus', focusInput);
window.addEventListener('pointerdown', focusInput, true);
window.addEventListener('mousedown', focusInput, true);
window.addEventListener('click', focusInput, true);
hiddenInput.setAttribute('inputmode', 'none');
hiddenInput.setAttribute('readonly', 'readonly');
@@ -511,7 +509,7 @@ hiddenInput.addEventListener('focus', () => {
});
document.addEventListener('click', (event) => {
if (!isTouchDevice && !event.target.closest('.mode-menu')) {
if (!isTouchDevice && !event.target.closest('.menu-popup')) {
focusInput();
}
});
-10
View File
@@ -1,10 +0,0 @@
┌──────────── Display ────────────┐ ┌────── Functions ─────┐ ┌──────────── Keypad ─────────────┐
| T: | | x^2 | y^x | 1/x | % | | +/- | Clear | Esc | backspace |
| Z: | | √x | y√x | 10^x | | | 7 | 8 | 9 | / |
| Y: | | log | ln | | | | 4 | 5 | 6 | * |
| X: | └──────────────────────┘ | 1 | 2 | 3 | - |
└─────────────────────────────────┘ ┌─────── Trigo ────────┐ | 0 | . | Enter | + |
┌──────── Display Buttons ────────┐ | sin | cos | tan | └─────────────────────────────────┘
| Mode | Paste | Up | Const | | asin | acos | atan |
| | Right | Down | Right | └──────────────────────┘
└─────────────────────────────────┘
@@ -1,13 +1,28 @@
# Calc 02 Visual Portrait
## Display
```
┌──────────── Display ────────────┐
| T: |
| Z: |
| Y: |
| X: |
└─────────────────────────────────┘
```
## Display Buttons
```
┌──────── Display Buttons ────────┐
| Mode | Paste | Up | Const |
| | Right | Down | Right |
| Const | Paste | Up | Mode |
| | Left | Down | Right |
└─────────────────────────────────┘
```
## Keypad
```
┌──────────── Keypad ─────────────┐
| +/- | Clear | Esc | backspace |
| 7 | 8 | 9 | / |
@@ -15,12 +30,23 @@
| 1 | 2 | 3 | - |
| 0 | . | Enter | + |
└─────────────────────────────────┘
┌─────────── Functions ───────────┐
| x^2 | y^x | 1/x | % |
| √x | y√x | 10^x | |
| log | ln | | |
```
## Functions
```
┌──────────── Functions ──────────┐
| x^2 | y^x | 1/x | % |
| √x | y√x | 10^x | |
| log | ln | | |
└─────────────────────────────────┘
┌───────────── Trigo ─────────────┐
| sin | cos | tan | |
| asin | acos | atan | |
```
## Trigo
```
┌──────────── Trigo ──────────────┐
| sin | cos | tan | |
| asin | acos | atan | |
└─────────────────────────────────┘
```
+70 -1
View File
@@ -2,6 +2,9 @@ class RpnCalculator {
static CONSTANTS = {
pi: Math.PI,
e: Math.E,
phi: (1 + Math.sqrt(5)) / 2,
g: 9.80665,
c: 299792458,
};
static OPERATIONS = {
@@ -46,6 +49,20 @@ class RpnCalculator {
aliases: ['^', 'y^x'],
execute: (calc, a, b) => Math.pow(a, b),
},
root: {
category: 'Arithmetic',
argCount: 2,
aliases: ['y√x', 'yroot', 'nroot'],
execute: (calc, a, b) => {
if (b === 0) {
throw new Error('Invalid input for root');
}
if (a < 0 && b % 2 === 0) {
throw new Error('Invalid input for root');
}
return Math.pow(a, 1 / b);
},
},
sqr: {
category: 'Arithmetic',
argCount: 1,
@@ -178,7 +195,7 @@ class RpnCalculator {
static getOperationsByCategory() {
return {
Stack: ['dup', 'drop', 'swap', 'clear', 'enter'],
Arithmetic: ['add', 'sub', 'mul', 'div', 'mod', 'pow', 'sqr', 'neg', 'sqrt', 'recip', 'log', 'ln'],
Arithmetic: ['add', 'sub', 'mul', 'div', 'mod', 'pow', 'root', 'sqr', 'neg', 'sqrt', 'recip', 'log', 'ln'],
Trigonometry: ['sin', 'cos', 'tan', 'asin', 'acos', 'atan'],
};
}
@@ -198,6 +215,15 @@ class RpnCalculator {
this.enabledCommands = new Set(selectedCommands.map((name) => this.normalizeCommandName(name)).filter((name) => RpnCalculator.OPERATIONS[name]));
}
static isValidConstantName(name) {
return typeof name === 'string' && name.trim() !== '';
}
static isReservedName(name) {
const normalized = typeof name === 'string' ? name.toLowerCase() : '';
return Boolean(RpnCalculator.OPERATIONS[normalized]);
}
toRadians(value) {
if (this.angleMode === 'grad') {
return (value * Math.PI) / 200;
@@ -243,6 +269,45 @@ class RpnCalculator {
return typeof name === 'string' && Object.prototype.hasOwnProperty.call(this.constants, name.toLowerCase());
}
setConstant(name, value) {
if (!RpnCalculator.isValidConstantName(name)) {
throw new Error('Invalid constant name');
}
if (!Number.isFinite(value)) {
throw new Error('Invalid constant value');
}
const normalized = name.trim().toLowerCase();
if (RpnCalculator.isReservedName(normalized)) {
throw new Error(`Constant name conflicts with a command: ${name}`);
}
this.constants[normalized] = value;
return value;
}
removeConstant(name) {
if (!RpnCalculator.isValidConstantName(name)) {
throw new Error('Invalid constant name');
}
const normalized = name.trim().toLowerCase();
if (!this.isConstantName(normalized)) {
return false;
}
delete this.constants[normalized];
return true;
}
hasConstant(name) {
if (!RpnCalculator.isValidConstantName(name)) {
return false;
}
return this.isConstantName(name.trim().toLowerCase());
}
push(value) {
if (this.stack.length >= this.maxSize) {
throw new Error('Stack overflow');
@@ -394,6 +459,10 @@ class RpnCalculator {
getConstants() {
return { ...this.constants };
}
listConstants() {
return this.getConstants();
}
}
if (typeof window !== 'undefined') {