Skip to content

Commit 9b7a833

Browse files
committed
final touches
1 parent 3512766 commit 9b7a833

File tree

6 files changed

+158
-41
lines changed

6 files changed

+158
-41
lines changed

.github/workflows/pipeline.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Balanced ternary to decimal pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
jobs:
10+
build:
11+
name: Build and Test
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: '18'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Build Astro project
28+
run: npm run build
29+
30+
- name: Cache build output
31+
uses: actions/cache@v3
32+
with:
33+
path: dist
34+
key: ${{ runner.os }}-astro-build-${{ github.sha }}
35+
36+
deploy:
37+
name: Deploy
38+
needs: build
39+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v3
45+
46+
- name: Setup Node.js
47+
uses: actions/setup-node@v3
48+
with:
49+
node-version: '18'
50+
cache: 'npm'
51+
52+
- name: Restore cached build
53+
uses: actions/cache@v3
54+
with:
55+
path: dist
56+
key: ${{ runner.os }}-astro-build-${{ github.sha }}
57+
58+
- name: Deploy to GitHub Pages
59+
uses: JamesIves/github-pages-deploy-action@v4
60+
with:
61+
folder: dist
62+
branch: gh-pages

README.md

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
1-
# Astro Starter Kit: Minimal
1+
<meta name="description" content="Decimal ↔ Balanced Ternary Converter" />
22

3-
```sh
4-
npm create astro@latest -- --template minimal
5-
```
3+
# 🔁 Balanced Ternary Converter
64

7-
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/minimal)
8-
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/minimal)
9-
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/minimal/devcontainer.json)
5+
Convert between Decimal and Balanced Ternary numbers — instantly and at scale.
106

11-
> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
7+
## 🌐 Live Demo
128

13-
## 🚀 Project Structure
9+
👉 [Use the tool in your browser](https://github.com/VBproDev/decimal-to-balanced-ternary-converter)
1410

15-
Inside of your Astro project, you'll see the following folders and files:
11+
---
1612

17-
```text
18-
/
19-
├── public/
20-
├── src/
21-
│ └── pages/
22-
│ └── index.astro
23-
└── package.json
24-
```
13+
## 🧮 Features
2514

26-
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
15+
- 🔢 Convert individual numbers between Decimal and Balanced Ternary.
16+
- 📈 Bulk convert ranges — e.g., `1,1000` or `T0,1T1`.
17+
- 🧵 Powered by Web Workers to handle large datasets smoothly without freezing the UI.
18+
- 📋 Clipboard support for small outputs.
19+
- 📄 Automatic .txt file download for large outputs (over 100,000 numbers).
20+
- 📱 Responsive layout with accessibility-first design.
21+
- ✅ Tested with bulk conversion of up to 21 million numbers. The tool may handle more numbers, you can help by testing the limits
2722

28-
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
23+
---
2924

30-
Any static assets, like images, can be placed in the `public/` directory.
25+
## 🧾 Input Format
3126

32-
## 🧞 Commands
27+
| Type | Format Example | Notes |
28+
|-----------|------------------|--------------------------------------------|
29+
| Single | `25` or `T10` | A single number |
30+
| Range | `1,1000` or `T0,1T1` | Inclusive range, e.g., from 1 to 1000 |
3331

34-
All commands are run from the root of the project, from a terminal:
32+
When using Balanced Ternary, the digit '-1' is represented by `T`.
3533

36-
| Command | Action |
37-
| :------------------------ | :----------------------------------------------- |
38-
| `npm install` | Installs dependencies |
39-
| `npm run dev` | Starts local dev server at `localhost:4321` |
40-
| `npm run build` | Build your production site to `./dist/` |
41-
| `npm run preview` | Preview your build locally, before deploying |
42-
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
43-
| `npm run astro -- --help` | Get help using the Astro CLI |
34+
---
4435

45-
## 👀 Want to learn more?
36+
## 📤 Output Options
4637

47-
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
38+
- Up to 100,000 values: Copy directly to clipboard.
39+
- Over 100,000 values: Download as a `.txt` file.
40+
41+
---
42+
43+
## 🚀 Tech Stack
44+
45+
- HTML, SCSS
46+
- TypeScript
47+
- Web Workers
48+
- Accessible, semantic markup
49+
50+
---
51+
52+
## 🌟 Support the Project
53+
54+
If you found this tool helpful, consider giving it a ⭐! It really motivates us to do more
55+
56+
---

astro.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
import { defineConfig } from 'astro/config';
33

44
// https://astro.build/config
5-
export default defineConfig({});
5+
export default defineConfig({
6+
site: 'https://vbprodev.github.io',
7+
base: '/decimal-and-balanced-ternary-converter',
8+
});

src/pages/index.astro

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ import "../styles/stylesheet.scss";
8181
<h2 class="copy-btn" role="button" tabindex="0" aria-label="Copy results">
8282
📋
8383
</h2>
84+
<h2
85+
class="download-btn"
86+
role="button"
87+
tabindex="0"
88+
aria-label="Downloadresults"
89+
>
90+
⬇️
91+
</h2>
8492
</div>
8593
</div>
8694
<textarea readonly tabindex="-1" class="conversion-result"></textarea>
@@ -90,7 +98,7 @@ import "../styles/stylesheet.scss";
9098
<footer>
9199
Consider starring ⭐ us on <a
92100
target="_blank"
93-
href="https://github.com/VBproDev/balanced-ternary-and-decimal-converter"
101+
href="https://github.com/VBproDev/decimal-and-balanced-ternary-converter"
94102
>Github!</a
95103
>
96104
<p>

src/scripts/script.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const base = document.querySelector(".numeric-base-select")!;
88
const outputArea = document.querySelector(".conversion-result")!;
99
const errorBanner = document.getElementById("error-banner")!;
1010
const convertBtn = document.querySelector(".convert-btn")!;
11-
const copyBtn = document.querySelector(".copy-icon-container")!;
11+
const copyBtn = document.querySelector(".copy-btn")!;
1212
const successBanner = document.getElementById("success-banner")!;
13+
const downloadBtn = document.querySelector(".download-btn")!;
1314

1415
function setLoadingUI() {
1516
successBanner.setAttribute("aria-live", "polite");
@@ -63,7 +64,7 @@ async function convertBtnHandler() {
6364
if (/\d+,\d+/.test(n)) {
6465
const range = n.split(',').map(x => Number(x)).sort((a, b) => a - b);
6566

66-
if (range[1] - range[0] > 500000) {
67+
if (range[1] - range[0] > 150000) {
6768

6869
setLoadingUI();
6970

@@ -129,6 +130,17 @@ function copyResults() {
129130
successHandling("Copied to clipboard!");
130131
}
131132

133+
function downloadResults() {
134+
const url = URL.createObjectURL(new Blob([outputArea.innerHTML], { type: "text/plain" }));
135+
const a = document.createElement("a");
136+
a.href = url;
137+
a.download = 'results.txt';
138+
document.body.appendChild(a);
139+
a.click();
140+
document.body.removeChild(a);
141+
URL.revokeObjectURL(url)
142+
}
143+
132144
convertBtn.addEventListener("click", () => convertBtnHandler());
133145
convertBtn.addEventListener("keydown", (event) => {
134146

@@ -138,9 +150,21 @@ convertBtn.addEventListener("keydown", (event) => {
138150

139151
});
140152

141-
copyBtn.addEventListener("click", copyResults);
153+
copyBtn.addEventListener("click", () => {
154+
155+
if (outputArea.innerHTML.length > 500000) {
156+
raiseError("Output this large can only be downloaded!", `Output is ${outputArea.innerHTML.length} characters long. The program has identified the output as too large to be copied to the clipboard.`);
157+
}
158+
159+
copyResults();
160+
});
161+
142162
copyBtn.addEventListener("keydown", (event: Event) => {
143163

164+
if (outputArea.innerHTML.length > 500000) {
165+
raiseError("Output this large can only be downloaded!", `Output is ${outputArea.innerHTML.length} characters long. The program has identified the output as too large to be copied to the clipboard.`);
166+
}
167+
144168
if ((event as KeyboardEvent).key === 'Enter' || (event as KeyboardEvent).key === ' ') {
145169
copyResults();
146170
}
@@ -150,4 +174,14 @@ copyBtn.addEventListener("keydown", (event: Event) => {
150174
base.addEventListener("change", (e) => {
151175
if ((base as HTMLInputElement).value.toLowerCase() === "balanced-ternary") num.placeholder = "Enter decimal";
152176
else num.placeholder = "Enter balanced ternary";
177+
});
178+
179+
downloadBtn.addEventListener("click", downloadResults)
180+
181+
downloadBtn.addEventListener("keydown", (event: Event) => {
182+
183+
if ((event as KeyboardEvent).key === 'Enter' || (event as KeyboardEvent).key === ' ') {
184+
downloadResults();
185+
}
186+
153187
});

src/styles/stylesheet.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $text-color: #2C2C2C;
44
$border-radius: 0.5rem;
55
$box-shadow: $text-color 0 1px 0;
66
$green-color: #207235;
7+
$margin: clamp(2%, 1rem, 3%);
78

89
%base-styles {
910
box-sizing: border-box;
@@ -14,7 +15,7 @@ $green-color: #207235;
1415
%base-input-styles {
1516
@extend %base-styles;
1617
width: 8rem;
17-
margin: 1rem;
18+
margin: $margin;
1819
line-height: 1.5rem;
1920
}
2021

@@ -87,7 +88,7 @@ $green-color: #207235;
8788
width: clamp(10rem, 90%, 30rem);
8889
background-color: $text-color;
8990
height: 15rem;
90-
margin: 1rem;
91+
margin: $margin;
9192
}
9293

9394
.conversion-result {
@@ -117,7 +118,7 @@ $green-color: #207235;
117118
align-items: center;
118119
text-align: center;
119120
background-color: #ced4da;
120-
width: 2rem;
121+
width: 4rem;
121122
height: 2rem;
122123
}
123124

0 commit comments

Comments
 (0)