Compare commits
48 Commits
b45cfe8091
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 9abdc33713 | |||
| 6dd9550890 | |||
| f44fb8c252 | |||
| 5cc97f754d | |||
| 736154110d | |||
| 62a0f447c5 | |||
| 16b567731f | |||
| b710d5f0eb | |||
| 07a4c533fb | |||
| acc075d30c | |||
| 6a37c7c1e8 | |||
| 5f2d18df99 | |||
| c69380d057 | |||
| c11a75d7f7 | |||
| 813fae1b61 | |||
| 208db58fe7 | |||
| ea6401a006 | |||
| ea61ec17d5 | |||
| a4bbffe65b | |||
| a24142cd72 | |||
| 4df99d0738 | |||
| 1cef2d2d6a | |||
| 442a97d573 | |||
| 44ce67c5cc | |||
| a7411243de | |||
| f8de4e1709 | |||
| 003d4fde1b | |||
| e5f50aee0a | |||
| 6a7a60a9bc | |||
| a37ed59b40 | |||
| c09fdc7e0f | |||
| 849170ea49 | |||
| 0100da80bb | |||
| e1fd730db5 | |||
| ba53f51bf7 | |||
| 534bbc0afb | |||
| 2504716c64 | |||
| 6c8c032f7a | |||
| d8d0556822 | |||
| 426fd326a5 | |||
| 5364208491 | |||
| 1e703bebe8 | |||
| 54797f9dd9 | |||
| 75bf6d69df | |||
| 256e9f2b33 | |||
| 77fb671dcf | |||
| ae11cb8007 | |||
| ba7fc8b4d6 |
+9
-8
@@ -1,8 +1,9 @@
|
|||||||
# Project memory
|
# State
|
||||||
|
- Core engine: `src/rpn-calculator.js`
|
||||||
- RPN calculator JS project.
|
- Reference demo: `samples/calc-02/` (portrait-first HP48GX layout; calc-02 keyboard shortcuts are the reference; compact mode/constants popups; Const button comes before Mode in the display row)
|
||||||
- Read `.memory/state.md` for current state.
|
- Important UI behavior: mode button shows the current angle mode; keyboard focus stays on the hidden input on desktop; clipboard paste is supported
|
||||||
- Keep names and commands in English.
|
- Note: keep scrolling behavior in mind for the calc-02 demo when changing the stack/UI layout
|
||||||
- Update memory files based on events: engine, demo, API, commands, exports, docs, or tasks.
|
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`, `listConstants`, `setConstant`, `removeConstant`, `hasConstant`
|
||||||
- Core arithmetic now includes `root` for y-th roots, and `samples/calc-02/` uses it for `y√x`.
|
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
|
||||||
- `samples/calc-02/` in portrait mode remains the active responsive demo.
|
- 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
@@ -1,9 +1,8 @@
|
|||||||
# State
|
# State
|
||||||
- Core engine: `src/rpn-calculator.js`
|
- Core engine: `src/rpn-calculator.js`
|
||||||
- Active demo: `samples/calc-02/` responsive HP48GX layout with portrait/landscape support; display-adjacent button row stays in 4 columns
|
- Default demo: `samples/dev/` classic browser demo; `samples/calc-02/` remains the portrait-first HP48GX-inspired reference
|
||||||
- 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`, `listConstants`, `setConstant`, `removeConstant`, `hasConstant`
|
||||||
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`
|
|
||||||
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
|
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
|
||||||
- Commands: arithmetic, stack, trigonometry, constants `pi` and `e`; arithmetic now includes `root` for y-th roots
|
- 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 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
|
- 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`
|
- Exports: browser `window.RpnCalculator`, CommonJS `module.exports`
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
# RPN Virtual Calculator
|
# 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
|
## Overview
|
||||||
|
|
||||||
This project provides:
|
This project provides:
|
||||||
|
|
||||||
- a reusable JavaScript RPN engine in `src/rpn-calculator.js`
|
- a reusable JavaScript RPN engine in `src/rpn-calculator.js`
|
||||||
- browser demos in `samples/dev/` and `samples/calc-02/`
|
- a classic browser demo in `samples/dev/`
|
||||||
- a command system centralized in a single operation dictionary
|
- a portrait-first HP48GX-inspired demo in `samples/calc-02/`
|
||||||
- a small public API focused on stack operations and generic command dispatch
|
- a centralized command system with aliases
|
||||||
|
- a compact public API focused on stack operations, editing, and command dispatch
|
||||||
|
|
||||||
The main class is `RpnCalculator`.
|
The main class is `RpnCalculator`.
|
||||||
|
|
||||||
## Project structure
|
## Project structure
|
||||||
|
|
||||||
- `src/rpn-calculator.js`: calculator engine
|
- `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.css`: demo styles
|
||||||
- `samples/dev/index.js`: demo UI and keyboard logic
|
- `samples/dev/index.js`: demo UI and keyboard logic
|
||||||
- `samples/calc-01/index.html`: active browser demo entry point
|
- `samples/calc-02/index.html`: portrait-first HP48GX-style demo entry point
|
||||||
- `samples/calc-01/index.css`: demo styles
|
- `samples/calc-02/index.css`: portrait-first demo styles
|
||||||
- `samples/calc-01/index.js`: demo UI and keyboard logic
|
- `samples/calc-02/index.js`: portrait-first HP48GX-style 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`: responsive HP48GX-style demo UI and keyboard logic
|
|
||||||
- `samples/calc-XX/`: placeholder name for future demo variants
|
- `samples/calc-XX/`: placeholder name for future demo variants
|
||||||
|
|
||||||
## Public API
|
## Public API
|
||||||
@@ -45,6 +43,10 @@ Instance helpers also available:
|
|||||||
|
|
||||||
- `getOperationsByCategory()`
|
- `getOperationsByCategory()`
|
||||||
- `getConstants()`
|
- `getConstants()`
|
||||||
|
- `listConstants()`
|
||||||
|
- `setConstant(name, value)`
|
||||||
|
- `removeConstant(name)`
|
||||||
|
- `hasConstant(name)`
|
||||||
|
|
||||||
Static helpers also available:
|
Static helpers also available:
|
||||||
|
|
||||||
@@ -64,10 +66,10 @@ State exposed on instances:
|
|||||||
|
|
||||||
```js README.md
|
```js README.md
|
||||||
const calc = new RpnCalculator({
|
const calc = new RpnCalculator({
|
||||||
maxSize: 2048,
|
maxSize: 2048,
|
||||||
base: 10,
|
base: 10,
|
||||||
angleMode: 'deg',
|
angleMode: 'deg',
|
||||||
enabledCommands: ['add', 'sub', 'mul', 'div']
|
enabledCommands: ['add', 'sub', 'mul', 'div']
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -84,6 +86,10 @@ Available constants:
|
|||||||
|
|
||||||
- `pi`
|
- `pi`
|
||||||
- `e`
|
- `e`
|
||||||
|
- `phi`
|
||||||
|
- `g`
|
||||||
|
- `c`
|
||||||
|
- plus any user-defined constants added through the engine API
|
||||||
|
|
||||||
They can be used through `command(...)`:
|
They can be used through `command(...)`:
|
||||||
|
|
||||||
@@ -189,10 +195,10 @@ console.log(calc.pop()); // 5
|
|||||||
```html README.md
|
```html README.md
|
||||||
<script src="./src/rpn-calculator.js"></script>
|
<script src="./src/rpn-calculator.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const calc = new RpnCalculator({ angleMode: 'deg' });
|
const calc = new RpnCalculator({ angleMode: 'deg' });
|
||||||
calc.push(9);
|
calc.push(9);
|
||||||
calc.command('sqrt');
|
calc.command('sqrt');
|
||||||
console.log(calc.pop());
|
console.log(calc.pop());
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -234,7 +240,7 @@ console.log(calc.pop()); // 0.5
|
|||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
The active demo lives in `samples/dev/`.
|
The default demo lives in `samples/dev/`.
|
||||||
|
|
||||||
Main UI features:
|
Main UI features:
|
||||||
|
|
||||||
@@ -244,7 +250,12 @@ Main UI features:
|
|||||||
- angle mode selector for `deg`, `rad`, and `grad`
|
- angle mode selector for `deg`, `rad`, and `grad`
|
||||||
- status pills for `inputValue` and `isEditing`
|
- status pills for `inputValue` and `isEditing`
|
||||||
- grouped panels for `Stack`, `Arithmetic`, `Trigonometry`, and `Constants`
|
- 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:
|
The demo loads the engine from:
|
||||||
|
|
||||||
@@ -264,16 +275,14 @@ The current demo supports:
|
|||||||
- `Escape`
|
- `Escape`
|
||||||
- `ArrowUp`, `ArrowDown`, `ArrowRight`
|
- `ArrowUp`, `ArrowDown`, `ArrowRight`
|
||||||
- `+`, `-`, `*`, `/`, `%`, `^`
|
- `+`, `-`, `*`, `/`, `%`, `^`
|
||||||
- `q`, `n`, `r`, `i`, `g`, `l`, `s`, `c`, `S`, `C`
|
- `s`, `S`, `r`, `R`, `v`, `u`
|
||||||
- `x`, `y`, `z`, `t`
|
- `l`, `L`, `n`, `N`, `e`, `E`
|
||||||
|
- `i`, `o`, `a`, `I`, `O`, `A`
|
||||||
|
|
||||||
The demo also implements stack selection and stack-item move mode in its UI layer using the public calculator methods.
|
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.
|
It keeps the calculator screen focused and updates the visible stack window as the selection moves.
|
||||||
|
|
||||||
## Calc 02 demo
|
Note: `calc-02` keyboard shortcuts are the reference for this project.
|
||||||
|
|
||||||
`samples/calc-02/` is a responsive HP48GX-inspired demo.
|
|
||||||
It adapts its layout to the browser window, supports portrait and landscape arrangements, and includes the `y√x` root operation.
|
|
||||||
|
|
||||||
## Exports
|
## Exports
|
||||||
|
|
||||||
|
|||||||
+192
-209
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
:root {
|
:root {
|
||||||
--bg0: #10151e;
|
--bg0: #10151e;
|
||||||
--bg1: #1b2432;
|
--bg1: #1b2432;
|
||||||
@@ -31,43 +32,39 @@
|
|||||||
html, body {
|
html, body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
|
overflow-y: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
color: var(--buttonText);
|
color: var(--buttonText);
|
||||||
background:
|
background: var(--bg0);
|
||||||
radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 32%),
|
|
||||||
linear-gradient(180deg, var(--bg1), var(--bg0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-shell {
|
.app-shell {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
display: grid;
|
display: grid;
|
||||||
place-items: center;
|
align-items: start;
|
||||||
padding: clamp(12px, 2vw, 28px);
|
justify-items: center;
|
||||||
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.calculator {
|
.calculator {
|
||||||
width: min(100vw - 24px, 1120px);
|
width: 100%;
|
||||||
height: min(100vh - 24px, 900px);
|
max-width: 460px;
|
||||||
|
height: 100vh;
|
||||||
|
max-height: 100vh;
|
||||||
|
padding: 8px;
|
||||||
display: grid;
|
display: grid;
|
||||||
padding: clamp(12px, 1.8vw, 18px);
|
grid-template-rows: auto auto minmax(0, 1fr);
|
||||||
|
gap: 8px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: linear-gradient(180deg, var(--panel2), var(--panel));
|
background: var(--panel);
|
||||||
border: 1px solid var(--edge);
|
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
||||||
box-shadow: 0 26px 70px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
justify-content: stretch;
|
||||||
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;
|
align-content: start;
|
||||||
grid-template-areas:
|
overflow: hidden;
|
||||||
"display functions"
|
|
||||||
"display functions"
|
|
||||||
"keypad functions"
|
|
||||||
"keypad trigo";
|
|
||||||
row-gap: 0;
|
|
||||||
column-gap: clamp(10px, 1.4vw, 18px);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.display-block,
|
.display-block,
|
||||||
@@ -75,16 +72,14 @@ body {
|
|||||||
.display-buttons-panel,
|
.display-buttons-panel,
|
||||||
.keypad-panel,
|
.keypad-panel,
|
||||||
.functions-panel,
|
.functions-panel,
|
||||||
.trigo-panel,
|
.trigo-panel {
|
||||||
.status-line {
|
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||||
background: rgba(6, 10, 16, 0.16);
|
background: rgba(6, 10, 16, 0.16);
|
||||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.display-block {
|
.display-block {
|
||||||
grid-area: display;
|
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 0;
|
gap: 0;
|
||||||
align-self: start;
|
align-self: start;
|
||||||
@@ -96,110 +91,139 @@ body {
|
|||||||
.display-panel {
|
.display-panel {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: clamp(12px, 1.5vw, 16px);
|
padding: 16px;
|
||||||
padding-bottom: clamp(4px, 0.6vw, 8px);
|
padding-bottom: 8px;
|
||||||
background: linear-gradient(180deg, var(--display), var(--display2));
|
background: var(--display);
|
||||||
color: var(--displayText);
|
color: var(--displayText);
|
||||||
font-family: "Courier New", monospace;
|
font-family: "Courier New", monospace;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
height: auto;
|
box-sizing: border-box;
|
||||||
min-height: clamp(112px, 18vw, 124px);
|
height: 138px;
|
||||||
max-height: none;
|
min-height: 138px;
|
||||||
|
max-height: 138px;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.display-frame {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.display-buttons-panel {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.display-grid {
|
.display-grid {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr;
|
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;
|
gap: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stack-cell {
|
.stack-cell {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 2.2ch 1fr auto;
|
grid-template-columns: 2.2ch auto minmax(0, 1fr);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 12px;
|
gap: 8px;
|
||||||
font-size: clamp(18px, 3vw, 30px);
|
font-size: 20px;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
padding-block: 0;
|
padding-block: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stack-label {
|
/* removed extra first-column styling */
|
||||||
text-align: right;
|
|
||||||
opacity: 0.78;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stack-value {
|
.stack-value {
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
text-align: right;
|
||||||
|
justify-self: end;
|
||||||
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.stack-value.is-editing {
|
||||||
|
letter-spacing: 0.02em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.stack-cell.is-selected {
|
||||||
|
background: transparent;
|
||||||
|
border-radius: 6px;
|
||||||
|
outline: 2px solid rgba(31, 42, 18, 0.2);
|
||||||
|
outline-offset: -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stack-cell.is-moving {
|
||||||
|
background: rgba(31, 42, 18, 0.18);
|
||||||
|
}
|
||||||
.display-buttons-panel {
|
.display-buttons-panel {
|
||||||
width: 100%;
|
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
min-height: 0;
|
||||||
|
background: rgba(6, 10, 16, 0.16);
|
||||||
|
}
|
||||||
|
|
||||||
|
.display-buttons-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
grid-template-rows: repeat(2, auto);
|
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
align-content: start;
|
align-content: start;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
grid-auto-flow: row;
|
}
|
||||||
grid-auto-rows: auto;
|
|
||||||
background: linear-gradient(180deg, #242a33, #1a1f27);
|
.display-button-spacer {
|
||||||
border-color: rgba(255, 255, 255, 0.04);
|
pointer-events: none;
|
||||||
margin-top: 0;
|
visibility: hidden;
|
||||||
|
background: transparent;
|
||||||
|
border-color: transparent;
|
||||||
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.display-button {
|
.display-button {
|
||||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 3px 0 rgba(0, 0, 0, 0.34);
|
background: linear-gradient(180deg, var(--btnTop), var(--btnBottom));
|
||||||
background-clip: padding-box;
|
color: #eef2f7;
|
||||||
background: linear-gradient(180deg, #3a414c, #252b34);
|
box-shadow: none;
|
||||||
color: #e8edf3;
|
|
||||||
border-color: rgba(255, 255, 255, 0.05);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.display-button-offset {
|
.display-button-symbol {
|
||||||
grid-column-start: 2;
|
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 {
|
.paste-symbol {
|
||||||
width: 100%;
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mode-menu {
|
.display-buttons-grid > button {
|
||||||
|
padding: 6px 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-popup {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 20;
|
z-index: 20;
|
||||||
display: grid;
|
display: flex;
|
||||||
gap: 6px;
|
flex-direction: column;
|
||||||
padding: 10px;
|
gap: 4px;
|
||||||
border-radius: 8px;
|
padding: 6px;
|
||||||
background: rgba(18, 24, 33, 0.98);
|
border-radius: 6px;
|
||||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
background: rgba(16, 21, 30, 0.96);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||||
box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
|
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.mode-menu-item {
|
.menu-popup-item {
|
||||||
min-width: 120px;
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 5px;
|
||||||
background: linear-gradient(180deg, var(--btnAltTop), var(--btnAltBottom));
|
background: linear-gradient(180deg, var(--btnAltTop), var(--btnAltBottom));
|
||||||
|
text-align: left;
|
||||||
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mode-menu-item.is-active {
|
.menu-popup-item.is-active {
|
||||||
outline: 2px solid rgba(207, 224, 174, 0.7);
|
outline: 1px solid rgba(207, 224, 174, 0.7);
|
||||||
|
outline-offset: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.key-escape {
|
.key-escape {
|
||||||
@@ -207,35 +231,24 @@ body {
|
|||||||
color: #eef2f7;
|
color: #eef2f7;
|
||||||
}
|
}
|
||||||
|
|
||||||
.display-button:nth-child(6) {
|
.keypad-panel,
|
||||||
background: linear-gradient(180deg, #343b46, #20262e);
|
.functions-panel,
|
||||||
}
|
|
||||||
|
|
||||||
.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;
|
|
||||||
padding-bottom: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.trigo-panel {
|
.trigo-panel {
|
||||||
grid-area: trigo;
|
padding: 8px;
|
||||||
padding: 10px;
|
|
||||||
align-self: start;
|
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
padding-top: 10px;
|
}
|
||||||
padding-bottom: 8px;
|
|
||||||
|
.calculator > .display-block,
|
||||||
|
.calculator > .display-buttons-panel,
|
||||||
|
.calculator > .keypad-scroll-area {
|
||||||
|
justify-self: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.keypad-scroll-area {
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: rgba(46, 105, 135, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-bar {
|
.status-bar {
|
||||||
@@ -277,36 +290,30 @@ body {
|
|||||||
.trigo-grid {
|
.trigo-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
grid-auto-rows: minmax(0, 1fr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.keypad-grid {
|
.keypad-grid {
|
||||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
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,
|
.functions-grid,
|
||||||
.trigo-grid {
|
.trigo-grid {
|
||||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
}
|
|
||||||
|
|
||||||
.functions-grid,
|
|
||||||
.trigo-grid {
|
|
||||||
grid-template-rows: repeat(2, minmax(0, 1fr));
|
grid-template-rows: repeat(2, minmax(0, 1fr));
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
border: 1px solid rgba(14, 18, 25, 0.85);
|
border: 1px solid rgba(14, 18, 25, 0.85);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 10px 8px;
|
padding: 8px 8px;
|
||||||
|
|
||||||
font: inherit;
|
font: inherit;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: var(--btnText);
|
color: var(--btnText);
|
||||||
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
|
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 3px 0 rgba(0, 0, 0, 0.28);
|
box-shadow: none;
|
||||||
transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
|
transition: filter 120ms ease, opacity 120ms ease;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,22 +321,29 @@ button:hover {
|
|||||||
filter: brightness(1.06);
|
filter: brightness(1.06);
|
||||||
}
|
}
|
||||||
|
|
||||||
.display-button:hover {
|
|
||||||
filter: brightness(1.08);
|
|
||||||
}
|
|
||||||
|
|
||||||
button:active {
|
button:active {
|
||||||
transform: translateY(2px);
|
transform: none;
|
||||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 1px 0 rgba(0, 0, 0, 0.25);
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.display-button:active {
|
.stack-copy-button:active {
|
||||||
transform: translateY(2px);
|
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 {
|
.stack-copy-button {
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
border-radius: 999px;
|
|
||||||
min-width: 24px;
|
min-width: 24px;
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
@@ -337,11 +351,12 @@ button:active {
|
|||||||
place-items: center;
|
place-items: center;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
transform: scale(0.9);
|
transform: scale(1);
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
border: none;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
color: rgba(31, 42, 18, 0.58);
|
color: rgba(31, 42, 18, 0.58);
|
||||||
margin-left: 6px;
|
margin-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stack-cell:last-child {
|
.stack-cell:last-child {
|
||||||
@@ -349,9 +364,9 @@ button:active {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.stack-copy-button svg {
|
.stack-copy-button svg {
|
||||||
width: 13px;
|
width: 15px;
|
||||||
height: 13px;
|
height: 15px;
|
||||||
fill: currentColor;
|
fill: #0a0a0a;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +383,7 @@ button:active {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.stack-copy-button:active {
|
.stack-copy-button:active {
|
||||||
transform: translateY(2px) scale(1);
|
transform: scale(1);
|
||||||
color: rgba(31, 42, 18, 0.95);
|
color: rgba(31, 42, 18, 0.95);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,19 +392,61 @@ button:active {
|
|||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.stack-value.is-editing {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-text {
|
||||||
|
display: inline-block;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-caret {
|
||||||
|
display: inline-block;
|
||||||
|
width: 1px;
|
||||||
|
height: 1em;
|
||||||
|
margin: 0 0.12ch;
|
||||||
|
background: currentColor;
|
||||||
|
animation: caret-blink 1s steps(1, end) infinite;
|
||||||
|
transform: translateY(0.02em);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes caret-blink {
|
||||||
|
0%, 49% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
50%, 100% {
|
||||||
|
opacity: 0.15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.key-default {
|
.key-default {
|
||||||
background: linear-gradient(180deg, var(--btnTop), var(--btnBottom));
|
background: linear-gradient(180deg, var(--btnTop), var(--btnBottom));
|
||||||
color: #eef2f7;
|
color: #eef2f7;
|
||||||
}
|
}
|
||||||
|
|
||||||
.key-accent {
|
.keypad-grid > button {
|
||||||
background: linear-gradient(180deg, var(--btnAccentTop), var(--btnAccentBottom));
|
min-height: 1.7em;
|
||||||
color: #eef2f7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.key-alt {
|
#keypadGrid > button {
|
||||||
background: linear-gradient(180deg, var(--btnAltTop), var(--btnAltBottom));
|
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;
|
color: #eef2f7;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,6 +458,7 @@ button:active {
|
|||||||
.key-enter {
|
.key-enter {
|
||||||
background: linear-gradient(180deg, var(--btnEnterTop), var(--btnEnterBottom));
|
background: linear-gradient(180deg, var(--btnEnterTop), var(--btnEnterBottom));
|
||||||
color: #eef2f7;
|
color: #eef2f7;
|
||||||
|
padding-inline: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hidden-input {
|
.hidden-input {
|
||||||
@@ -412,79 +470,4 @@ button:active {
|
|||||||
pointer-events: none;
|
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 auto auto;
|
|
||||||
row-gap: 6px;
|
|
||||||
grid-template-areas:
|
|
||||||
"display"
|
|
||||||
"keypad"
|
|
||||||
"functions"
|
|
||||||
"trigo";
|
|
||||||
}
|
|
||||||
|
|
||||||
.display-buttons-panel {
|
|
||||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
||||||
grid-template-rows: repeat(2, auto);
|
|
||||||
margin-top: 0;
|
|
||||||
margin-bottom: 0;
|
|
||||||
padding-top: 4px;
|
|
||||||
padding-bottom: 4px;
|
|
||||||
align-content: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.keypad-grid {
|
|
||||||
grid-template-rows: repeat(5, minmax(42px, 1fr));
|
|
||||||
}
|
|
||||||
|
|
||||||
.functions-grid,
|
|
||||||
.trigo-grid {
|
|
||||||
grid-auto-rows: minmax(0, auto);
|
|
||||||
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: 8px;
|
|
||||||
padding: 10px;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.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: 8px;
|
|
||||||
padding: 8px 6px;
|
|
||||||
font-size: 13px;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.display-buttons-panel {
|
|
||||||
gap: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
+33
-28
@@ -4,46 +4,51 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>HP48GX RPN Calculator</title>
|
<title>HP48GX RPN Calculator</title>
|
||||||
<link rel="stylesheet" href="./index.css">
|
<link rel="stylesheet" href="./index.css?ver=1">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main class="app-shell">
|
<main class="app-shell">
|
||||||
<section class="calculator calculator-portrait" aria-label="HP48GX style RPN calculator">
|
<section class="calculator" aria-label="HP48GX style RPN calculator">
|
||||||
<div class="display-block">
|
<div class="display-block">
|
||||||
<div class="display-panel">
|
<div class="display-panel">
|
||||||
<div class="status-bar" id="statusLine" aria-live="polite"></div>
|
<div class="status-bar" id="statusLine" aria-live="polite"></div>
|
||||||
<div class="display-frame">
|
<div class="display-frame">
|
||||||
<div class="display-grid">
|
<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">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><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">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><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">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><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="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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="display-buttons-panel">
|
<div class="display-buttons-panel">
|
||||||
<button id="modeButton" class="display-button">Mode</button>
|
<div class="display-buttons-grid">
|
||||||
<button id="pasteButton" class="display-button">⎘</button>
|
<button id="constButton" class="display-button">π</button>
|
||||||
<button id="upButton" class="display-button">↑</button>
|
<button id="pasteButton" class="display-button"><span class="display-button-symbol paste-symbol">⎘</span></button>
|
||||||
<button id="constButton" class="display-button">π</button>
|
<button id="upButton" class="display-button"><span class="display-button-symbol arrow-symbol">↑</span></button>
|
||||||
<button id="leftButton" class="display-button display-button-offset">←</button>
|
<button id="modeButton" class="display-button">Mode</button>
|
||||||
<button id="downButton" class="display-button">↓</button>
|
<div class="display-button-spacer"></div>
|
||||||
<button id="rightButton" class="display-button">→</button>
|
<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>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="keypad-panel">
|
<div class="keypad-scroll-area">
|
||||||
<div class="keypad-grid" id="keypadGrid"></div>
|
<div class="keypad-panel">
|
||||||
</div>
|
<div class="keypad-grid" id="keypadGrid"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="functions-panel">
|
<div class="functions-panel">
|
||||||
<div class="functions-grid" id="functionsGrid"></div>
|
<div class="functions-grid" id="functionsGrid"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="trigo-panel">
|
<div class="trigo-panel">
|
||||||
<div class="trigo-grid" id="trigoGrid"></div>
|
<div class="trigo-grid" id="trigoGrid"></div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<input id="hiddenInput" class="hidden-input" type="text" autocomplete="off" aria-hidden="true" tabindex="-1">
|
<input id="hiddenInput" class="hidden-input" type="text" autocomplete="off" aria-hidden="true" tabindex="-1">
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
+405
-144
@@ -30,22 +30,22 @@ const calculatorEl = document.querySelector('.calculator');
|
|||||||
const statusLine = document.getElementById('statusLine');
|
const statusLine = document.getElementById('statusLine');
|
||||||
|
|
||||||
const keypadKeys = [
|
const keypadKeys = [
|
||||||
{ label: 'ENTER', action: 'enter', className: 'key-enter' },
|
|
||||||
{ label: '⎋', action: 'escape', className: 'key-escape' },
|
|
||||||
{ label: 'C', action: 'clear', className: 'key-danger' },
|
{ label: 'C', action: 'clear', className: 'key-danger' },
|
||||||
{ label: '⌫', action: 'backspace', className: 'key-danger' },
|
{ label: '⌫', action: 'backspace', className: 'key-danger' },
|
||||||
|
{ label: '⎋', action: 'escape', className: 'key-escape' },
|
||||||
|
{ label: '⏎', action: 'enter', className: 'key-enter' },
|
||||||
{ label: '7', input: '7', className: 'key-default' },
|
{ label: '7', input: '7', className: 'key-default' },
|
||||||
{ label: '8', input: '8', className: 'key-default' },
|
{ label: '8', input: '8', className: 'key-default' },
|
||||||
{ label: '9', input: '9', 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: '4', input: '4', className: 'key-default' },
|
||||||
{ label: '5', input: '5', className: 'key-default' },
|
{ label: '5', input: '5', className: 'key-default' },
|
||||||
{ label: '6', input: '6', 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: '1', input: '1', className: 'key-default' },
|
||||||
{ label: '2', input: '2', className: 'key-default' },
|
{ label: '2', input: '2', className: 'key-default' },
|
||||||
{ label: '3', input: '3', 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: '0', input: '0', className: 'key-default' },
|
||||||
{ label: '.', input: '.', className: 'key-default' },
|
{ label: '.', input: '.', className: 'key-default' },
|
||||||
{ label: '±', action: 'neg', className: 'key-default' },
|
{ label: '±', action: 'neg', className: 'key-default' },
|
||||||
@@ -53,32 +53,31 @@ const keypadKeys = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const functionKeys = [
|
const functionKeys = [
|
||||||
{ label: 'x²', action: 'sqr', className: 'key-default' },
|
{ label: 'x²', action: 'sqr', className: 'key-default', title: 's' },
|
||||||
{ label: 'yˣ', action: 'pow', className: 'key-default' },
|
{ label: '√x', action: 'sqrt', className: 'key-default', title: 'r' },
|
||||||
{ label: '1/x', action: 'recip', className: 'key-default' },
|
{ label: '1/x', action: 'recip', className: 'key-default', title: 'x' },
|
||||||
{ label: '%', action: 'mod', className: 'key-default' },
|
{ label: '%', action: 'mod', className: 'key-default' },
|
||||||
{ label: '√x', action: 'sqrt', className: 'key-default' },
|
{ label: 'yˣ', action: 'pow', className: 'key-default', title: 'S' },
|
||||||
{ label: 'y√x', action: 'root', className: 'key-default' },
|
{ label: 'y√x', action: 'root', className: 'key-default', title: 'R' },
|
||||||
{ label: '10ˣ', action: 'pow10', className: 'key-default' },
|
{ label: '10ˣ', action: 'pow10', className: 'key-default', title: 'd' },
|
||||||
{ label: '', spacer: true },
|
{ label: '', spacer: true },
|
||||||
{ label: 'log', action: 'log', className: 'key-default' },
|
{ label: 'log', action: 'log', className: 'key-default', title: 'l / L' },
|
||||||
{ label: 'ln', action: 'ln', className: 'key-default' },
|
{ label: 'ln', action: 'ln', className: 'key-default', title: 'n / N' },
|
||||||
{ label: 'eˣ', action: 'exp', className: 'key-default' },
|
{ label: 'eˣ', action: 'exp', className: 'key-default', title: 'e / E' },
|
||||||
{ label: '', spacer: true },
|
{ label: '', spacer: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
const trigoKeys = [
|
const trigoKeys = [
|
||||||
{ label: 'sin', action: 'sin', className: 'key-default' },
|
{ label: 'sin', action: 'sin', className: 'key-default', title: 'i' },
|
||||||
{ label: 'cos', action: 'cos', className: 'key-default' },
|
{ label: 'cos', action: 'cos', className: 'key-default', title: 'o' },
|
||||||
{ label: 'tan', action: 'tan', className: 'key-default' },
|
{ label: 'tan', action: 'tan', className: 'key-default', title: 'a' },
|
||||||
{ label: '', spacer: true },
|
{ label: '', spacer: true },
|
||||||
{ label: 'asin', action: 'asin', className: 'key-default' },
|
{ label: 'asin', action: 'asin', className: 'key-default', title: 'I' },
|
||||||
{ label: 'acos', action: 'acos', className: 'key-default' },
|
{ label: 'acos', action: 'acos', className: 'key-default', title: 'O' },
|
||||||
{ label: 'atan', action: 'atan', className: 'key-default' },
|
{ label: 'atan', action: 'atan', className: 'key-default', title: 'A' },
|
||||||
{ label: '', spacer: true },
|
{ label: '', spacer: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
const isTouchDevice = window.matchMedia('(pointer: coarse)').matches || 'ontouchstart' in window;
|
const isTouchDevice = window.matchMedia('(pointer: coarse)').matches || 'ontouchstart' in window;
|
||||||
|
|
||||||
function focusInput() {
|
function focusInput() {
|
||||||
@@ -95,6 +94,11 @@ function focusInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let statusTimer = null;
|
let statusTimer = null;
|
||||||
|
let editCursor = 0;
|
||||||
|
let editRestoreValue = null;
|
||||||
|
let stackMode = 'normal';
|
||||||
|
let stackSelection = 0;
|
||||||
|
let stackMoveSnapshot = null;
|
||||||
|
|
||||||
function setStatus(message, isError = false, timeoutMs = 1400) {
|
function setStatus(message, isError = false, timeoutMs = 1400) {
|
||||||
if (!statusLine) return;
|
if (!statusLine) return;
|
||||||
@@ -119,27 +123,41 @@ function clearStatus() {
|
|||||||
statusLine.classList.remove('is-error');
|
statusLine.classList.remove('is-error');
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeStack() {
|
|
||||||
while (calc.stack.length > 4) {
|
|
||||||
calc.stack.shift();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStackLine(indexFromTop) {
|
function getStackLine(indexFromTop) {
|
||||||
return indexFromTop >= 0 && indexFromTop < calc.stack.length ? calc.stack[indexFromTop] : '';
|
return indexFromTop >= 0 && indexFromTop < calc.stack.length ? calc.stack[indexFromTop] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStackDisplayValue(label) {
|
function getStackDisplayValue(label) {
|
||||||
if (label === 'X') {
|
if (label === 'X' && calc.isEditing) {
|
||||||
return calc.isEditing ? calc.inputValue : (calc.formatNumber(getStackLine(0)) || '');
|
return calc.inputValue;
|
||||||
}
|
}
|
||||||
if (label === 'Y') {
|
const indexMap = { X: 0, Y: 1, Z: 2, T: 3 };
|
||||||
return calc.isEditing ? (calc.formatNumber(getStackLine(0)) || '') : (calc.formatNumber(getStackLine(1)) || '');
|
const indexFromTop = calc.isEditing ? Math.max(0, indexMap[label] - 1) : indexMap[label];
|
||||||
|
return calc.formatNumber(getStackLine(indexFromTop)) || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVisibleStackLabel(label) {
|
||||||
|
if (stackMode === 'navigation' || stackMode === 'move') {
|
||||||
|
const indexMap = { X: 0, Y: 1, Z: 2, T: 3 };
|
||||||
|
return String(indexMap[label]);
|
||||||
}
|
}
|
||||||
if (label === 'Z') {
|
return label;
|
||||||
return calc.isEditing ? (calc.formatNumber(getStackLine(1)) || '') : (calc.formatNumber(getStackLine(2)) || '');
|
}
|
||||||
|
|
||||||
|
function updateStackLabels() {
|
||||||
|
const stackLabels = ['T', 'Z', 'Y', 'X'];
|
||||||
|
for (const label of stackLabels) {
|
||||||
|
const stackCell = stackEls[label].parentElement;
|
||||||
|
if (!stackCell) continue;
|
||||||
|
const labelEl = stackCell.querySelector('.stack-label');
|
||||||
|
if (labelEl) {
|
||||||
|
labelEl.textContent = `${getVisibleStackLabel(label)}:`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return calc.isEditing ? (calc.formatNumber(getStackLine(2)) || '') : (calc.formatNumber(getStackLine(3)) || '');
|
}
|
||||||
|
|
||||||
|
function stackModeToLabel(index) {
|
||||||
|
return ['X', 'Y', 'Z', 'T'][Math.max(0, Math.min(3, index))] ?? 'X';
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCopyButtons() {
|
function updateCopyButtons() {
|
||||||
@@ -153,40 +171,191 @@ function updateCopyButtons() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderEditValue() {
|
||||||
|
const cursor = Math.max(0, Math.min(editCursor, calc.inputValue.length));
|
||||||
|
stackEls.X.innerHTML = `<span class="edit-text">${calc.inputValue.slice(0, cursor)}</span><span class="edit-caret" aria-hidden="true"></span><span class="edit-text">${calc.inputValue.slice(cursor)}</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
normalizeStack();
|
|
||||||
const isPortrait = window.matchMedia('(orientation: portrait)').matches || window.innerWidth <= 860;
|
const isPortrait = window.matchMedia('(orientation: portrait)').matches || window.innerWidth <= 860;
|
||||||
calculatorEl?.classList.toggle('portrait', isPortrait);
|
calculatorEl?.classList.toggle('portrait', isPortrait);
|
||||||
calculatorEl?.classList.toggle('landscape', !isPortrait);
|
calculatorEl?.classList.toggle('landscape', !isPortrait);
|
||||||
stackEls.X.textContent = getStackDisplayValue('X');
|
const stackLabels = ['T', 'Z', 'Y', 'X'];
|
||||||
stackEls.Y.textContent = getStackDisplayValue('Y');
|
for (const label of stackLabels) {
|
||||||
stackEls.Z.textContent = getStackDisplayValue('Z');
|
const isSelected = stackMode !== 'normal' && stackModeToLabel(stackSelection) === label;
|
||||||
stackEls.T.textContent = getStackDisplayValue('T');
|
const value = label === 'X' && calc.isEditing ? '' : getStackDisplayValue(label);
|
||||||
|
stackEls[label].textContent = value;
|
||||||
|
stackEls[label].classList.toggle('is-editing', label === 'X' && calc.isEditing);
|
||||||
|
stackEls[label].classList.toggle('is-caret-visible', label === 'X' && calc.isEditing);
|
||||||
|
stackEls[label].parentElement?.classList.toggle('is-selected', isSelected);
|
||||||
|
stackEls[label].parentElement?.classList.toggle('is-moving', stackMode === 'move' && stackModeToLabel(stackSelection) === label);
|
||||||
|
}
|
||||||
|
if (calc.isEditing) {
|
||||||
|
renderEditValue();
|
||||||
|
}
|
||||||
|
updateStackLabels();
|
||||||
updateCopyButtons();
|
updateCopyButtons();
|
||||||
modeButton.textContent = calc.angleMode;
|
modeButton.textContent = calc.angleMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stopEditing(clearValue = false) {
|
||||||
|
if (clearValue) {
|
||||||
|
calc.inputValue = '';
|
||||||
|
}
|
||||||
|
calc.isEditing = false;
|
||||||
|
editCursor = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelEditing() {
|
||||||
|
if (editRestoreValue !== null) {
|
||||||
|
calc.push(editRestoreValue);
|
||||||
|
}
|
||||||
|
editRestoreValue = null;
|
||||||
|
stopEditing(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function enterNavigationMode() {
|
||||||
|
if (calc.isEditing) return;
|
||||||
|
stackMode = 'navigation';
|
||||||
|
stackSelection = 0;
|
||||||
|
stackMoveSnapshot = null;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function exitStackMode() {
|
||||||
|
stackMode = 'normal';
|
||||||
|
stackSelection = 0;
|
||||||
|
stackMoveSnapshot = null;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveNavigationSelection(delta) {
|
||||||
|
const maxIndex = Math.max(0, calc.stack.length - 1);
|
||||||
|
stackSelection = Math.max(0, Math.min(maxIndex, stackSelection + delta));
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function beginStackMove() {
|
||||||
|
stackMode = 'move';
|
||||||
|
stackMoveSnapshot = calc.stack.slice();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreStackMoveSnapshot() {
|
||||||
|
if (!stackMoveSnapshot) return;
|
||||||
|
calc.stack = stackMoveSnapshot.slice();
|
||||||
|
stackMoveSnapshot = null;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateStackMove() {
|
||||||
|
stackMoveSnapshot = null;
|
||||||
|
stackMode = 'normal';
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveSelectedStackValue(delta) {
|
||||||
|
const index = stackSelection;
|
||||||
|
const target = Math.max(0, Math.min(calc.stack.length - 1, index + delta));
|
||||||
|
if (target === index) return;
|
||||||
|
const value = calc.stack.splice(index, 1)[0];
|
||||||
|
calc.stack.splice(target, 0, value);
|
||||||
|
stackSelection = target;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function enterNavigationMode() {
|
||||||
|
if (calc.isEditing) return;
|
||||||
|
stackMode = 'navigation';
|
||||||
|
stackSelection = 0;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function exitStackMode() {
|
||||||
|
stackMode = 'normal';
|
||||||
|
stackSelection = 0;
|
||||||
|
stackMoveSnapshot = null;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveNavigationSelection(delta) {
|
||||||
|
const maxIndex = Math.max(0, calc.stack.length - 1);
|
||||||
|
stackSelection = Math.max(0, Math.min(maxIndex, stackSelection + delta));
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function beginStackMove() {
|
||||||
|
stackMode = 'move';
|
||||||
|
stackMoveSnapshot = calc.stack.slice();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreStackMoveSnapshot() {
|
||||||
|
if (!stackMoveSnapshot) return;
|
||||||
|
calc.stack = stackMoveSnapshot.slice();
|
||||||
|
stackMoveSnapshot = null;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateStackMove() {
|
||||||
|
stackMoveSnapshot = null;
|
||||||
|
stackMode = 'normal';
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveSelectedStackValue(delta) {
|
||||||
|
const index = stackSelection;
|
||||||
|
const target = Math.max(0, Math.min(calc.stack.length - 1, index + delta));
|
||||||
|
if (target === index) return;
|
||||||
|
const value = calc.stack.splice(index, 1)[0];
|
||||||
|
calc.stack.splice(target, 0, value);
|
||||||
|
stackSelection = target;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveEditCursor(delta) {
|
||||||
|
editCursor = Math.max(0, Math.min(calc.inputValue.length, editCursor + delta));
|
||||||
|
}
|
||||||
|
|
||||||
function pushEditingValueIfNeeded() {
|
function pushEditingValueIfNeeded() {
|
||||||
if (!calc.isEditing) return;
|
if (!calc.isEditing) return;
|
||||||
if (calc.inputValue !== '') {
|
if (calc.inputValue !== '') {
|
||||||
calc.push(calc.parseInputValue(calc.inputValue));
|
calc.push(calc.parseInputValue(calc.inputValue));
|
||||||
}
|
}
|
||||||
|
editRestoreValue = null;
|
||||||
calc.inputValue = '';
|
calc.inputValue = '';
|
||||||
calc.isEditing = false;
|
calc.isEditing = false;
|
||||||
|
editCursor = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEditingFromStackTop() {
|
||||||
|
if (!calc.isValidIndex(0)) return false;
|
||||||
|
const value = calc.stack[0];
|
||||||
|
editRestoreValue = value;
|
||||||
|
calc.remove(0);
|
||||||
|
calc.isEditing = true;
|
||||||
|
calc.inputValue = calc.formatNumber(value);
|
||||||
|
editCursor = calc.inputValue.length;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function inputToX(value) {
|
function inputToX(value) {
|
||||||
if (!calc.isEditing) {
|
if (!calc.isEditing) {
|
||||||
calc.isEditing = true;
|
calc.isEditing = true;
|
||||||
calc.inputValue = '';
|
calc.inputValue = '';
|
||||||
|
editCursor = 0;
|
||||||
}
|
}
|
||||||
if (value === 'Backspace') {
|
if (value === 'Backspace') {
|
||||||
calc.inputValue = calc.inputValue.slice(0, -1);
|
if (editCursor > 0) {
|
||||||
|
calc.inputValue = `${calc.inputValue.slice(0, editCursor - 1)}${calc.inputValue.slice(editCursor)}`;
|
||||||
|
editCursor -= 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
calc.inputValue += value;
|
calc.inputValue = `${calc.inputValue.slice(0, editCursor)}${value}${calc.inputValue.slice(editCursor)}`;
|
||||||
|
editCursor += value.length;
|
||||||
}
|
}
|
||||||
if (calc.inputValue === '') {
|
if (calc.inputValue === '') {
|
||||||
calc.isEditing = false;
|
stopEditing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,18 +387,15 @@ function execute(name) {
|
|||||||
}
|
}
|
||||||
} else if (name === 'clear') {
|
} else if (name === 'clear') {
|
||||||
calc.clear();
|
calc.clear();
|
||||||
calc.inputValue = '';
|
stopEditing(true);
|
||||||
calc.isEditing = false;
|
|
||||||
} else if (name === 'escape') {
|
} else if (name === 'escape') {
|
||||||
calc.inputValue = '';
|
cancelEditing();
|
||||||
calc.isEditing = false;
|
|
||||||
} else if (name === 'backspace') {
|
} else if (name === 'backspace') {
|
||||||
if (calc.isEditing) {
|
if (calc.isEditing) {
|
||||||
inputToX('Backspace');
|
inputToX('Backspace');
|
||||||
} else if (calc.isValidIndex(0)) {
|
} else if (calc.isValidIndex(0)) {
|
||||||
calc.remove(0);
|
calc.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (name === 'swap') {
|
} else if (name === 'swap') {
|
||||||
pushEditingValueIfNeeded();
|
pushEditingValueIfNeeded();
|
||||||
if (calc.isValidIndex(1)) {
|
if (calc.isValidIndex(1)) {
|
||||||
@@ -237,35 +403,26 @@ function execute(name) {
|
|||||||
}
|
}
|
||||||
} else if (name === 'neg') {
|
} else if (name === 'neg') {
|
||||||
if (calc.isEditing) {
|
if (calc.isEditing) {
|
||||||
calc.inputValue = calc.inputValue.startsWith('-') ? calc.inputValue.slice(1) : `-${calc.inputValue}`;
|
const hasSign = calc.inputValue.startsWith('-');
|
||||||
|
calc.inputValue = hasSign ? calc.inputValue.slice(1) : `-${calc.inputValue}`;
|
||||||
|
moveEditCursor(hasSign ? -1 : 1);
|
||||||
} else {
|
} else {
|
||||||
calc.push(calc.pop() * -1);
|
calc.command('neg');
|
||||||
}
|
}
|
||||||
} 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 {
|
} else {
|
||||||
pushEditingValueIfNeeded();
|
pushEditingValueIfNeeded();
|
||||||
calc.command(name);
|
calc.command(name);
|
||||||
}
|
}
|
||||||
|
if (!calc.isEditing) {
|
||||||
|
editCursor = 0;
|
||||||
|
}
|
||||||
render();
|
render();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setStatus(error?.message || 'Operation error', true);
|
setStatus(error?.message || 'Operation error', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createKeyButton({ label, input, action, spacer, className }) {
|
function createKeyButton({ label, input, action, spacer, className, title }) {
|
||||||
if (spacer) {
|
if (spacer) {
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
return div;
|
return div;
|
||||||
@@ -274,6 +431,7 @@ function createKeyButton({ label, input, action, spacer, className }) {
|
|||||||
button.type = 'button';
|
button.type = 'button';
|
||||||
button.textContent = label;
|
button.textContent = label;
|
||||||
button.className = className;
|
button.className = className;
|
||||||
|
if (title) button.title = title;
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
if (input) {
|
if (input) {
|
||||||
inputToX(input);
|
inputToX(input);
|
||||||
@@ -304,6 +462,53 @@ async function copyStackValue(label) {
|
|||||||
function handleKeyboard(event) {
|
function handleKeyboard(event) {
|
||||||
if (event.defaultPrevented) return;
|
if (event.defaultPrevented) return;
|
||||||
const key = event.key;
|
const key = event.key;
|
||||||
|
if (stackMode === 'navigation') {
|
||||||
|
if (key === 'ArrowUp') {
|
||||||
|
event.preventDefault();
|
||||||
|
moveNavigationSelection(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'ArrowDown') {
|
||||||
|
event.preventDefault();
|
||||||
|
moveNavigationSelection(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'Escape' || key === 'ArrowLeft') {
|
||||||
|
event.preventDefault();
|
||||||
|
exitStackMode();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
|
beginStackMove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (stackMode === 'move') {
|
||||||
|
if (key === 'ArrowUp') {
|
||||||
|
event.preventDefault();
|
||||||
|
moveSelectedStackValue(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'ArrowDown') {
|
||||||
|
event.preventDefault();
|
||||||
|
moveSelectedStackValue(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'Escape') {
|
||||||
|
event.preventDefault();
|
||||||
|
restoreStackMoveSnapshot();
|
||||||
|
exitStackMode();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
|
validateStackMove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (/^[0-9.]$/.test(key)) {
|
if (/^[0-9.]$/.test(key)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
inputToX(key);
|
inputToX(key);
|
||||||
@@ -321,16 +526,58 @@ function handleKeyboard(event) {
|
|||||||
'/': 'div',
|
'/': 'div',
|
||||||
'%': 'mod',
|
'%': 'mod',
|
||||||
'^': 'pow',
|
'^': 'pow',
|
||||||
|
s: 'sqr',
|
||||||
|
S: 'pow',
|
||||||
|
r: 'sqrt',
|
||||||
|
R: 'root',
|
||||||
|
x: 'recip',
|
||||||
|
d: 'pow10',
|
||||||
|
l: 'log',
|
||||||
|
L: 'log',
|
||||||
|
n: 'ln',
|
||||||
|
N: 'ln',
|
||||||
|
e: 'exp',
|
||||||
|
E: 'exp',
|
||||||
|
i: 'sin',
|
||||||
|
o: 'cos',
|
||||||
|
a: 'tan',
|
||||||
|
I: 'asin',
|
||||||
|
O: 'acos',
|
||||||
|
A: 'atan',
|
||||||
};
|
};
|
||||||
const arrowMap = {
|
if (key === 'ArrowLeft') {
|
||||||
ArrowUp: upButton,
|
|
||||||
ArrowDown: downButton,
|
|
||||||
ArrowLeft: leftButton,
|
|
||||||
ArrowRight: rightButton,
|
|
||||||
};
|
|
||||||
if (arrowMap[key]) {
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
arrowMap[key].click();
|
if (calc.isEditing) {
|
||||||
|
moveEditCursor(-1);
|
||||||
|
render();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
leftButton.click();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'ArrowRight') {
|
||||||
|
event.preventDefault();
|
||||||
|
if (calc.isEditing) {
|
||||||
|
moveEditCursor(1);
|
||||||
|
render();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rightButton.click();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'ArrowUp') {
|
||||||
|
event.preventDefault();
|
||||||
|
upButton.click();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key === 'ArrowDown') {
|
||||||
|
event.preventDefault();
|
||||||
|
if (calc.isEditing) {
|
||||||
|
cancelEditing();
|
||||||
|
render();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
downButton.click();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (map[key]) {
|
if (map[key]) {
|
||||||
@@ -340,41 +587,49 @@ function handleKeyboard(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const modeOptions = ['deg', 'rad', 'grad'];
|
const modeOptions = ['deg', 'rad', 'grad'];
|
||||||
let modeMenuEl = null;
|
let activeMenuEl = null;
|
||||||
|
|
||||||
function closeModeMenu() {
|
function closeModeMenu() {
|
||||||
if (modeMenuEl) {
|
if (activeMenuEl) {
|
||||||
modeMenuEl.remove();
|
activeMenuEl.remove();
|
||||||
modeMenuEl = null;
|
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() {
|
function toggleModeMenu() {
|
||||||
if (modeMenuEl) {
|
if (activeMenuEl) {
|
||||||
closeModeMenu();
|
closeModeMenu();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
closeConstMenu();
|
closeConstMenu();
|
||||||
const rect = modeButton.getBoundingClientRect();
|
activeMenuEl = openMenu(modeButton, modeOptions.map((mode) => ({
|
||||||
modeMenuEl = document.createElement('div');
|
label: mode,
|
||||||
modeMenuEl.className = 'mode-menu';
|
value: mode,
|
||||||
modeMenuEl.style.top = `${rect.bottom + 6 + window.scrollY}px`;
|
active: mode === calc.angleMode,
|
||||||
modeOptions.forEach((mode) => {
|
})), (mode) => {
|
||||||
const button = document.createElement('button');
|
calc.angleMode = mode;
|
||||||
button.type = 'button';
|
render();
|
||||||
button.className = `mode-menu-item${mode === calc.angleMode ? ' is-active' : ''}`;
|
closeModeMenu();
|
||||||
button.textContent = mode;
|
|
||||||
button.addEventListener('click', () => {
|
|
||||||
calc.angleMode = mode;
|
|
||||||
render();
|
|
||||||
closeModeMenu();
|
|
||||||
});
|
|
||||||
modeMenuEl.appendChild(button);
|
|
||||||
});
|
});
|
||||||
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) => {
|
modeButton.addEventListener('click', (event) => {
|
||||||
@@ -385,6 +640,7 @@ modeButton.addEventListener('click', (event) => {
|
|||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => {
|
||||||
closeModeMenu();
|
closeModeMenu();
|
||||||
closeConstMenu();
|
closeConstMenu();
|
||||||
|
render();
|
||||||
});
|
});
|
||||||
window.addEventListener('scroll', () => {
|
window.addEventListener('scroll', () => {
|
||||||
closeModeMenu();
|
closeModeMenu();
|
||||||
@@ -398,10 +654,8 @@ window.addEventListener('click', (event) => {
|
|||||||
if (label) copyStackValue(label);
|
if (label) copyStackValue(label);
|
||||||
return;
|
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();
|
closeModeMenu();
|
||||||
}
|
|
||||||
if (constMenuEl && !event.target.closest('.mode-menu') && event.target !== constButton) {
|
|
||||||
closeConstMenu();
|
closeConstMenu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -422,54 +676,50 @@ hiddenInput.addEventListener('paste', (event) => {
|
|||||||
pasteTextIntoStack(text);
|
pasteTextIntoStack(text);
|
||||||
});
|
});
|
||||||
|
|
||||||
upButton.addEventListener('click', () => {});
|
upButton.addEventListener('click', () => {
|
||||||
|
if (!calc.isEditing && stackMode === 'normal') {
|
||||||
|
enterNavigationMode();
|
||||||
|
focusInput();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const constants = [
|
const constantLabels = {
|
||||||
{ label: 'π', value: Math.PI },
|
pi: 'π',
|
||||||
{ label: 'e', value: Math.E },
|
e: 'e',
|
||||||
{ label: 'φ', value: (1 + Math.sqrt(5)) / 2 },
|
phi: 'φ',
|
||||||
{ label: 'g', value: 9.80665 },
|
g: 'g',
|
||||||
{ label: 'c', value: 299792458 },
|
c: 'C',
|
||||||
];
|
};
|
||||||
|
const constantOrder = ['pi', 'e', 'phi', 'g', 'c'];
|
||||||
|
|
||||||
let constMenuEl = null;
|
|
||||||
|
|
||||||
function closeConstMenu() {
|
function closeConstMenu() {
|
||||||
if (constMenuEl) {
|
if (activeMenuEl) {
|
||||||
constMenuEl.remove();
|
activeMenuEl.remove();
|
||||||
constMenuEl = null;
|
activeMenuEl = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleConstMenu() {
|
function toggleConstMenu() {
|
||||||
if (constMenuEl) {
|
if (activeMenuEl) {
|
||||||
closeConstMenu();
|
closeConstMenu();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
closeModeMenu();
|
closeModeMenu();
|
||||||
const rect = constButton.getBoundingClientRect();
|
const availableConstants = calc.listConstants();
|
||||||
constMenuEl = document.createElement('div');
|
const keys = [...constantOrder, ...Object.keys(availableConstants).filter((name) => !constantOrder.includes(name))]
|
||||||
constMenuEl.className = 'mode-menu';
|
.filter((name) => Object.prototype.hasOwnProperty.call(availableConstants, name));
|
||||||
constMenuEl.style.top = `${rect.bottom + 6 + window.scrollY}px`;
|
activeMenuEl = openMenu(constButton, keys.map((name) => ({
|
||||||
constants.forEach((constant) => {
|
label: constantLabels[name] ?? name,
|
||||||
const button = document.createElement('button');
|
value: name,
|
||||||
button.type = 'button';
|
})), (name) => {
|
||||||
button.className = 'mode-menu-item';
|
pushEditingValueIfNeeded();
|
||||||
button.textContent = constant.label;
|
calc.push(availableConstants[name]);
|
||||||
button.addEventListener('click', () => {
|
render();
|
||||||
pushEditingValueIfNeeded();
|
clearStatus();
|
||||||
calc.push(constant.value);
|
closeConstMenu();
|
||||||
render();
|
focusInput();
|
||||||
clearStatus();
|
|
||||||
closeConstMenu();
|
|
||||||
focusInput();
|
|
||||||
});
|
|
||||||
constMenuEl.appendChild(button);
|
|
||||||
});
|
});
|
||||||
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) => {
|
constButton.addEventListener('click', (event) => {
|
||||||
@@ -477,32 +727,43 @@ constButton.addEventListener('click', (event) => {
|
|||||||
toggleConstMenu();
|
toggleConstMenu();
|
||||||
});
|
});
|
||||||
|
|
||||||
leftButton.addEventListener('click', () => {});
|
leftButton.addEventListener('click', () => {
|
||||||
|
if (calc.isEditing) {
|
||||||
|
moveEditCursor(-1);
|
||||||
|
render();
|
||||||
|
focusInput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (stackMode === 'navigation') {
|
||||||
|
exitStackMode();
|
||||||
|
focusInput();
|
||||||
|
}
|
||||||
|
});
|
||||||
downButton.addEventListener('click', () => {
|
downButton.addEventListener('click', () => {
|
||||||
if (!calc.isEditing && calc.isValidIndex(0)) {
|
if (!calc.isEditing && startEditingFromStackTop()) {
|
||||||
const value = calc.stack[0];
|
|
||||||
calc.remove(0);
|
|
||||||
calc.isEditing = true;
|
|
||||||
calc.inputValue = calc.formatNumber(value);
|
|
||||||
render();
|
render();
|
||||||
focusInput();
|
focusInput();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
rightButton.addEventListener('click', () => {
|
rightButton.addEventListener('click', () => {
|
||||||
|
if (calc.isEditing) {
|
||||||
|
moveEditCursor(1);
|
||||||
|
render();
|
||||||
|
focusInput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
execute('swap');
|
execute('swap');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener('keydown', handleKeyboard, { capture: true });
|
window.addEventListener('keydown', handleKeyboard, { capture: true });
|
||||||
window.addEventListener('load', focusInput);
|
window.addEventListener('load', focusInput);
|
||||||
window.addEventListener('pageshow', focusInput);
|
window.addEventListener('pageshow', focusInput);
|
||||||
window.addEventListener('focus', focusInput);
|
window.addEventListener('focus', focusInput);
|
||||||
window.addEventListener('pointerdown', focusInput, true);
|
window.addEventListener('pointerdown', focusInput, true);
|
||||||
window.addEventListener('mousedown', focusInput, true);
|
window.addEventListener('mousedown', focusInput, true);
|
||||||
window.addEventListener('click', focusInput, true);
|
|
||||||
|
|
||||||
hiddenInput.setAttribute('inputmode', 'none');
|
hiddenInput.setAttribute('inputmode', 'none');
|
||||||
hiddenInput.setAttribute('readonly', 'readonly');
|
hiddenInput.setAttribute('readonly', 'readonly');
|
||||||
@@ -517,7 +778,7 @@ hiddenInput.addEventListener('focus', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('click', (event) => {
|
document.addEventListener('click', (event) => {
|
||||||
if (!isTouchDevice && !event.target.closest('.mode-menu')) {
|
if (!isTouchDevice && !event.target.closest('.menu-popup')) {
|
||||||
focusInput();
|
focusInput();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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,26 +1,52 @@
|
|||||||
|
# Calc 02 Visual Portrait
|
||||||
|
|
||||||
|
## Display
|
||||||
|
|
||||||
|
```
|
||||||
┌──────────── Display ────────────┐
|
┌──────────── Display ────────────┐
|
||||||
| T: |
|
| T: |
|
||||||
| Z: |
|
| Z: |
|
||||||
| Y: |
|
| Y: |
|
||||||
| X: |
|
| X: |
|
||||||
└─────────────────────────────────┘
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## Display Buttons
|
||||||
|
|
||||||
|
```
|
||||||
┌──────── Display Buttons ────────┐
|
┌──────── Display Buttons ────────┐
|
||||||
| Mode | Paste | Up | Const |
|
| Const | Paste | Up | Mode |
|
||||||
| | Right | Down | Right |
|
| | Left | Down | Right |
|
||||||
└─────────────────────────────────┘
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## Keypad
|
||||||
|
|
||||||
|
```
|
||||||
┌──────────── Keypad ─────────────┐
|
┌──────────── Keypad ─────────────┐
|
||||||
| +/- | Clear | Esc | backspace |
|
| Clear | Backspace | Esc | Enter |
|
||||||
| 7 | 8 | 9 | / |
|
| 7 | 8 | 9 | / |
|
||||||
| 4 | 5 | 6 | * |
|
| 4 | 5 | 6 | * |
|
||||||
| 1 | 2 | 3 | - |
|
| 1 | 2 | 3 | - |
|
||||||
| 0 | . | Enter | + |
|
| 0 | . | +/- | + |
|
||||||
└─────────────────────────────────┘
|
└─────────────────────────────────┘
|
||||||
┌─────────── Functions ───────────┐
|
```
|
||||||
| x^2 | y^x | 1/x | % |
|
|
||||||
| √x | y√x | 10^x | |
|
## Functions
|
||||||
| log | ln | | |
|
|
||||||
|
```
|
||||||
|
┌──────────── Functions ──────────┐
|
||||||
|
| x^2 | √x | 1/x | % |
|
||||||
|
| y^x | y√x | 10^x | |
|
||||||
|
| log | ln | e^x | |
|
||||||
└─────────────────────────────────┘
|
└─────────────────────────────────┘
|
||||||
┌───────────── Trigo ─────────────┐
|
```
|
||||||
| sin | cos | tan | |
|
|
||||||
| asin | acos | atan | |
|
## Trigo
|
||||||
|
|
||||||
|
```
|
||||||
|
┌──────────── Trigo ──────────────┐
|
||||||
|
| sin | cos | tan | |
|
||||||
|
| asin | acos | atan | |
|
||||||
└─────────────────────────────────┘
|
└─────────────────────────────────┘
|
||||||
|
```
|
||||||
+68
-1
@@ -2,6 +2,9 @@ class RpnCalculator {
|
|||||||
static CONSTANTS = {
|
static CONSTANTS = {
|
||||||
pi: Math.PI,
|
pi: Math.PI,
|
||||||
e: Math.E,
|
e: Math.E,
|
||||||
|
phi: (1 + Math.sqrt(5)) / 2,
|
||||||
|
g: 9.80665,
|
||||||
|
c: 299792458,
|
||||||
};
|
};
|
||||||
|
|
||||||
static OPERATIONS = {
|
static OPERATIONS = {
|
||||||
@@ -46,6 +49,18 @@ class RpnCalculator {
|
|||||||
aliases: ['^', 'y^x'],
|
aliases: ['^', 'y^x'],
|
||||||
execute: (calc, a, b) => Math.pow(a, b),
|
execute: (calc, a, b) => Math.pow(a, b),
|
||||||
},
|
},
|
||||||
|
pow10: {
|
||||||
|
category: 'Arithmetic',
|
||||||
|
argCount: 1,
|
||||||
|
aliases: ['10^x'],
|
||||||
|
execute: (calc, a) => Math.pow(10, a),
|
||||||
|
},
|
||||||
|
exp: {
|
||||||
|
category: 'Arithmetic',
|
||||||
|
argCount: 1,
|
||||||
|
aliases: ['e^x'],
|
||||||
|
execute: (calc, a) => Math.exp(a),
|
||||||
|
},
|
||||||
root: {
|
root: {
|
||||||
category: 'Arithmetic',
|
category: 'Arithmetic',
|
||||||
argCount: 2,
|
argCount: 2,
|
||||||
@@ -192,7 +207,7 @@ class RpnCalculator {
|
|||||||
static getOperationsByCategory() {
|
static getOperationsByCategory() {
|
||||||
return {
|
return {
|
||||||
Stack: ['dup', 'drop', 'swap', 'clear', 'enter'],
|
Stack: ['dup', 'drop', 'swap', 'clear', 'enter'],
|
||||||
Arithmetic: ['add', 'sub', 'mul', 'div', 'mod', 'pow', 'root', 'sqr', 'neg', 'sqrt', 'recip', 'log', 'ln'],
|
Arithmetic: ['add', 'sub', 'mul', 'div', 'mod', 'pow', 'pow10', 'exp', 'root', 'sqr', 'neg', 'sqrt', 'recip', 'log', 'ln'],
|
||||||
Trigonometry: ['sin', 'cos', 'tan', 'asin', 'acos', 'atan'],
|
Trigonometry: ['sin', 'cos', 'tan', 'asin', 'acos', 'atan'],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -212,6 +227,15 @@ class RpnCalculator {
|
|||||||
this.enabledCommands = new Set(selectedCommands.map((name) => this.normalizeCommandName(name)).filter((name) => RpnCalculator.OPERATIONS[name]));
|
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) {
|
toRadians(value) {
|
||||||
if (this.angleMode === 'grad') {
|
if (this.angleMode === 'grad') {
|
||||||
return (value * Math.PI) / 200;
|
return (value * Math.PI) / 200;
|
||||||
@@ -257,6 +281,45 @@ class RpnCalculator {
|
|||||||
return typeof name === 'string' && Object.prototype.hasOwnProperty.call(this.constants, name.toLowerCase());
|
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) {
|
push(value) {
|
||||||
if (this.stack.length >= this.maxSize) {
|
if (this.stack.length >= this.maxSize) {
|
||||||
throw new Error('Stack overflow');
|
throw new Error('Stack overflow');
|
||||||
@@ -408,6 +471,10 @@ class RpnCalculator {
|
|||||||
getConstants() {
|
getConstants() {
|
||||||
return { ...this.constants };
|
return { ...this.constants };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listConstants() {
|
||||||
|
return this.getConstants();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
|||||||
Reference in New Issue
Block a user