mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-20 21:23:10 +03:00
Built IP calculations, conversions and visualisations
This commit is contained in:
commit
94941fdaec
34 files changed
+7653
No files matched your search
+23
@@ -0,0 +1,23 @@
|
||||
node_modules
|
||||
|
||||
# Output
|
||||
.output
|
||||
.vercel
|
||||
.netlify
|
||||
.wrangler
|
||||
/.svelte-kit
|
||||
/build
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.test
|
||||
|
||||
# Vite
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
@@ -0,0 +1,172 @@
|
||||
# IP Calc - Advanced IP Address Calculator
|
||||
|
||||
A comprehensive, modern web application for IP address calculations, subnet analysis, and network planning. Built with SvelteKit and Tailwind CSS.
|
||||
|
||||

|
||||
|
||||
## ✨ Features
|
||||
|
||||
### 🔢 Subnet Calculator
|
||||
- **Comprehensive subnet analysis** with network, broadcast, and host calculations
|
||||
- **Visual network topology** with interactive address range visualization
|
||||
- **Binary representation** of subnet masks and addresses
|
||||
- **Efficiency metrics** showing address utilization
|
||||
|
||||
### 🔄 CIDR Converter
|
||||
- **Bidirectional conversion** between CIDR notation and subnet masks
|
||||
- **Interactive slider** for easy CIDR selection
|
||||
- **Common subnet presets** with usage recommendations
|
||||
- **Real-time validation** with helpful error messages
|
||||
|
||||
### 🔀 IP Address Converter
|
||||
- **Multi-format support**: Decimal, Binary, Hexadecimal, and Octal
|
||||
- **IP class detection** with automatic classification
|
||||
- **Live conversion** as you type
|
||||
- **Copy-to-clipboard** functionality for easy sharing
|
||||
|
||||
### 📚 Network Reference
|
||||
- **Network classes** (A, B, C) with detailed information
|
||||
- **Reserved IP ranges** (RFC compliance)
|
||||
- **Common subnet tables** with usage scenarios
|
||||
- **Pro tips** for network planning
|
||||
|
||||
## 🚀 Technologies Used
|
||||
|
||||
- **SvelteKit** - Modern, fast web framework
|
||||
- **TypeScript** - Type-safe development
|
||||
- **Tailwind CSS** - Utility-first styling
|
||||
- **Vite** - Lightning-fast build tool
|
||||
|
||||
## 🛠️ Installation & Setup
|
||||
|
||||
### Prerequisites
|
||||
- Node.js v22.12.0 or higher
|
||||
- npm v10.0.0 or higher
|
||||
|
||||
### Quick Start
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone <repository-url>
|
||||
cd ip-calc
|
||||
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Start development server
|
||||
npm run dev
|
||||
|
||||
# Open http://localhost:5173 in your browser
|
||||
```
|
||||
|
||||
### Building for Production
|
||||
|
||||
```bash
|
||||
# Build the application
|
||||
npm run build
|
||||
|
||||
# Preview production build
|
||||
npm run preview
|
||||
```
|
||||
|
||||
## 📁 Project Structure
|
||||
|
||||
```
|
||||
ip-calc/
|
||||
├── src/
|
||||
│ ├── lib/
|
||||
│ │ ├── components/ # Reusable Svelte components
|
||||
│ │ │ ├── IPInput.svelte
|
||||
│ │ │ ├── CIDRInput.svelte
|
||||
│ │ │ ├── SubnetCalculator.svelte
|
||||
│ │ │ ├── CIDRConverter.svelte
|
||||
│ │ │ ├── IPConverter.svelte
|
||||
│ │ │ ├── NetworkVisualizer.svelte
|
||||
│ │ │ └── InfoPanel.svelte
|
||||
│ │ ├── utils/ # Utility functions
|
||||
│ │ │ ├── ip-validation.ts
|
||||
│ │ │ ├── ip-calculations.ts
|
||||
│ │ │ └── ip-conversions.ts
|
||||
│ │ ├── constants/ # Network constants
|
||||
│ │ │ └── networks.ts
|
||||
│ │ └── types/ # TypeScript definitions
|
||||
│ │ └── ip.ts
|
||||
│ ├── routes/ # SvelteKit routes
|
||||
│ │ ├── +layout.svelte
|
||||
│ │ └── +page.svelte
|
||||
│ └── app.css # Global styles
|
||||
├── static/ # Static assets
|
||||
├── tailwind.config.js # Tailwind configuration
|
||||
└── package.json # Project dependencies
|
||||
```
|
||||
|
||||
## 🎯 Key Features in Detail
|
||||
|
||||
### Modular Architecture
|
||||
- **Short, focused functions** with clear responsibilities
|
||||
- **Reusable components** following DRY principles
|
||||
- **Type-safe** development with comprehensive TypeScript coverage
|
||||
- **Clean separation** of concerns between utilities, components, and presentation
|
||||
|
||||
### User Experience
|
||||
- **Dark/Light mode** with system preference detection
|
||||
- **Responsive design** that works on all devices
|
||||
- **Smooth animations** and transitions
|
||||
- **Accessibility-first** design with ARIA labels and keyboard navigation
|
||||
- **Real-time validation** with helpful error messages
|
||||
|
||||
### Performance Optimizations
|
||||
- **Lazy loading** of calculations and visualizations
|
||||
- **Efficient reactivity** with Svelte's reactive statements
|
||||
- **Minimal bundle size** with tree-shaking
|
||||
- **Fast development** with Vite's HMR
|
||||
|
||||
### Network Analysis Tools
|
||||
- **Visual subnet representation** with color-coded address ranges
|
||||
- **Binary mask breakdown** showing network vs host bits
|
||||
- **Address utilization metrics** for efficiency analysis
|
||||
- **RFC-compliant** reserved range detection
|
||||
|
||||
## 🔧 Development Scripts
|
||||
|
||||
```bash
|
||||
# Development
|
||||
npm run dev # Start dev server
|
||||
npm run build # Build for production
|
||||
npm run preview # Preview production build
|
||||
|
||||
# Code Quality
|
||||
npm run check # Type checking
|
||||
npm run lint # ESLint (if configured)
|
||||
npm run format # Prettier formatting
|
||||
```
|
||||
|
||||
## 📊 Browser Support
|
||||
|
||||
- **Chrome** 90+
|
||||
- **Firefox** 88+
|
||||
- **Safari** 14+
|
||||
- **Edge** 90+
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
||||
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
||||
4. Push to the branch (`git push origin feature/amazing-feature`)
|
||||
5. Open a Pull Request
|
||||
|
||||
## 📝 License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
## 🙏 Acknowledgments
|
||||
|
||||
- Network constants and standards from various RFCs
|
||||
- Color schemes inspired by modern design systems
|
||||
- Typography using Inter and Fira Code fonts
|
||||
- Icons from Heroicons and Lucide
|
||||
|
||||
---
|
||||
|
||||
**Built with ❤️ for network engineers, developers, and IT professionals**
|
||||
Generated
+2508
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "ip-calc",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^6.0.0",
|
||||
"@sveltejs/kit": "^2.22.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^6.0.0",
|
||||
"@tailwindcss/forms": "^0.5.10",
|
||||
"@tailwindcss/postcss": "^4.1.12",
|
||||
"@tailwindcss/typography": "^0.5.16",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"lucide-svelte": "^0.542.0",
|
||||
"svelte": "^5.0.0",
|
||||
"svelte-check": "^4.0.0",
|
||||
"tailwindcss": "^4.1.12",
|
||||
"typescript": "^5.0.0",
|
||||
"vite": "^7.0.4"
|
||||
},
|
||||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
||||
}
|
||||
+640
@@ -0,0 +1,640 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;400;500;600;700&display=swap');
|
||||
|
||||
/* Theme Colors */
|
||||
:root {
|
||||
/* Background colors */
|
||||
--bg-primary: #0d1117;
|
||||
--bg-secondary: #161b22;
|
||||
--bg-tertiary: #21262d;
|
||||
|
||||
/* Text colors */
|
||||
--text-primary: #c9d1d9;
|
||||
--text-secondary: #7d8590;
|
||||
|
||||
/* Primary brand color */
|
||||
--color-primary: #dbf465;
|
||||
--color-primary-hover: #c5e146;
|
||||
--color-primary-dark: #a8c237;
|
||||
|
||||
/* Action colors */
|
||||
--color-success: #238636;
|
||||
--color-success-light: #2ea043;
|
||||
--color-warning: #d29922;
|
||||
--color-warning-light: #fb8500;
|
||||
--color-error: #da3633;
|
||||
--color-error-light: #f85149;
|
||||
--color-info: #0969da;
|
||||
--color-info-light: #1f6feb;
|
||||
|
||||
/* Border and surface colors */
|
||||
--border-primary: #30363d;
|
||||
--border-secondary: #21262d;
|
||||
--surface-hover: #262c36;
|
||||
--surface-active: #2f3640;
|
||||
|
||||
/* Shadows */
|
||||
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
|
||||
--shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
|
||||
--shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
|
||||
|
||||
/* Border radius */
|
||||
--radius-sm: 4px;
|
||||
--radius-md: 6px;
|
||||
--radius-lg: 8px;
|
||||
|
||||
/* Spacing */
|
||||
--spacing-xs: 0.25rem;
|
||||
--spacing-sm: 0.5rem;
|
||||
--spacing-md: 1rem;
|
||||
--spacing-lg: 1.5rem;
|
||||
--spacing-xl: 2rem;
|
||||
|
||||
/* Font */
|
||||
--font-mono: 'Roboto Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
|
||||
--font-size-xs: 0.75rem;
|
||||
--font-size-sm: 0.875rem;
|
||||
--font-size-md: 1rem;
|
||||
--font-size-lg: 1.125rem;
|
||||
--font-size-xl: 1.25rem;
|
||||
--font-size-2xl: 1.5rem;
|
||||
|
||||
/* Transitions */
|
||||
--transition-fast: 0.15s ease;
|
||||
--transition-normal: 0.2s ease;
|
||||
--transition-slow: 0.3s ease;
|
||||
}
|
||||
|
||||
/* Light theme */
|
||||
.theme-light {
|
||||
--bg-primary: #ffffff;
|
||||
--bg-secondary: #f6f8fa;
|
||||
--bg-tertiary: #f0f2f5;
|
||||
--text-primary: #24292f;
|
||||
--text-secondary: #656d76;
|
||||
--border-primary: #d1d9e0;
|
||||
--border-secondary: #d8dee4;
|
||||
--surface-hover: #f3f4f6;
|
||||
--surface-active: #e5e7ea;
|
||||
}
|
||||
|
||||
/* Reset */
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 16px;
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
line-height: 1.5;
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-primary);
|
||||
transition: background-color var(--transition-normal), color var(--transition-normal);
|
||||
}
|
||||
|
||||
/* Typography */
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
h1 { font-size: var(--font-size-2xl); }
|
||||
h2 { font-size: var(--font-size-xl); }
|
||||
h3 { font-size: var(--font-size-lg); }
|
||||
|
||||
p {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
/* Form elements */
|
||||
input, select, textarea {
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
transition: all var(--transition-fast);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
input:focus, select:focus, textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 2px rgba(219, 244, 101, 0.2);
|
||||
}
|
||||
|
||||
input::placeholder {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
button {
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
transition: all var(--transition-fast);
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-primary);
|
||||
}
|
||||
|
||||
button:hover:not(:disabled) {
|
||||
background-color: var(--surface-hover);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
button.btn-primary {
|
||||
background-color: var(--color-primary);
|
||||
color: var(--bg-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
button.btn-icon {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
button.btn-icon svg {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
|
||||
/* Labels */
|
||||
label {
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Code */
|
||||
code, pre {
|
||||
font-family: var(--font-mono);
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
/* Layout */
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 var(--spacing-md);
|
||||
}
|
||||
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
|
||||
}
|
||||
|
||||
.main-content {
|
||||
padding: var(--spacing-lg) 0;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
.header {
|
||||
background-color: var(--bg-secondary);
|
||||
border-bottom: 1px solid var(--border-primary);
|
||||
padding: var(--spacing-md) 0;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.logo-icon {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
|
||||
border-radius: var(--radius-md);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.logo-icon svg {
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
color: var(--bg-primary);
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
font-size: var(--font-size-xl);
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Cards */
|
||||
.card {
|
||||
background-color: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-lg);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
.card-header h2 {
|
||||
font-size: var(--font-size-lg);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.card-header p {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Tabs */
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: var(--spacing-xs);
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-xs);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.tab {
|
||||
flex: 1;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border-radius: var(--radius-md);
|
||||
text-align: center;
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--color-primary);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
/* Form groups */
|
||||
.form-group {
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
/* Grid layouts */
|
||||
.grid {
|
||||
display: grid;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.grid-2 {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.grid-3 {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
.grid-4 {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.grid-2, .grid-3, .grid-4 {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Info panels */
|
||||
.info-panel {
|
||||
background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
/* Loading */
|
||||
.loading {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
border: 2px solid var(--border-primary);
|
||||
border-top: 2px solid var(--color-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(0.5rem);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.fade-in {
|
||||
animation: fadeIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
/* Theme toggle */
|
||||
.theme-toggle {
|
||||
position: relative;
|
||||
width: 3rem;
|
||||
height: 1.5rem;
|
||||
background-color: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: 0.75rem;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.toggle-slider {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
left: 1px;
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
background-color: var(--text-primary);
|
||||
border-radius: 50%;
|
||||
transition: transform var(--transition-fast);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.toggle-slider svg {
|
||||
width: 0.75rem;
|
||||
height: 0.75rem;
|
||||
color: var(--bg-primary);
|
||||
}
|
||||
|
||||
.theme-toggle.dark .toggle-slider {
|
||||
transform: translateX(1.5rem);
|
||||
background-color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Screen reader only */
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
/* Component-specific styles */
|
||||
.info-cards {
|
||||
display: grid;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.info-card {
|
||||
background-color: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-card .info-label {
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.value-copy {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.ip-value {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-md);
|
||||
font-weight: 500;
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.ip-value.success {
|
||||
color: var(--color-success-light);
|
||||
background-color: rgba(35, 134, 54, 0.1);
|
||||
}
|
||||
|
||||
.ip-value.error {
|
||||
color: var(--color-error-light);
|
||||
background-color: rgba(218, 54, 51, 0.1);
|
||||
}
|
||||
|
||||
.ip-value.info {
|
||||
color: var(--color-info-light);
|
||||
background-color: rgba(9, 105, 218, 0.1);
|
||||
}
|
||||
|
||||
.ip-value.warning {
|
||||
color: var(--color-warning-light);
|
||||
background-color: rgba(210, 153, 34, 0.1);
|
||||
}
|
||||
|
||||
.metric-value {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-lg);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.metric-value.success { color: var(--color-success-light); }
|
||||
.metric-value.info { color: var(--color-info-light); }
|
||||
|
||||
.cidr {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
margin-left: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.binary-display {
|
||||
display: grid;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.binary-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.binary-row .info-label {
|
||||
width: 80px;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.binary-value {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
.binary-value.success { color: var(--color-success-light); }
|
||||
.binary-value.info { color: var(--color-info-light); }
|
||||
.binary-value.error { color: var(--color-error-light); }
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.info-card {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.binary-row {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.binary-row .info-label {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* Form field components */
|
||||
.form-field {
|
||||
min-width: 250px;
|
||||
}
|
||||
|
||||
.field-input {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.field-icon {
|
||||
position: absolute;
|
||||
right: var(--spacing-sm);
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.field-error {
|
||||
color: var(--color-error-light);
|
||||
font-size: var(--font-size-xs);
|
||||
margin-top: var(--spacing-xs);
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.field-help {
|
||||
color: var(--color-success-light);
|
||||
font-size: var(--font-size-xs);
|
||||
margin-top: var(--spacing-xs);
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.status-icon svg {
|
||||
width: 0.75rem;
|
||||
height: 0.75rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.status-icon.success {
|
||||
background-color: var(--color-success);
|
||||
}
|
||||
|
||||
.status-icon.error {
|
||||
background-color: var(--color-error);
|
||||
}
|
||||
|
||||
.required {
|
||||
color: var(--color-error);
|
||||
margin-left: var(--spacing-xs);
|
||||
}
|
||||
|
||||
/* Copy button styles */
|
||||
.copy-btn {
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.copy-btn.copied {
|
||||
color: var(--color-success-light);
|
||||
background-color: rgba(35, 134, 54, 0.1);
|
||||
border-color: var(--color-success);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.copy-btn.copied:hover {
|
||||
background-color: rgba(35, 134, 54, 0.2);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.form-field {
|
||||
min-width: auto;
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// See https://svelte.dev/docs/kit/types#app.d.ts
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;400;500;600;700&display=swap');
|
||||
@import './styles/variables.scss';
|
||||
@import './styles/base.scss';
|
||||
@import './styles/components.scss';
|
||||
|
||||
// Tooltip styles
|
||||
.tooltip-container {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
position: absolute;
|
||||
z-index: 1000;
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: var(--font-size-xs);
|
||||
white-space: nowrap;
|
||||
box-shadow: var(--shadow-lg);
|
||||
pointer-events: none;
|
||||
|
||||
// Arrow styles
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 4px solid transparent;
|
||||
}
|
||||
|
||||
&.top {
|
||||
bottom: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
|
||||
&::before {
|
||||
top: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
border-top-color: var(--border-primary);
|
||||
}
|
||||
}
|
||||
|
||||
&.bottom {
|
||||
top: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
margin-top: var(--spacing-xs);
|
||||
|
||||
&::before {
|
||||
bottom: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
border-bottom-color: var(--border-primary);
|
||||
}
|
||||
}
|
||||
|
||||
&.left {
|
||||
right: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
margin-right: var(--spacing-xs);
|
||||
|
||||
&::before {
|
||||
left: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
border-left-color: var(--border-primary);
|
||||
}
|
||||
}
|
||||
|
||||
&.right {
|
||||
left: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
margin-left: var(--spacing-xs);
|
||||
|
||||
&::before {
|
||||
right: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
border-right-color: var(--border-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Theme toggle
|
||||
.theme-toggle {
|
||||
position: relative;
|
||||
width: 3rem;
|
||||
height: 1.5rem;
|
||||
background-color: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: 0.75rem;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
|
||||
&:hover {
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.toggle-slider {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
left: 1px;
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
background-color: var(--text-primary);
|
||||
border-radius: 50%;
|
||||
transition: transform var(--transition-fast);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
svg {
|
||||
width: 0.75rem;
|
||||
height: 0.75rem;
|
||||
color: var(--bg-primary);
|
||||
}
|
||||
}
|
||||
|
||||
&.dark .toggle-slider {
|
||||
transform: translateX(1.5rem);
|
||||
background-color: var(--color-primary);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.157 22.819c-10.4-14.885-30.94-19.297-45.792-9.835L22.282 29.608A29.92 29.92 0 0 0 8.764 49.65a31.5 31.5 0 0 0 3.108 20.231 30 30 0 0 0-4.477 11.183 31.9 31.9 0 0 0 5.448 24.116c10.402 14.887 30.942 19.297 45.791 9.835l26.083-16.624A29.92 29.92 0 0 0 98.235 78.35a31.53 31.53 0 0 0-3.105-20.232 30 30 0 0 0 4.474-11.182 31.88 31.88 0 0 0-5.447-24.116" style="fill:#ff3e00"/><path d="M45.817 106.582a20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.503 18 18 0 0 1 .624-2.435l.49-1.498 1.337.981a33.6 33.6 0 0 0 10.203 5.098l.97.294-.09.968a5.85 5.85 0 0 0 1.052 3.878 6.24 6.24 0 0 0 6.695 2.485 5.8 5.8 0 0 0 1.603-.704L69.27 76.28a5.43 5.43 0 0 0 2.45-3.631 5.8 5.8 0 0 0-.987-4.371 6.24 6.24 0 0 0-6.698-2.487 5.7 5.7 0 0 0-1.6.704l-9.953 6.345a19 19 0 0 1-5.296 2.326 20.72 20.72 0 0 1-22.237-8.243 19.17 19.17 0 0 1-3.277-14.502 17.99 17.99 0 0 1 8.13-12.052l26.081-16.623a19 19 0 0 1 5.3-2.329 20.72 20.72 0 0 1 22.237 8.243 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-.624 2.435l-.49 1.498-1.337-.98a33.6 33.6 0 0 0-10.203-5.1l-.97-.294.09-.968a5.86 5.86 0 0 0-1.052-3.878 6.24 6.24 0 0 0-6.696-2.485 5.8 5.8 0 0 0-1.602.704L37.73 51.72a5.42 5.42 0 0 0-2.449 3.63 5.79 5.79 0 0 0 .986 4.372 6.24 6.24 0 0 0 6.698 2.486 5.8 5.8 0 0 0 1.602-.704l9.952-6.342a19 19 0 0 1 5.295-2.328 20.72 20.72 0 0 1 22.237 8.242 19.17 19.17 0 0 1 3.277 14.503 18 18 0 0 1-8.13 12.053l-26.081 16.622a19 19 0 0 1-5.3 2.328" style="fill:#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,613 @@
|
||||
<script lang="ts">
|
||||
import { cidrToMask, maskToCidr } from '../utils/ip-calculations.js';
|
||||
import { validateSubnetMask } from '../utils/ip-validation.js';
|
||||
import { COMMON_SUBNETS } from '../constants/networks.js';
|
||||
import Tooltip from './Tooltip.svelte';
|
||||
|
||||
let cidrValue = $state(24);
|
||||
let maskValue = $state('255.255.255.0');
|
||||
let selectedTab = $state<'cidr-to-mask' | 'mask-to-cidr'>('cidr-to-mask');
|
||||
|
||||
/**
|
||||
* Converts CIDR to mask when CIDR input changes
|
||||
*/
|
||||
$effect(() => {
|
||||
if (selectedTab === 'cidr-to-mask') {
|
||||
const mask = cidrToMask(cidrValue);
|
||||
maskValue = mask.octets.join('.');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Converts mask to CIDR when mask input changes
|
||||
*/
|
||||
function handleMaskChange(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
maskValue = target.value;
|
||||
|
||||
if (validateSubnetMask(maskValue).valid) {
|
||||
cidrValue = maskToCidr(maskValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets subnet information for current values
|
||||
*/
|
||||
function getSubnetInfo(cidr: number) {
|
||||
const subnet = COMMON_SUBNETS.find(s => s.cidr === cidr);
|
||||
return subnet || { cidr, mask: cidrToMask(cidr).octets.join('.'), hosts: Math.pow(2, 32 - cidr) - 2 };
|
||||
}
|
||||
|
||||
let subnetInfo = $derived(getSubnetInfo(cidrValue));
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h2>CIDR ↔ Subnet Mask Converter</h2>
|
||||
<p>Convert between CIDR notation and subnet mask formats.</p>
|
||||
</header>
|
||||
|
||||
<!-- Tab Navigation -->
|
||||
<div class="tabs">
|
||||
<button
|
||||
type="button"
|
||||
class="tab {selectedTab === 'cidr-to-mask' ? 'active' : ''}"
|
||||
onclick={() => selectedTab = 'cidr-to-mask'}
|
||||
>
|
||||
CIDR → Subnet Mask
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="tab {selectedTab === 'mask-to-cidr' ? 'active' : ''}"
|
||||
onclick={() => selectedTab = 'mask-to-cidr'}
|
||||
>
|
||||
Subnet Mask → CIDR
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- CIDR to Mask Tab -->
|
||||
{#if selectedTab === 'cidr-to-mask'}
|
||||
<div class="converter-section fade-in">
|
||||
<!-- CIDR Input -->
|
||||
<div class="form-group">
|
||||
<Tooltip text="Drag slider to adjust CIDR prefix length - higher values create smaller subnets" position="right">
|
||||
<label for="cidr-slider" class="slider-label">
|
||||
CIDR Prefix Length: /{cidrValue}
|
||||
</label>
|
||||
</Tooltip>
|
||||
<div class="slider-container">
|
||||
<input
|
||||
id="cidr-slider"
|
||||
type="range"
|
||||
min="0"
|
||||
max="32"
|
||||
bind:value={cidrValue}
|
||||
class="cidr-slider"
|
||||
/>
|
||||
<div class="slider-markers">
|
||||
<span>0</span>
|
||||
<span>8</span>
|
||||
<span>16</span>
|
||||
<span>24</span>
|
||||
<span>32</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Result Display -->
|
||||
<div class="result-display info">
|
||||
<div class="result-content">
|
||||
<span class="result-label">Subnet Mask</span>
|
||||
<span class="result-value">
|
||||
{maskValue}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Mask to CIDR Tab -->
|
||||
{#if selectedTab === 'mask-to-cidr'}
|
||||
<div class="converter-section fade-in">
|
||||
<!-- Mask Input -->
|
||||
<div class="form-group">
|
||||
<label for="mask-input">Subnet Mask</label>
|
||||
<input
|
||||
id="mask-input"
|
||||
type="text"
|
||||
value={maskValue}
|
||||
placeholder="255.255.255.0"
|
||||
class="mask-input"
|
||||
oninput={handleMaskChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Result Display -->
|
||||
<div class="result-display success">
|
||||
<div class="result-content">
|
||||
<span class="result-label">CIDR Notation</span>
|
||||
<span class="result-value">
|
||||
/{cidrValue}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Subnet Information -->
|
||||
<section class="info-panel">
|
||||
<h3>Subnet Information</h3>
|
||||
<div class="grid grid-3">
|
||||
<Tooltip text="Number of bits used for network identification - higher values create smaller, more specific subnets" position="top">
|
||||
<div class="info-metric">
|
||||
<span class="info-label">Network Bits</span>
|
||||
<span class="metric-value info">{cidrValue}</span>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip text="Number of bits available for host addresses - more host bits allow for more devices" position="top">
|
||||
<div class="info-metric">
|
||||
<span class="info-label">Host Bits</span>
|
||||
<span class="metric-value info">{32 - cidrValue}</span>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Tooltip text="Number of IP addresses available for devices (excludes network and broadcast addresses)" position="top">
|
||||
<div class="info-metric">
|
||||
<span class="info-label">Usable Hosts</span>
|
||||
<span class="metric-value success">
|
||||
{(subnetInfo.hosts).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Common Subnets Reference -->
|
||||
<section class="common-subnets-section">
|
||||
<h3>Common Subnets</h3>
|
||||
<div class="subnets-grid">
|
||||
{#each COMMON_SUBNETS as subnet}
|
||||
<Tooltip text="Click to select this common subnet configuration" position="top">
|
||||
<button
|
||||
type="button"
|
||||
class="subnet-card {cidrValue === subnet.cidr ? 'active' : ''}"
|
||||
onclick={() => cidrValue = subnet.cidr}
|
||||
aria-label="Select /{subnet.cidr} subnet with {subnet.hosts.toLocaleString()} hosts"
|
||||
>
|
||||
<div class="subnet-info">
|
||||
<div class="subnet-cidr">
|
||||
<span class="cidr-notation">/{subnet.cidr}</span>
|
||||
<span class="subnet-mask">{subnet.mask}</span>
|
||||
</div>
|
||||
<span class="host-count">{subnet.hosts.toLocaleString()} hosts</span>
|
||||
</div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/each}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Explainer Section -->
|
||||
<section class="explainer-section">
|
||||
<h3>Understanding CIDR and Subnet Masks</h3>
|
||||
|
||||
<div class="explainer-grid">
|
||||
<div class="explainer-card">
|
||||
<h4>CIDR Notation</h4>
|
||||
<p>CIDR (Classless Inter-Domain Routing) uses a slash followed by a number (e.g., /24) to indicate how many bits are used for the network portion of an IP address.</p>
|
||||
</div>
|
||||
|
||||
<div class="explainer-card">
|
||||
<h4>Subnet Mask</h4>
|
||||
<p>A 32-bit number that masks an IP address to divide it into network and host portions. Written in dotted decimal notation (e.g., 255.255.255.0).</p>
|
||||
</div>
|
||||
|
||||
<div class="explainer-card">
|
||||
<h4>Network Bits</h4>
|
||||
<p>The leftmost bits in an IP address that identify the network. More network bits mean smaller subnets with fewer available host addresses.</p>
|
||||
</div>
|
||||
|
||||
<div class="explainer-card">
|
||||
<h4>Host Bits</h4>
|
||||
<p>The remaining bits used for host addresses within the network. More host bits allow for more devices but fewer possible subnets.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="conversion-examples">
|
||||
<h4>Common Conversions</h4>
|
||||
<div class="examples-grid">
|
||||
<div class="example-item">
|
||||
<span class="example-cidr">/24</span>
|
||||
<span class="example-arrow">↔</span>
|
||||
<span class="example-mask">255.255.255.0</span>
|
||||
<span class="example-desc">254 hosts</span>
|
||||
</div>
|
||||
<div class="example-item">
|
||||
<span class="example-cidr">/25</span>
|
||||
<span class="example-arrow">↔</span>
|
||||
<span class="example-mask">255.255.255.128</span>
|
||||
<span class="example-desc">126 hosts</span>
|
||||
</div>
|
||||
<div class="example-item">
|
||||
<span class="example-cidr">/26</span>
|
||||
<span class="example-arrow">↔</span>
|
||||
<span class="example-mask">255.255.255.192</span>
|
||||
<span class="example-desc">62 hosts</span>
|
||||
</div>
|
||||
<div class="example-item">
|
||||
<span class="example-cidr">/30</span>
|
||||
<span class="example-arrow">↔</span>
|
||||
<span class="example-mask">255.255.255.252</span>
|
||||
<span class="example-desc">2 hosts</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tips-box">
|
||||
<h4>🔧 Usage Tips</h4>
|
||||
<ul>
|
||||
<li><strong>Smaller CIDR = Bigger Network:</strong> /16 has more hosts than /24</li>
|
||||
<li><strong>Binary Thinking:</strong> Each bit doubles or halves the number of addresses</li>
|
||||
<li><strong>/30 for Links:</strong> Perfect for point-to-point connections (only 2 usable IPs)</li>
|
||||
<li><strong>Planning:</strong> Start with larger subnets and subdivide as needed</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.converter-section {
|
||||
margin: var(--spacing-lg) 0;
|
||||
}
|
||||
|
||||
.slider-label {
|
||||
display: block;
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.cidr-slider {
|
||||
width: 100%;
|
||||
height: 0.5rem;
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-lg);
|
||||
appearance: none;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.cidr-slider::-webkit-slider-thumb {
|
||||
appearance: none;
|
||||
height: 1.25rem;
|
||||
width: 1.25rem;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
cursor: pointer;
|
||||
box-shadow: var(--shadow-md);
|
||||
transition: transform var(--transition-fast);
|
||||
}
|
||||
|
||||
.cidr-slider::-webkit-slider-thumb:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.cidr-slider::-moz-range-thumb {
|
||||
height: 1.25rem;
|
||||
width: 1.25rem;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
box-shadow: var(--shadow-md);
|
||||
transition: transform var(--transition-fast);
|
||||
}
|
||||
|
||||
.cidr-slider::-moz-range-thumb:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.slider-markers {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.mask-input {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-lg);
|
||||
}
|
||||
|
||||
.result-display {
|
||||
padding: var(--spacing-md);
|
||||
border-radius: var(--radius-lg);
|
||||
margin-top: var(--spacing-md);
|
||||
}
|
||||
|
||||
.result-display.info {
|
||||
background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
|
||||
border: 1px solid var(--color-info);
|
||||
}
|
||||
|
||||
.result-display.success {
|
||||
background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
|
||||
border: 1px solid var(--color-success);
|
||||
}
|
||||
|
||||
.result-content {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.result-label {
|
||||
display: block;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.result-value {
|
||||
display: block;
|
||||
font-size: var(--font-size-2xl);
|
||||
font-family: var(--font-mono);
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
margin-top: var(--spacing-xl);
|
||||
}
|
||||
|
||||
.info-metric {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.info-metric .info-label {
|
||||
display: block;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.common-subnets-section {
|
||||
margin-top: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.subnets-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: var(--spacing-sm);
|
||||
margin-top: var(--spacing-md);
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.subnet-card {
|
||||
padding: var(--spacing-sm);
|
||||
text-align: left;
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-lg);
|
||||
background-color: var(--bg-secondary);
|
||||
transition: all var(--transition-fast);
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.subnet-card:hover {
|
||||
background-color: var(--surface-hover);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.subnet-card.active {
|
||||
background-color: var(--surface-hover);
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
.subnet-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.subnet-cidr {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.cidr-notation {
|
||||
font-family: var(--font-mono);
|
||||
font-weight: 700;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.subnet-mask {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.host-count {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.subnet-info {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.host-count {
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
|
||||
.explainer-section {
|
||||
margin-top: var(--spacing-xl);
|
||||
padding: var(--spacing-lg);
|
||||
background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px solid var(--border-secondary);
|
||||
}
|
||||
|
||||
.explainer-section h3 {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
text-align: center;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.explainer-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: var(--spacing-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.explainer-card {
|
||||
background-color: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.explainer-card:hover {
|
||||
border-color: color-mix(in srgb, var(--color-primary) 33%, transparent);
|
||||
box-shadow: var(--shadow-md);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.explainer-card h4 {
|
||||
color: var(--color-primary);
|
||||
font-size: var(--font-size-md);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.explainer-card p {
|
||||
color: var(--text-primary);
|
||||
font-size: var(--font-size-sm);
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.conversion-examples {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
padding: var(--spacing-md);
|
||||
background-color: var(--bg-primary);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--border-primary);
|
||||
}
|
||||
|
||||
.conversion-examples h4 {
|
||||
color: var(--color-info-light);
|
||||
margin-bottom: var(--spacing-md);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.examples-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.example-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: var(--spacing-sm);
|
||||
background-color: var(--bg-secondary);
|
||||
border-radius: var(--radius-sm);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
.example-cidr {
|
||||
color: var(--color-info-light);
|
||||
font-weight: 700;
|
||||
min-width: 2rem;
|
||||
}
|
||||
|
||||
.example-arrow {
|
||||
color: var(--text-secondary);
|
||||
margin: 0 var(--spacing-xs);
|
||||
}
|
||||
|
||||
.example-mask {
|
||||
color: var(--color-success-light);
|
||||
font-weight: 600;
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.example-desc {
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-xs);
|
||||
min-width: 4rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.tips-box {
|
||||
background-color: var(--bg-primary);
|
||||
border: 1px solid var(--color-warning);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
.tips-box h4 {
|
||||
color: var(--color-warning);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.tips-box ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.tips-box li {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
color: var(--text-primary);
|
||||
font-size: var(--font-size-sm);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.tips-box li::before {
|
||||
content: "•";
|
||||
color: var(--color-warning);
|
||||
font-weight: bold;
|
||||
display: inline-block;
|
||||
width: 1em;
|
||||
margin-right: var(--spacing-xs);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.explainer-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.examples-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.example-item {
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.explainer-section {
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,200 @@
|
||||
<script lang="ts">
|
||||
import { validateCIDR } from '../utils/ip-validation.js';
|
||||
import type { ValidationResult } from '../types/ip.js';
|
||||
import Tooltip from './Tooltip.svelte';
|
||||
import SvgIcon from './SvgIcon.svelte';
|
||||
|
||||
interface Props {
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
label?: string;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
class?: string;
|
||||
}
|
||||
|
||||
let {
|
||||
value = $bindable(''),
|
||||
placeholder = '192.168.1.0/24',
|
||||
label = 'CIDR Notation',
|
||||
required = false,
|
||||
disabled = false,
|
||||
class: className = ''
|
||||
}: Props = $props();
|
||||
|
||||
let validation: ValidationResult = $state({ valid: true });
|
||||
let focused = $state(false);
|
||||
|
||||
/**
|
||||
* Validates CIDR input on change
|
||||
*/
|
||||
function handleInput(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
value = target.value;
|
||||
validation = validateCIDR(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick CIDR presets
|
||||
*/
|
||||
const cidrPresets = [
|
||||
{ cidr: 8, label: '/8 (Class A)', hosts: '16M hosts' },
|
||||
{ cidr: 16, label: '/16 (Class B)', hosts: '65K hosts' },
|
||||
{ cidr: 24, label: '/24 (Class C)', hosts: '254 hosts' },
|
||||
{ cidr: 25, label: '/25', hosts: '126 hosts' },
|
||||
{ cidr: 26, label: '/26', hosts: '62 hosts' },
|
||||
{ cidr: 27, label: '/27', hosts: '30 hosts' },
|
||||
{ cidr: 28, label: '/28', hosts: '14 hosts' },
|
||||
{ cidr: 30, label: '/30 (P2P)', hosts: '2 hosts' }
|
||||
];
|
||||
|
||||
/**
|
||||
* Applies CIDR preset
|
||||
*/
|
||||
function applyPreset(cidr: number) {
|
||||
if (value && value.includes('/')) {
|
||||
const ip = value.split('/')[0];
|
||||
value = `${ip}/${cidr}`;
|
||||
} else if (value) {
|
||||
value = `${value}/${cidr}`;
|
||||
}
|
||||
validation = validateCIDR(value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="form-field {className}">
|
||||
{#if label}
|
||||
<label for="cidr-input">
|
||||
{label}
|
||||
{#if required}<span class="required">*</span>{/if}
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<div class="field-input">
|
||||
<input
|
||||
id="cidr-input"
|
||||
type="text"
|
||||
{value}
|
||||
{placeholder}
|
||||
{required}
|
||||
{disabled}
|
||||
class="input-cidr"
|
||||
class:valid={validation.valid && value}
|
||||
class:invalid={!validation.valid && value}
|
||||
class:focused
|
||||
oninput={handleInput}
|
||||
onfocus={() => focused = true}
|
||||
onblur={() => focused = false}
|
||||
/>
|
||||
|
||||
<!-- Validation indicator -->
|
||||
<div class="field-icon">
|
||||
{#if value && validation.valid}
|
||||
<div class="status-icon success">
|
||||
<SvgIcon icon="check" size="sm" />
|
||||
</div>
|
||||
{:else if value && !validation.valid}
|
||||
<div class="status-icon error">
|
||||
<SvgIcon icon="close" size="sm" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error message -->
|
||||
{#if !validation.valid && validation.error}
|
||||
<p class="field-error fade-in">
|
||||
{validation.error}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<!-- CIDR presets -->
|
||||
<div class="presets-section">
|
||||
<p class="presets-label">Quick presets:</p>
|
||||
<div class="presets-grid">
|
||||
{#each cidrPresets as preset}
|
||||
<Tooltip text="Apply {preset.label} - {preset.hosts}" position="top">
|
||||
<button
|
||||
type="button"
|
||||
class="preset-btn"
|
||||
{disabled}
|
||||
onclick={() => applyPreset(preset.cidr)}
|
||||
aria-label="Apply {preset.label} preset with {preset.hosts}"
|
||||
>
|
||||
{preset.label}
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.form-field {
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
|
||||
.input-cidr {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-md);
|
||||
padding-right: 2.5rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.input-cidr.valid {
|
||||
border-color: var(--color-success);
|
||||
}
|
||||
|
||||
.input-cidr.invalid {
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
|
||||
.input-cidr.focused {
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
|
||||
.presets-section {
|
||||
margin-top: var(--spacing-md);
|
||||
}
|
||||
|
||||
.presets-label {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.presets-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.preset-btn {
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
font-size: var(--font-size-xs);
|
||||
border-radius: var(--radius-sm);
|
||||
background-color: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-secondary);
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.preset-btn:hover:not(:disabled) {
|
||||
background-color: var(--surface-hover);
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.preset-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.form-field {
|
||||
min-width: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,436 @@
|
||||
<script lang="ts">
|
||||
import { convertIPFormats, decimalToIP, binaryToIP, hexToIP, getIPClass } from '../utils/ip-conversions.js';
|
||||
import { validateIPv4 } from '../utils/ip-validation.js';
|
||||
import IPInput from './IPInput.svelte';
|
||||
import Tooltip from './Tooltip.svelte';
|
||||
|
||||
let ipAddress = $state('192.168.1.1');
|
||||
let formats = $state({
|
||||
binary: '',
|
||||
decimal: '',
|
||||
hex: '',
|
||||
octal: ''
|
||||
});
|
||||
let ipClass = $state({ class: '', type: '', description: '' });
|
||||
let copiedStates = $state<Record<string, boolean>>({});
|
||||
|
||||
/**
|
||||
* Updates all format conversions when IP changes
|
||||
*/
|
||||
$effect(() => {
|
||||
if (ipAddress && validateIPv4(ipAddress).valid) {
|
||||
formats = convertIPFormats(ipAddress);
|
||||
ipClass = getIPClass(ipAddress);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Converts from decimal to IP
|
||||
*/
|
||||
function handleDecimalInput(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const decimal = parseInt(target.value);
|
||||
|
||||
if (!isNaN(decimal) && decimal >= 0 && decimal <= 4294967295) {
|
||||
try {
|
||||
ipAddress = decimalToIP(decimal);
|
||||
} catch (err) {
|
||||
console.error('Invalid decimal conversion:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from binary to IP
|
||||
*/
|
||||
function handleBinaryInput(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const binary = target.value.replace(/[^01.\s]/g, '');
|
||||
|
||||
if (binary.replace(/[.\s]/g, '').length === 32) {
|
||||
try {
|
||||
ipAddress = binaryToIP(binary);
|
||||
} catch (err) {
|
||||
console.error('Invalid binary conversion:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from hex to IP
|
||||
*/
|
||||
function handleHexInput(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const hex = target.value.replace(/[^0-9a-fA-F.x]/g, '');
|
||||
|
||||
if (hex.replace(/[.x]/g, '').length === 8) {
|
||||
try {
|
||||
ipAddress = hexToIP(hex);
|
||||
} catch (err) {
|
||||
console.error('Invalid hex conversion:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies text to clipboard with visual feedback
|
||||
*/
|
||||
async function copyToClipboard(text: string, id: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedStates[id] = true;
|
||||
setTimeout(() => {
|
||||
copiedStates[id] = false;
|
||||
}, 3000);
|
||||
} catch (err) {
|
||||
console.error('Failed to copy text: ', err);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h2>IP Address Converter</h2>
|
||||
<p>Convert IP addresses between different number formats.</p>
|
||||
</header>
|
||||
|
||||
<!-- Main IP Input -->
|
||||
<div class="form-group">
|
||||
<IPInput
|
||||
bind:value={ipAddress}
|
||||
label="IP Address"
|
||||
placeholder="192.168.1.1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if validateIPv4(ipAddress).valid}
|
||||
<div class="results-section fade-in">
|
||||
<!-- IP Class Information -->
|
||||
<section class="info-panel info">
|
||||
<h3>IP Class Information</h3>
|
||||
<div class="grid grid-3">
|
||||
<div class="class-info">
|
||||
<span class="info-label">Class</span>
|
||||
<span class="class-value">{ipClass.class}</span>
|
||||
</div>
|
||||
<div class="class-info">
|
||||
<span class="info-label">Type</span>
|
||||
<span class="class-value type">{ipClass.type}</span>
|
||||
</div>
|
||||
<div class="class-info">
|
||||
<span class="info-label">Usage</span>
|
||||
<span class="class-description">{ipClass.description}</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Format Conversions -->
|
||||
<div class="grid grid-2 conversions-grid">
|
||||
<!-- Binary Format -->
|
||||
<div class="format-group">
|
||||
<label for="binary-input">Binary Format</label>
|
||||
<div class="format-input">
|
||||
<input
|
||||
id="binary-input"
|
||||
type="text"
|
||||
value={formats.binary}
|
||||
placeholder="11000000.10101000.00000001.00000001"
|
||||
class="format-field binary"
|
||||
oninput={handleBinaryInput}
|
||||
/>
|
||||
<Tooltip text={copiedStates['binary'] ? 'Copied!' : 'Copy binary format to clipboard'} position="left">
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn {copiedStates['binary'] ? 'copied' : ''}"
|
||||
onclick={() => copyToClipboard(formats.binary, 'binary')}
|
||||
aria-label="Copy binary format to clipboard"
|
||||
>
|
||||
{#if copiedStates['binary']}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M8 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z"/>
|
||||
<path d="M6 3a2 2 0 00-2 2v11a2 2 0 002 2h8a2 2 0 002-2V5a2 2 0 00-2-2 3 3 0 01-3 3H9a3 3 0 01-3-3z"/>
|
||||
</svg>
|
||||
{/if}
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Decimal Format -->
|
||||
<div class="format-group">
|
||||
<label for="decimal-input">Decimal Format</label>
|
||||
<div class="format-input">
|
||||
<input
|
||||
id="decimal-input"
|
||||
type="text"
|
||||
value={formats.decimal}
|
||||
placeholder="3232235777"
|
||||
class="format-field decimal"
|
||||
oninput={handleDecimalInput}
|
||||
/>
|
||||
<Tooltip text={copiedStates['decimal'] ? 'Copied!' : 'Copy decimal format to clipboard'} position="left">
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn {copiedStates['decimal'] ? 'copied' : ''}"
|
||||
onclick={() => copyToClipboard(formats.decimal, 'decimal')}
|
||||
aria-label="Copy decimal format to clipboard"
|
||||
>
|
||||
{#if copiedStates['decimal']}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M8 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z"/>
|
||||
<path d="M6 3a2 2 0 00-2 2v11a2 2 0 002 2h8a2 2 0 002-2V5a2 2 0 00-2-2 3 3 0 01-3 3H9a3 3 0 01-3-3z"/>
|
||||
</svg>
|
||||
{/if}
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hexadecimal Format -->
|
||||
<div class="format-group">
|
||||
<label for="hex-input">Hexadecimal Format</label>
|
||||
<div class="format-input">
|
||||
<input
|
||||
id="hex-input"
|
||||
type="text"
|
||||
value={formats.hex}
|
||||
placeholder="0xC0.0xA8.0x01.0x01"
|
||||
class="format-field hex"
|
||||
oninput={handleHexInput}
|
||||
/>
|
||||
<Tooltip text={copiedStates['hex'] ? 'Copied!' : 'Copy hexadecimal format to clipboard'} position="left">
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn {copiedStates['hex'] ? 'copied' : ''}"
|
||||
onclick={() => copyToClipboard(formats.hex, 'hex')}
|
||||
aria-label="Copy hexadecimal format to clipboard"
|
||||
>
|
||||
{#if copiedStates['hex']}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M8 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z"/>
|
||||
<path d="M6 3a2 2 0 00-2 2v11a2 2 0 002 2h8a2 2 0 002-2V5a2 2 0 00-2-2 3 3 0 01-3 3H9a3 3 0 01-3-3z"/>
|
||||
</svg>
|
||||
{/if}
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Octal Format -->
|
||||
<div class="format-group">
|
||||
<label for="octal-input">Octal Format</label>
|
||||
<div class="format-input">
|
||||
<input
|
||||
id="octal-input"
|
||||
type="text"
|
||||
value={formats.octal}
|
||||
placeholder="0300.0250.001.001"
|
||||
class="format-field octal"
|
||||
readonly
|
||||
/>
|
||||
<Tooltip text={copiedStates['octal'] ? 'Copied!' : 'Copy octal format to clipboard'} position="left">
|
||||
<button
|
||||
type="button"
|
||||
class="copy-btn {copiedStates['octal'] ? 'copied' : ''}"
|
||||
onclick={() => copyToClipboard(formats.octal, 'octal')}
|
||||
aria-label="Copy octal format to clipboard"
|
||||
>
|
||||
{#if copiedStates['octal']}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M8 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z"/>
|
||||
<path d="M6 3a2 2 0 00-2 2v11a2 2 0 002 2h8a2 2 0 002-2V5a2 2 0 00-2-2 3 3 0 01-3 3H9a3 3 0 01-3-3z"/>
|
||||
</svg>
|
||||
{/if}
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Format Examples -->
|
||||
<section class="examples-section">
|
||||
<h3>Format Examples</h3>
|
||||
<div class="grid grid-4">
|
||||
<div class="example">
|
||||
<span class="example-label binary">Binary</span>
|
||||
<code class="example-value">11000000.10101000...</code>
|
||||
</div>
|
||||
<div class="example">
|
||||
<span class="example-label decimal">Decimal</span>
|
||||
<code class="example-value">3232235777</code>
|
||||
</div>
|
||||
<div class="example">
|
||||
<span class="example-label hex">Hexadecimal</span>
|
||||
<code class="example-value">0xC0A80101</code>
|
||||
</div>
|
||||
<div class="example">
|
||||
<span class="example-label octal">Octal</span>
|
||||
<code class="example-value">030052000401</code>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.results-section {
|
||||
margin-top: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.class-info {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.class-value {
|
||||
display: block;
|
||||
font-size: var(--font-size-xl);
|
||||
font-weight: 700;
|
||||
font-family: var(--font-mono);
|
||||
color: var(--color-primary);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.class-value.type {
|
||||
color: var(--color-info-light);
|
||||
}
|
||||
|
||||
.class-description {
|
||||
display: block;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.conversions-grid {
|
||||
margin-top: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.format-group {
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
.format-input {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.format-field {
|
||||
flex: 1;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-md);
|
||||
}
|
||||
|
||||
.format-field.binary {
|
||||
border-color: var(--color-info);
|
||||
}
|
||||
|
||||
.format-field.decimal {
|
||||
border-color: var(--color-success);
|
||||
}
|
||||
|
||||
.format-field.hex {
|
||||
border-color: var(--color-warning);
|
||||
}
|
||||
|
||||
.format-field.octal {
|
||||
border-color: var(--text-secondary);
|
||||
background-color: var(--bg-tertiary);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
color: var(--text-secondary);
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.copy-btn svg {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
|
||||
.copy-btn:hover {
|
||||
background-color: var(--surface-hover);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
|
||||
.examples-section {
|
||||
margin-top: var(--spacing-lg);
|
||||
padding: var(--spacing-md);
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-lg);
|
||||
}
|
||||
|
||||
.example {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.example-label {
|
||||
display: block;
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 600;
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.example-label.binary {
|
||||
color: var(--color-info-light);
|
||||
}
|
||||
|
||||
.example-label.decimal {
|
||||
color: var(--color-success-light);
|
||||
}
|
||||
|
||||
.example-label.hex {
|
||||
color: var(--color-warning-light);
|
||||
}
|
||||
|
||||
.example-label.octal {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.example-value {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.format-input {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
align-self: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,119 @@
|
||||
<script lang="ts">
|
||||
import { validateIPv4 } from '../utils/ip-validation.js';
|
||||
import type { ValidationResult } from '../types/ip.js';
|
||||
import SvgIcon from './SvgIcon.svelte';
|
||||
|
||||
interface Props {
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
label?: string;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
class?: string;
|
||||
}
|
||||
|
||||
let {
|
||||
value = $bindable(''),
|
||||
placeholder = '192.168.1.1',
|
||||
label = 'IP Address',
|
||||
required = false,
|
||||
disabled = false,
|
||||
class: className = ''
|
||||
}: Props = $props();
|
||||
|
||||
let validation: ValidationResult = $state({ valid: true });
|
||||
let focused = $state(false);
|
||||
|
||||
/**
|
||||
* Validates input on change
|
||||
*/
|
||||
function handleInput(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
value = target.value;
|
||||
validation = validateIPv4(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats IP address as user types
|
||||
*/
|
||||
function formatIP(ip: string): string {
|
||||
return ip.replace(/[^0-9.]/g, '');
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="form-field {className}">
|
||||
{#if label}
|
||||
<label for="ip-input">
|
||||
{label}
|
||||
{#if required}<span class="required">*</span>{/if}
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<div class="field-input">
|
||||
<input
|
||||
id="ip-input"
|
||||
type="text"
|
||||
{value}
|
||||
{placeholder}
|
||||
{required}
|
||||
{disabled}
|
||||
class="input-ip"
|
||||
class:valid={validation.valid && value}
|
||||
class:invalid={!validation.valid && value}
|
||||
class:focused
|
||||
oninput={handleInput}
|
||||
onfocus={() => focused = true}
|
||||
onblur={() => focused = false}
|
||||
/>
|
||||
|
||||
<!-- Validation indicator -->
|
||||
<div class="field-icon">
|
||||
{#if value && validation.valid}
|
||||
<div class="status-icon success">
|
||||
<SvgIcon icon="check" size="sm" />
|
||||
</div>
|
||||
{:else if value && !validation.valid}
|
||||
<div class="status-icon error">
|
||||
<SvgIcon icon="close" size="sm" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error message -->
|
||||
{#if !validation.valid && validation.error}
|
||||
<p class="field-error fade-in">
|
||||
{validation.error}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<!-- Helper text -->
|
||||
{#if validation.valid && value}
|
||||
<p class="field-help">
|
||||
Valid IPv4 address format
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
.input-ip {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-lg);
|
||||
padding-right: 2.5rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.input-ip.valid {
|
||||
border-color: var(--color-success);
|
||||
}
|
||||
|
||||
.input-ip.invalid {
|
||||
border-color: var(--color-error);
|
||||
}
|
||||
|
||||
.input-ip.focused {
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,464 @@
|
||||
<script lang="ts">
|
||||
import { NETWORK_CLASSES, RESERVED_RANGES, COMMON_SUBNETS } from '../constants/networks.js';
|
||||
import Tooltip from './Tooltip.svelte';
|
||||
|
||||
let selectedCategory = $state<'classes' | 'reserved' | 'subnets'>('classes');
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h2>Network Reference</h2>
|
||||
<p>Essential networking information and constants for IP address planning.</p>
|
||||
</header>
|
||||
|
||||
<!-- Category Tabs -->
|
||||
<div class="tabs">
|
||||
<button
|
||||
type="button"
|
||||
class="tab {selectedCategory === 'classes' ? 'active' : ''}"
|
||||
onclick={() => selectedCategory = 'classes'}
|
||||
>
|
||||
Network Classes
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="tab {selectedCategory === 'reserved' ? 'active' : ''}"
|
||||
onclick={() => selectedCategory = 'reserved'}
|
||||
>
|
||||
Reserved Ranges
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="tab {selectedCategory === 'subnets' ? 'active' : ''}"
|
||||
onclick={() => selectedCategory = 'subnets'}
|
||||
>
|
||||
Common Subnets
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Network Classes -->
|
||||
{#if selectedCategory === 'classes'}
|
||||
<div class="reference-section fade-in">
|
||||
{#each Object.entries(NETWORK_CLASSES) as [className, classInfo]}
|
||||
<Tooltip text="Class {className} networks use {classInfo.defaultMask} as default subnet mask and support {classInfo.range}" position="top">
|
||||
<div class="reference-card">
|
||||
<div class="card-header-inline">
|
||||
<div class="class-info">
|
||||
<div class="class-badge {className.toLowerCase()}">
|
||||
{className}
|
||||
</div>
|
||||
<div class="class-details">
|
||||
<h3>Class {className}</h3>
|
||||
<span class="mask-info">
|
||||
{classInfo.defaultMask} (/{classInfo.cidr})
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<span class="range-badge">
|
||||
{classInfo.range.split(' - ')[0]} - {classInfo.range.split(' - ')[1]}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<p class="class-description">
|
||||
{classInfo.description}
|
||||
</p>
|
||||
|
||||
<p class="usage-info">
|
||||
<strong>Typical Usage:</strong> {classInfo.usage}
|
||||
</p>
|
||||
</div>
|
||||
</Tooltip>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Reserved Ranges -->
|
||||
{#if selectedCategory === 'reserved'}
|
||||
<div class="reference-section fade-in">
|
||||
{#each Object.entries(RESERVED_RANGES) as [rangeName, rangeInfo]}
|
||||
<Tooltip text="{rangeInfo.description} - Defined in {rangeInfo.rfc}" position="top">
|
||||
<div class="reference-card">
|
||||
<div class="card-header-inline">
|
||||
<div class="range-info">
|
||||
<h3 class="range-address">
|
||||
{rangeInfo.range}
|
||||
</h3>
|
||||
<span class="range-description">
|
||||
{rangeInfo.description}
|
||||
</span>
|
||||
</div>
|
||||
<span class="rfc-badge">
|
||||
{rangeInfo.rfc}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Special highlighting for private networks -->
|
||||
{#if rangeName.includes('PRIVATE')}
|
||||
<div class="private-notice">
|
||||
<strong>Private Network:</strong> Not routed on the public Internet
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Tooltip>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Common Subnets -->
|
||||
{#if selectedCategory === 'subnets'}
|
||||
<div class="subnets-table fade-in">
|
||||
<div class="table-header">
|
||||
<span>CIDR</span>
|
||||
<span>Subnet Mask</span>
|
||||
<span>Hosts</span>
|
||||
<span>Usage</span>
|
||||
</div>
|
||||
|
||||
{#each COMMON_SUBNETS as subnet}
|
||||
<Tooltip text="/{subnet.cidr} subnet with mask {subnet.mask} supports {subnet.hosts.toLocaleString()} hosts" position="top">
|
||||
<div class="table-row">
|
||||
<span class="cidr-cell">
|
||||
/{subnet.cidr}
|
||||
</span>
|
||||
<span class="mask-cell">
|
||||
{subnet.mask}
|
||||
</span>
|
||||
<span class="hosts-cell">
|
||||
{subnet.hosts.toLocaleString()}
|
||||
</span>
|
||||
<span class="usage-cell">
|
||||
{#if subnet.cidr === 8}
|
||||
Large ISPs
|
||||
{:else if subnet.cidr === 16}
|
||||
Universities
|
||||
{:else if subnet.cidr === 24}
|
||||
Small businesses
|
||||
{:else if subnet.cidr === 25}
|
||||
Departments
|
||||
{:else if subnet.cidr === 26}
|
||||
Teams
|
||||
{:else if subnet.cidr === 27}
|
||||
Small offices
|
||||
{:else if subnet.cidr === 28}
|
||||
Workgroups
|
||||
{:else if subnet.cidr === 29}
|
||||
Small groups
|
||||
{:else if subnet.cidr === 30}
|
||||
Point-to-point
|
||||
{:else}
|
||||
General use
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
</Tooltip>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Quick Tips -->
|
||||
<section class="tips-section">
|
||||
<h4 class="tips-header">
|
||||
<svg class="tip-icon" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
Pro Tips
|
||||
</h4>
|
||||
<ul class="tips-list">
|
||||
<li>• Always plan for future growth when choosing subnet sizes</li>
|
||||
<li>• Use /30 subnets for point-to-point links to save addresses</li>
|
||||
<li>• Consider VLSM (Variable Length Subnet Masking) for efficient allocation</li>
|
||||
<li>• Private addresses (RFC 1918) are not routable on the Internet</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.reference-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
margin: var(--spacing-lg) 0;
|
||||
}
|
||||
|
||||
.reference-card {
|
||||
padding: var(--spacing-md);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-lg);
|
||||
background-color: var(--bg-secondary);
|
||||
transition: all var(--transition-fast);
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.reference-card:hover {
|
||||
box-shadow: var(--shadow-md);
|
||||
border-color: color-mix(in srgb, var(--color-primary) 33%, transparent);
|
||||
}
|
||||
|
||||
.card-header-inline {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.class-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.class-badge {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.class-badge.a {
|
||||
background-color: var(--color-info);
|
||||
}
|
||||
|
||||
.class-badge.b {
|
||||
background-color: var(--color-success);
|
||||
}
|
||||
|
||||
.class-badge.c {
|
||||
background-color: var(--color-warning);
|
||||
}
|
||||
|
||||
.class-details h3 {
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.mask-info {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.range-badge {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
background-color: var(--bg-tertiary);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.class-description {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.usage-info {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.range-info h3 {
|
||||
font-family: var(--font-mono);
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.range-description {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.rfc-badge {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--color-info-light);
|
||||
background-color: rgba(9, 105, 218, 0.1);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.private-notice {
|
||||
margin-top: var(--spacing-sm);
|
||||
padding: var(--spacing-sm);
|
||||
background-color: rgba(35, 134, 54, 0.1);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--color-success-light);
|
||||
}
|
||||
|
||||
.subnets-table {
|
||||
margin: var(--spacing-lg) 0;
|
||||
:global(.tooltip-container) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.table-header {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr 1.5fr 2fr;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
border-bottom: 1px solid var(--border-primary);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.table-header > span:nth-child(1) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.table-header > span:nth-child(2) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.table-header > span:nth-child(3) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.table-header > span:nth-child(4) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.table-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr 1.5fr 2fr;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-sm);
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-lg);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
transition: background-color var(--transition-fast);
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.table-row:hover {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
|
||||
.cidr-cell {
|
||||
font-family: var(--font-mono);
|
||||
font-weight: 700;
|
||||
color: var(--color-info-light);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.mask-cell {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-primary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.hosts-cell {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--color-success-light);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.usage-cell {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.tips-section {
|
||||
margin-top: var(--spacing-xl);
|
||||
padding: var(--spacing-md);
|
||||
background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px solid var(--border-secondary);
|
||||
}
|
||||
|
||||
.tips-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.tip-icon {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
.tips-list {
|
||||
list-style: none;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.card-header-inline {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.table-header,
|
||||
.table-row {
|
||||
grid-template-columns: 1fr;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.table-header {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.table-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
.cidr-cell::before {
|
||||
content: 'CIDR: ';
|
||||
color: var(--text-secondary);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.mask-cell::before {
|
||||
content: 'Mask: ';
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.hosts-cell::before {
|
||||
content: 'Hosts: ';
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.usage-cell::before {
|
||||
content: 'Usage: ';
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,521 @@
|
||||
<script lang="ts">
|
||||
import type { SubnetInfo } from '../types/ip.js';
|
||||
import Tooltip from './Tooltip.svelte';
|
||||
|
||||
interface Props {
|
||||
subnetInfo: SubnetInfo;
|
||||
class?: string;
|
||||
}
|
||||
|
||||
let { subnetInfo, class: className = '' }: Props = $props();
|
||||
|
||||
/**
|
||||
* Generates visual representation of network range
|
||||
*/
|
||||
function generateNetworkBlocks() {
|
||||
const totalHosts = subnetInfo.hostCount;
|
||||
const usableHosts = subnetInfo.usableHosts;
|
||||
|
||||
// For visualization, we'll show up to 256 blocks max
|
||||
const maxBlocks = 256;
|
||||
const blocksToShow = Math.min(totalHosts, maxBlocks);
|
||||
const blockSize = totalHosts > maxBlocks ? Math.ceil(totalHosts / maxBlocks) : 1;
|
||||
|
||||
const blocks = [];
|
||||
|
||||
for (let i = 0; i < blocksToShow; i++) {
|
||||
const isNetwork = i === 0;
|
||||
const isBroadcast = i === blocksToShow - 1 && totalHosts > 2;
|
||||
const isUsable = !isNetwork && !isBroadcast;
|
||||
|
||||
blocks.push({
|
||||
id: i,
|
||||
type: isNetwork ? 'network' : isBroadcast ? 'broadcast' : 'usable',
|
||||
represents: blockSize,
|
||||
tooltip: isNetwork
|
||||
? 'Network Address'
|
||||
: isBroadcast
|
||||
? 'Broadcast Address'
|
||||
: `Usable Host${blockSize > 1 ? 's' : ''}`
|
||||
});
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
let networkBlocks = $derived(generateNetworkBlocks());
|
||||
let usablePercentage = $derived(subnetInfo.hostCount > 0 ? (subnetInfo.usableHosts / subnetInfo.hostCount) * 100 : 0);
|
||||
</script>
|
||||
|
||||
<div class="network-visualizer {className}">
|
||||
<section class="visualizer-section">
|
||||
<h3>Network Visualization</h3>
|
||||
|
||||
<!-- Network Range Bar -->
|
||||
<div class="range-section">
|
||||
<div class="range-header">
|
||||
<span class="range-label">Address Range</span>
|
||||
<span class="range-count">
|
||||
{subnetInfo.hostCount.toLocaleString()} total addresses
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="range-bar">
|
||||
<!-- Network Address -->
|
||||
<div
|
||||
class="range-segment network"
|
||||
style="width: {100 / subnetInfo.hostCount}%"
|
||||
title="Network Address"
|
||||
>
|
||||
{#if subnetInfo.hostCount <= 32}
|
||||
<span class="segment-label">N</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Usable Hosts -->
|
||||
<div
|
||||
class="range-segment usable"
|
||||
style="left: {100 / subnetInfo.hostCount}%; width: {usablePercentage * (1 - 2 / subnetInfo.hostCount)}%"
|
||||
title="Usable Host Addresses"
|
||||
></div>
|
||||
|
||||
<!-- Broadcast Address -->
|
||||
{#if subnetInfo.hostCount > 1}
|
||||
<div
|
||||
class="range-segment broadcast"
|
||||
style="width: {100 / subnetInfo.hostCount}%"
|
||||
title="Broadcast Address"
|
||||
>
|
||||
{#if subnetInfo.hostCount <= 32}
|
||||
<span class="segment-label">B</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Legend -->
|
||||
<div class="range-legend">
|
||||
<div class="legend-item">
|
||||
<div class="legend-color network"></div>
|
||||
<span>Network</span>
|
||||
</div>
|
||||
<div class="legend-item">
|
||||
<div class="legend-color usable"></div>
|
||||
<span>Usable Hosts ({subnetInfo.usableHosts.toLocaleString()})</span>
|
||||
</div>
|
||||
{#if subnetInfo.hostCount > 1}
|
||||
<div class="legend-item">
|
||||
<div class="legend-color broadcast"></div>
|
||||
<span>Broadcast</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Binary Subnet Mask Visualization -->
|
||||
<section class="binary-section">
|
||||
<h4>Subnet Mask Binary Breakdown</h4>
|
||||
|
||||
<div class="binary-display">
|
||||
{#each subnetInfo.subnet.octets as octet, i}
|
||||
<div class="binary-row">
|
||||
<span class="octet-decimal">
|
||||
{octet.toString().padStart(3, '0')}
|
||||
</span>
|
||||
<span class="arrow">→</span>
|
||||
<div class="bits-group">
|
||||
{#each octet.toString(2).padStart(8, '0').split('') as bit, bitIndex}
|
||||
<Tooltip text="{bit === '1' ? 'Network bit (1)' : 'Host bit (0)'} - Position {i * 8 + bitIndex + 1}" position="top">
|
||||
<span class="bit-box {bit === '1' ? 'network-bit' : 'host-bit'}">
|
||||
{bit}
|
||||
</span>
|
||||
</Tooltip>
|
||||
{/each}
|
||||
</div>
|
||||
<span class="octet-label">
|
||||
(Octet {i + 1})
|
||||
</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="binary-summary">
|
||||
<div class="bit-stats">
|
||||
<div class="bit-stat">
|
||||
<div class="legend-color network"></div>
|
||||
<span>Network bits: {subnetInfo.cidr}</span>
|
||||
</div>
|
||||
<div class="bit-stat">
|
||||
<div class="legend-color host"></div>
|
||||
<span>Host bits: {32 - subnetInfo.cidr}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Address Grid (for smaller subnets) -->
|
||||
{#if subnetInfo.hostCount <= 64}
|
||||
<section class="grid-section">
|
||||
<h4>Address Grid</h4>
|
||||
|
||||
<div class="address-grid-wrap">
|
||||
<div class="address-grid">
|
||||
{#each networkBlocks as block}
|
||||
<Tooltip text="{block.tooltip}" position="top">
|
||||
<div class="address-block {block.type}">
|
||||
{#if block.type === 'network'}
|
||||
N
|
||||
{:else if block.type === 'broadcast'}
|
||||
B
|
||||
{:else}
|
||||
{block.id}
|
||||
{/if}
|
||||
</div>
|
||||
</Tooltip>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
<!-- Efficiency Metrics -->
|
||||
<section class="efficiency-section">
|
||||
<h4>Network Efficiency</h4>
|
||||
|
||||
<div class="efficiency-grid">
|
||||
<div class="efficiency-metric">
|
||||
<div class="metric-value">
|
||||
{usablePercentage.toFixed(1)}%
|
||||
</div>
|
||||
<div class="metric-label">
|
||||
Address Utilization
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="efficiency-metric">
|
||||
<div class="metric-value">
|
||||
{subnetInfo.cidr}/32
|
||||
</div>
|
||||
<div class="metric-label">
|
||||
Network Specificity
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.network-visualizer {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.visualizer-section {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.visualizer-section h3 {
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
.range-section {
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
.range-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.range-label {
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.range-count {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.range-bar {
|
||||
position: relative;
|
||||
height: 2rem;
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-lg);
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--border-primary);
|
||||
}
|
||||
|
||||
.range-segment {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.range-segment.network {
|
||||
left: 0;
|
||||
background-color: var(--color-info);
|
||||
}
|
||||
|
||||
.range-segment.usable {
|
||||
background-color: var(--color-success);
|
||||
}
|
||||
|
||||
.range-segment.broadcast {
|
||||
right: 0;
|
||||
background-color: var(--color-error);
|
||||
}
|
||||
|
||||
.segment-label {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.range-legend {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: var(--spacing-lg);
|
||||
margin-top: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.legend-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.legend-color {
|
||||
width: 0.75rem;
|
||||
height: 0.75rem;
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.legend-color.network {
|
||||
background-color: var(--color-info);
|
||||
}
|
||||
|
||||
.legend-color.usable {
|
||||
background-color: var(--color-success);
|
||||
}
|
||||
|
||||
.legend-color.broadcast {
|
||||
background-color: var(--color-error);
|
||||
}
|
||||
|
||||
.legend-color.host {
|
||||
background-color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.binary-section {
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.binary-section h4 {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.binary-display {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-sm);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
.binary-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.octet-decimal {
|
||||
width: 3rem;
|
||||
color: var(--text-secondary);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: var(--font-size-lg);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.bits-group {
|
||||
display: flex;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.bit-box {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: var(--font-size-xs);
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.bit-box.network-bit {
|
||||
background-color: var(--color-info);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.bit-box.host-bit {
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
}
|
||||
|
||||
.octet-label {
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-xs);
|
||||
}
|
||||
|
||||
.binary-summary {
|
||||
margin-top: var(--spacing-md);
|
||||
padding-top: var(--spacing-sm);
|
||||
border-top: 1px solid var(--border-primary);
|
||||
}
|
||||
|
||||
.bit-stats {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
.bit-stat {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.grid-section {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.grid-section h4 {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.address-grid-wrap {
|
||||
padding: var(--spacing-md);
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-lg);
|
||||
width: 100%;
|
||||
}
|
||||
.address-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(8, 1fr);
|
||||
gap: var(--spacing-xs);
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.address-block {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 600;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
transition: transform var(--transition-fast);
|
||||
}
|
||||
|
||||
.address-block:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.address-block.network {
|
||||
background-color: var(--color-info);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.address-block.broadcast {
|
||||
background-color: var(--color-error);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.address-block.usable {
|
||||
background-color: var(--color-success);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.address-block.usable:hover {
|
||||
background-color: var(--color-success-light);
|
||||
}
|
||||
|
||||
.efficiency-section {
|
||||
padding: var(--spacing-md);
|
||||
background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px solid var(--border-secondary);
|
||||
}
|
||||
|
||||
.efficiency-section h4 {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.efficiency-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.efficiency-metric {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.efficiency-metric .metric-value {
|
||||
font-size: var(--font-size-2xl);
|
||||
font-weight: 700;
|
||||
color: var(--color-info-light);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.efficiency-metric .metric-label {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.range-legend {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.binary-row {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.bit-stats {
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.efficiency-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.address-grid {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,343 @@
|
||||
<script lang="ts">
|
||||
import { calculateSubnet } from '../utils/ip-calculations.js';
|
||||
import { validateCIDR } from '../utils/ip-validation.js';
|
||||
import CIDRInput from './CIDRInput.svelte';
|
||||
import NetworkVisualizer from './NetworkVisualizer.svelte';
|
||||
import Tooltip from './Tooltip.svelte';
|
||||
import SvgIcon from './SvgIcon.svelte';
|
||||
import type { SubnetInfo } from '../types/ip.js';
|
||||
|
||||
let cidrInput = $state('192.168.1.0/24');
|
||||
let subnetInfo: SubnetInfo | null = $state(null);
|
||||
let isCalculating = $state(false);
|
||||
let hasEverShownResults = $state(false);
|
||||
|
||||
/**
|
||||
* Calculate subnet info when input changes
|
||||
*/
|
||||
$effect(() => {
|
||||
if (cidrInput && validateCIDR(cidrInput).valid) {
|
||||
isCalculating = true;
|
||||
const [ip, cidr] = cidrInput.split('/');
|
||||
setTimeout(() => {
|
||||
subnetInfo = calculateSubnet(ip, parseInt(cidr, 10));
|
||||
isCalculating = false;
|
||||
if (!hasEverShownResults) {
|
||||
hasEverShownResults = true;
|
||||
}
|
||||
}, 100);
|
||||
} else {
|
||||
subnetInfo = null;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Format large numbers
|
||||
*/
|
||||
function formatNumber(num: number): string {
|
||||
return num.toLocaleString();
|
||||
}
|
||||
|
||||
let copiedStates = $state<Record<string, boolean>>({});
|
||||
|
||||
/**
|
||||
* Copy to clipboard with visual feedback
|
||||
*/
|
||||
async function copyToClipboard(text: string, id: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
copiedStates[id] = true;
|
||||
setTimeout(() => {
|
||||
copiedStates[id] = false;
|
||||
}, 3000);
|
||||
} catch (err) {
|
||||
console.error('Failed to copy:', err);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<h2>Subnet Calculator</h2>
|
||||
<p>Calculate network, broadcast, and host information for any subnet.</p>
|
||||
</header>
|
||||
|
||||
<!-- Input -->
|
||||
<div class="form-group">
|
||||
<CIDRInput
|
||||
bind:value={cidrInput}
|
||||
label="Network Address (CIDR)"
|
||||
placeholder="192.168.1.0/24"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Results -->
|
||||
{#if subnetInfo}
|
||||
<div class="grid grid-2 {!hasEverShownResults ? 'fade-in' : ''} {isCalculating ? 'calculating' : ''}">
|
||||
<!-- Network Info -->
|
||||
<section>
|
||||
<h3 style="margin-bottom: var(--spacing-md); border-bottom: 1px solid var(--border-primary); padding-bottom: var(--spacing-xs);">
|
||||
Network Information
|
||||
</h3>
|
||||
|
||||
<div class="info-cards">
|
||||
<div class="info-card">
|
||||
<span class="info-label">Network Address</span>
|
||||
<div class="value-copy">
|
||||
<code class="ip-value success">{subnetInfo.network.octets.join('.')}</code>
|
||||
<Tooltip text={copiedStates['network'] ? 'Copied!' : 'Copy network address to clipboard'} position="top">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-icon copy-btn {copiedStates['network'] ? 'copied' : ''}"
|
||||
onclick={() => copyToClipboard(subnetInfo!.network.octets.join('.'), 'network')}
|
||||
aria-label="Copy network address"
|
||||
>
|
||||
<SvgIcon icon={copiedStates['network'] ? 'check' : 'clipboard'} size="md" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<span class="info-label">Broadcast Address</span>
|
||||
<div class="value-copy">
|
||||
<code class="ip-value error">{subnetInfo.broadcast.octets.join('.')}</code>
|
||||
<Tooltip text={copiedStates['broadcast'] ? 'Copied!' : 'Copy broadcast address to clipboard'} position="top">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-icon copy-btn {copiedStates['broadcast'] ? 'copied' : ''}"
|
||||
onclick={() => copyToClipboard(subnetInfo!.broadcast.octets.join('.'), 'broadcast')}
|
||||
aria-label="Copy broadcast address"
|
||||
>
|
||||
<SvgIcon icon={copiedStates['broadcast'] ? 'check' : 'clipboard'} size="md" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<span class="info-label">Subnet Mask</span>
|
||||
<div class="value-copy">
|
||||
<code class="ip-value info">{subnetInfo.subnet.octets.join('.')}</code>
|
||||
<span class="cidr">/{subnetInfo.cidr}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<span class="info-label">Wildcard Mask</span>
|
||||
<code class="ip-value warning">{subnetInfo.wildcardMask.octets.join('.')}</code>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Host Info -->
|
||||
<section>
|
||||
<h3 style="margin-bottom: var(--spacing-md); border-bottom: 1px solid var(--border-primary); padding-bottom: var(--spacing-xs);">
|
||||
Host Information
|
||||
</h3>
|
||||
|
||||
<div class="info-cards">
|
||||
<div class="info-card">
|
||||
<span class="info-label">Total Hosts</span>
|
||||
<span class="metric-value info">{formatNumber(subnetInfo.hostCount)}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<span class="info-label">Usable Hosts</span>
|
||||
<span class="metric-value success">{formatNumber(subnetInfo.usableHosts)}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<span class="info-label">First Host</span>
|
||||
<code class="ip-value success">{subnetInfo.firstHost.octets.join('.')}</code>
|
||||
</div>
|
||||
|
||||
<div class="info-card">
|
||||
<span class="info-label">Last Host</span>
|
||||
<code class="ip-value success">{subnetInfo.lastHost.octets.join('.')}</code>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- Binary Representation -->
|
||||
<section class="info-panel" style="margin-top: var(--spacing-lg);">
|
||||
<h3>Binary Representation</h3>
|
||||
<div class="binary-display">
|
||||
<div class="binary-row">
|
||||
<span class="info-label">Network:</span>
|
||||
<code class="binary-value success">{subnetInfo.network.binary}</code>
|
||||
</div>
|
||||
<div class="binary-row">
|
||||
<span class="info-label">Mask:</span>
|
||||
<code class="binary-value info">{subnetInfo.subnet.binary}</code>
|
||||
</div>
|
||||
<div class="binary-row">
|
||||
<span class="info-label">Broadcast:</span>
|
||||
<code class="binary-value error">{subnetInfo.broadcast.binary}</code>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Network Visualization -->
|
||||
<section style="margin-top: var(--spacing-lg);">
|
||||
<NetworkVisualizer {subnetInfo} />
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
<!-- Loading -->
|
||||
{#if isCalculating}
|
||||
<div class="loading" style="justify-content: center; padding: var(--spacing-xl);">
|
||||
<div class="spinner"></div>
|
||||
Calculating subnet...
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Explainer Section -->
|
||||
<section class="explainer-section">
|
||||
<h3>Understanding Subnet Calculations</h3>
|
||||
|
||||
<div class="explainer-grid">
|
||||
<div class="explainer-card">
|
||||
<h4>Network Address</h4>
|
||||
<p>The first IP address in a subnet, used to identify the network itself. Hosts cannot be assigned this address as it represents the entire network segment.</p>
|
||||
</div>
|
||||
|
||||
<div class="explainer-card">
|
||||
<h4>Broadcast Address</h4>
|
||||
<p>The last IP address in a subnet, used to send messages to all devices on the network. When a packet is sent to this address, it reaches every host in the subnet.</p>
|
||||
</div>
|
||||
|
||||
<div class="explainer-card">
|
||||
<h4>Subnet Mask</h4>
|
||||
<p>Defines which portion of an IP address represents the network and which represents the host. A mask of /24 means the first 24 bits identify the network.</p>
|
||||
</div>
|
||||
|
||||
<div class="explainer-card">
|
||||
<h4>Wildcard Mask</h4>
|
||||
<p>The inverse of a subnet mask, used in access control lists. Where the subnet mask has 1s, the wildcard has 0s, and vice versa.</p>
|
||||
</div>
|
||||
|
||||
<div class="explainer-card">
|
||||
<h4>Usable Hosts</h4>
|
||||
<p>The number of IP addresses available for devices. Always 2 less than total addresses because network and broadcast addresses are reserved.</p>
|
||||
</div>
|
||||
|
||||
<div class="explainer-card">
|
||||
<h4>CIDR Notation</h4>
|
||||
<p>Classless Inter-Domain Routing notation (e.g., /24) indicates how many bits are used for the network portion. Higher numbers mean smaller subnets with fewer hosts.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tips-box">
|
||||
<h4>💡 Pro Tips</h4>
|
||||
<ul>
|
||||
<li><strong>Plan for Growth:</strong> Choose subnet sizes that accommodate future expansion</li>
|
||||
<li><strong>Binary Understanding:</strong> Learning binary helps understand how subnetting works</li>
|
||||
<li><strong>Common Sizes:</strong> /24 (254 hosts), /25 (126 hosts), /26 (62 hosts), /30 (2 hosts for point-to-point)</li>
|
||||
<li><strong>Private Networks:</strong> Use RFC 1918 addresses (10.x.x.x, 172.16-31.x.x, 192.168.x.x) for internal networks</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.calculating {
|
||||
opacity: 0.7;
|
||||
pointer-events: none;
|
||||
transition: opacity var(--transition-fast);
|
||||
}
|
||||
|
||||
.explainer-section {
|
||||
margin-top: var(--spacing-xl);
|
||||
padding: var(--spacing-lg);
|
||||
background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px solid var(--border-secondary);
|
||||
}
|
||||
|
||||
.explainer-section h3 {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
text-align: center;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.explainer-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: var(--spacing-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.explainer-card {
|
||||
background-color: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.explainer-card:hover {
|
||||
border-color: color-mix(in srgb, var(--color-primary) 33%, transparent);
|
||||
box-shadow: var(--shadow-md);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.explainer-card h4 {
|
||||
color: var(--color-primary);
|
||||
font-size: var(--font-size-md);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.explainer-card p {
|
||||
color: var(--text-primary);
|
||||
font-size: var(--font-size-sm);
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tips-box {
|
||||
background-color: var(--bg-primary);
|
||||
border: 1px solid var(--color-warning);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
.tips-box h4 {
|
||||
color: var(--color-warning);
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.tips-box ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.tips-box li {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
color: var(--text-primary);
|
||||
font-size: var(--font-size-sm);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.tips-box li::before {
|
||||
content: "•";
|
||||
color: var(--color-warning);
|
||||
font-weight: bold;
|
||||
display: inline-block;
|
||||
width: 1em;
|
||||
margin-right: var(--spacing-xs);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.explainer-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.explainer-section {
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,65 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
icon: 'check' | 'clipboard' | 'close' | 'sun' | 'moon';
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
class?: string;
|
||||
}
|
||||
|
||||
let {
|
||||
icon,
|
||||
size = 'md',
|
||||
class: className = ''
|
||||
}: Props = $props();
|
||||
|
||||
const iconPaths = {
|
||||
check: 'M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z',
|
||||
clipboard: 'M8 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z M6 3a2 2 0 00-2 2v11a2 2 0 002 2h8a2 2 0 002-2V5a2 2 0 00-2-2 3 3 0 01-3 3H9a3 3 0 01-3-3z',
|
||||
close: 'M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z',
|
||||
sun: 'M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z',
|
||||
moon: 'M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z'
|
||||
};
|
||||
|
||||
const sizeClass = {
|
||||
sm: 'icon-sm',
|
||||
md: 'icon-md',
|
||||
lg: 'icon-lg'
|
||||
}[size];
|
||||
</script>
|
||||
|
||||
<svg fill="currentColor" viewBox="0 0 20 20" class="{sizeClass} {className}">
|
||||
{#if icon === 'check'}
|
||||
<path fill-rule="evenodd" d="{iconPaths.check}" clip-rule="evenodd"/>
|
||||
{:else if icon === 'clipboard'}
|
||||
{#each iconPaths.clipboard.split(' M') as pathData, i}
|
||||
<path d="{i === 0 ? pathData : 'M' + pathData}"/>
|
||||
{/each}
|
||||
{:else if icon === 'close'}
|
||||
<path fill-rule="evenodd" d="{iconPaths.close}" clip-rule="evenodd"/>
|
||||
{:else if icon === 'sun'}
|
||||
<path fill-rule="evenodd" d="{iconPaths.sun}" clip-rule="evenodd"/>
|
||||
{:else if icon === 'moon'}
|
||||
<path d="{iconPaths.moon}"/>
|
||||
{/if}
|
||||
</svg>
|
||||
|
||||
<style>
|
||||
svg {
|
||||
display: inline-block;
|
||||
color: currentColor;
|
||||
}
|
||||
|
||||
.icon-sm {
|
||||
width: 0.75rem;
|
||||
height: 0.75rem;
|
||||
}
|
||||
|
||||
.icon-md {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
|
||||
.icon-lg {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,134 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
text: string;
|
||||
position?: 'top' | 'bottom' | 'left' | 'right';
|
||||
delay?: number;
|
||||
children: any;
|
||||
}
|
||||
|
||||
let {
|
||||
text,
|
||||
position = 'top',
|
||||
delay = 500,
|
||||
children
|
||||
}: Props = $props();
|
||||
|
||||
let showTooltip = $state(false);
|
||||
let tooltipTimeout: NodeJS.Timeout;
|
||||
|
||||
/**
|
||||
* Show tooltip after delay
|
||||
*/
|
||||
function handleMouseEnter() {
|
||||
tooltipTimeout = setTimeout(() => {
|
||||
showTooltip = true;
|
||||
}, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide tooltip immediately
|
||||
*/
|
||||
function handleMouseLeave() {
|
||||
clearTimeout(tooltipTimeout);
|
||||
showTooltip = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="tooltip-container"
|
||||
onmouseenter={handleMouseEnter}
|
||||
onmouseleave={handleMouseLeave}
|
||||
>
|
||||
{@render children()}
|
||||
|
||||
{#if showTooltip}
|
||||
<div class="tooltip {position}">
|
||||
{text}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.tooltip-container {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
position: absolute;
|
||||
z-index: 1000;
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: var(--font-size-xs);
|
||||
white-space: nowrap;
|
||||
box-shadow: var(--shadow-lg);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.tooltip::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 4px solid transparent;
|
||||
}
|
||||
|
||||
.tooltip.top {
|
||||
bottom: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.tooltip.top::before {
|
||||
top: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
border-top-color: var(--border-primary);
|
||||
}
|
||||
|
||||
.tooltip.bottom {
|
||||
top: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.tooltip.bottom::before {
|
||||
bottom: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
border-bottom-color: var(--border-primary);
|
||||
}
|
||||
|
||||
.tooltip.left {
|
||||
right: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
margin-right: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.tooltip.left::before {
|
||||
left: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
border-left-color: var(--border-primary);
|
||||
}
|
||||
|
||||
.tooltip.right {
|
||||
left: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
margin-left: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.tooltip.right::before {
|
||||
right: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
border-right-color: var(--border-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,74 @@
|
||||
// Standard network classes and reserved ranges
|
||||
export const NETWORK_CLASSES = {
|
||||
A: {
|
||||
range: '1.0.0.0 - 126.255.255.255',
|
||||
defaultMask: '255.0.0.0',
|
||||
cidr: 8,
|
||||
description: 'Large networks (16.7M hosts per network)',
|
||||
usage: 'Large corporations, ISPs'
|
||||
},
|
||||
B: {
|
||||
range: '128.0.0.0 - 191.255.255.255',
|
||||
defaultMask: '255.255.0.0',
|
||||
cidr: 16,
|
||||
description: 'Medium networks (65K hosts per network)',
|
||||
usage: 'Universities, large organizations'
|
||||
},
|
||||
C: {
|
||||
range: '192.0.0.0 - 223.255.255.255',
|
||||
defaultMask: '255.255.255.0',
|
||||
cidr: 24,
|
||||
description: 'Small networks (254 hosts per network)',
|
||||
usage: 'Small businesses, home networks'
|
||||
}
|
||||
} as const;
|
||||
|
||||
export const RESERVED_RANGES = {
|
||||
LOCALHOST: {
|
||||
range: '127.0.0.0/8',
|
||||
description: 'Loopback addresses',
|
||||
rfc: 'RFC 1122'
|
||||
},
|
||||
PRIVATE_A: {
|
||||
range: '10.0.0.0/8',
|
||||
description: 'Private network (Class A)',
|
||||
rfc: 'RFC 1918'
|
||||
},
|
||||
PRIVATE_B: {
|
||||
range: '172.16.0.0/12',
|
||||
description: 'Private network (Class B)',
|
||||
rfc: 'RFC 1918'
|
||||
},
|
||||
PRIVATE_C: {
|
||||
range: '192.168.0.0/16',
|
||||
description: 'Private network (Class C)',
|
||||
rfc: 'RFC 1918'
|
||||
},
|
||||
LINK_LOCAL: {
|
||||
range: '169.254.0.0/16',
|
||||
description: 'Link-local addresses',
|
||||
rfc: 'RFC 3927'
|
||||
},
|
||||
MULTICAST: {
|
||||
range: '224.0.0.0/4',
|
||||
description: 'Multicast addresses',
|
||||
rfc: 'RFC 1112'
|
||||
},
|
||||
BROADCAST: {
|
||||
range: '255.255.255.255/32',
|
||||
description: 'Limited broadcast',
|
||||
rfc: 'RFC 919'
|
||||
}
|
||||
} as const;
|
||||
|
||||
export const COMMON_SUBNETS = [
|
||||
{ cidr: 8, mask: '255.0.0.0', hosts: 16777214 },
|
||||
{ cidr: 16, mask: '255.255.0.0', hosts: 65534 },
|
||||
{ cidr: 24, mask: '255.255.255.0', hosts: 254 },
|
||||
{ cidr: 25, mask: '255.255.255.128', hosts: 126 },
|
||||
{ cidr: 26, mask: '255.255.255.192', hosts: 62 },
|
||||
{ cidr: 27, mask: '255.255.255.224', hosts: 30 },
|
||||
{ cidr: 28, mask: '255.255.255.240', hosts: 14 },
|
||||
{ cidr: 29, mask: '255.255.255.248', hosts: 6 },
|
||||
{ cidr: 30, mask: '255.255.255.252', hosts: 2 }
|
||||
] as const;
|
||||
@@ -0,0 +1 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
||||
@@ -0,0 +1,40 @@
|
||||
// Core IP address types and interfaces
|
||||
export interface IPAddress {
|
||||
octets: number[];
|
||||
binary: string;
|
||||
decimal: number;
|
||||
hex: string;
|
||||
valid: boolean;
|
||||
}
|
||||
|
||||
export interface SubnetInfo {
|
||||
network: IPAddress;
|
||||
broadcast: IPAddress;
|
||||
subnet: IPAddress;
|
||||
cidr: number;
|
||||
hostCount: number;
|
||||
usableHosts: number;
|
||||
firstHost: IPAddress;
|
||||
lastHost: IPAddress;
|
||||
wildcardMask: IPAddress;
|
||||
}
|
||||
|
||||
export interface NetworkRange {
|
||||
start: IPAddress;
|
||||
end: IPAddress;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export type IPVersion = 'v4' | 'v6';
|
||||
|
||||
export interface ValidationResult {
|
||||
valid: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface ConversionFormats {
|
||||
binary: string;
|
||||
decimal: string;
|
||||
hex: string;
|
||||
octal: string;
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import type { IPAddress, SubnetInfo } from '../types/ip.js';
|
||||
|
||||
/**
|
||||
* Converts IP string to IPAddress object
|
||||
*/
|
||||
export function parseIP(ip: string): IPAddress {
|
||||
const octets = ip.split('.').map(Number);
|
||||
const binary = octets.map(n => n.toString(2).padStart(8, '0')).join('.');
|
||||
const decimal = octets.reduce((acc, octet, i) => acc + octet * Math.pow(256, 3 - i), 0);
|
||||
const hex = octets.map(n => n.toString(16).padStart(2, '0').toUpperCase()).join('.');
|
||||
|
||||
return {
|
||||
octets,
|
||||
binary,
|
||||
decimal,
|
||||
hex,
|
||||
valid: true
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts CIDR prefix to subnet mask
|
||||
*/
|
||||
export function cidrToMask(cidr: number): IPAddress {
|
||||
const mask = (0xffffffff << (32 - cidr)) >>> 0;
|
||||
const octets = [
|
||||
(mask >>> 24) & 0xff,
|
||||
(mask >>> 16) & 0xff,
|
||||
(mask >>> 8) & 0xff,
|
||||
mask & 0xff
|
||||
];
|
||||
|
||||
return parseIP(octets.join('.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts subnet mask to CIDR prefix
|
||||
*/
|
||||
export function maskToCidr(mask: string): number {
|
||||
const octets = mask.split('.').map(Number);
|
||||
const binary = octets.map(n => n.toString(2).padStart(8, '0')).join('');
|
||||
return binary.split('1').length - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates network address
|
||||
*/
|
||||
export function getNetworkAddress(ip: string, cidr: number): IPAddress {
|
||||
const ipNum = ipToNumber(ip);
|
||||
const mask = (0xffffffff << (32 - cidr)) >>> 0;
|
||||
const networkNum = (ipNum & mask) >>> 0;
|
||||
|
||||
return numberToIP(networkNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates broadcast address
|
||||
*/
|
||||
export function getBroadcastAddress(ip: string, cidr: number): IPAddress {
|
||||
const networkNum = ipToNumber(getNetworkAddress(ip, cidr).octets.join('.'));
|
||||
const hostBits = 32 - cidr;
|
||||
const broadcastNum = networkNum + Math.pow(2, hostBits) - 1;
|
||||
|
||||
return numberToIP(broadcastNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates complete subnet information
|
||||
*/
|
||||
export function calculateSubnet(ip: string, cidr: number): SubnetInfo {
|
||||
const network = getNetworkAddress(ip, cidr);
|
||||
const broadcast = getBroadcastAddress(ip, cidr);
|
||||
const subnet = cidrToMask(cidr);
|
||||
const wildcardMask = getWildcardMask(cidr);
|
||||
|
||||
const hostBits = 32 - cidr;
|
||||
const hostCount = Math.pow(2, hostBits);
|
||||
const usableHosts = hostCount > 2 ? hostCount - 2 : 0;
|
||||
|
||||
const firstHost = numberToIP(ipToNumber(network.octets.join('.')) + 1);
|
||||
const lastHost = numberToIP(ipToNumber(broadcast.octets.join('.')) - 1);
|
||||
|
||||
return {
|
||||
network,
|
||||
broadcast,
|
||||
subnet,
|
||||
cidr,
|
||||
hostCount,
|
||||
usableHosts,
|
||||
firstHost,
|
||||
lastHost,
|
||||
wildcardMask
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates wildcard mask
|
||||
*/
|
||||
export function getWildcardMask(cidr: number): IPAddress {
|
||||
const mask = cidrToMask(cidr);
|
||||
const wildcardOctets = mask.octets.map(octet => 255 - octet);
|
||||
|
||||
return parseIP(wildcardOctets.join('.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts IP address to 32-bit number
|
||||
*/
|
||||
function ipToNumber(ip: string): number {
|
||||
const octets = ip.split('.').map(Number);
|
||||
return (octets[0] << 24 | octets[1] << 16 | octets[2] << 8 | octets[3]) >>> 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts 32-bit number to IP address
|
||||
*/
|
||||
function numberToIP(num: number): IPAddress {
|
||||
const octets = [
|
||||
(num >>> 24) & 0xff,
|
||||
(num >>> 16) & 0xff,
|
||||
(num >>> 8) & 0xff,
|
||||
num & 0xff
|
||||
];
|
||||
|
||||
return parseIP(octets.join('.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if IP is in subnet range
|
||||
*/
|
||||
export function isIPInSubnet(ip: string, subnet: string, cidr: number): boolean {
|
||||
const ipNum = ipToNumber(ip);
|
||||
const subnetNum = ipToNumber(subnet);
|
||||
const mask = (0xffffffff << (32 - cidr)) >>> 0;
|
||||
|
||||
return ((ipNum & mask) >>> 0) === ((subnetNum & mask) >>> 0);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import type { ConversionFormats } from '../types/ip.js';
|
||||
|
||||
/**
|
||||
* Converts IP address to various number formats
|
||||
*/
|
||||
export function convertIPFormats(ip: string): ConversionFormats {
|
||||
const octets = ip.split('.').map(Number);
|
||||
|
||||
const binary = octets
|
||||
.map(octet => octet.toString(2).padStart(8, '0'))
|
||||
.join('.');
|
||||
|
||||
const decimal = octets
|
||||
.reduce((acc, octet, i) => acc + octet * Math.pow(256, 3 - i), 0)
|
||||
.toString();
|
||||
|
||||
const hex = octets
|
||||
.map(octet => '0x' + octet.toString(16).padStart(2, '0').toUpperCase())
|
||||
.join('.');
|
||||
|
||||
const octal = octets
|
||||
.map(octet => '0' + octet.toString(8))
|
||||
.join('.');
|
||||
|
||||
return { binary, decimal, hex, octal };
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts decimal number to IP address
|
||||
*/
|
||||
export function decimalToIP(decimal: number): string {
|
||||
const octets = [
|
||||
(decimal >>> 24) & 0xff,
|
||||
(decimal >>> 16) & 0xff,
|
||||
(decimal >>> 8) & 0xff,
|
||||
decimal & 0xff
|
||||
];
|
||||
|
||||
return octets.join('.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts binary string to IP address
|
||||
*/
|
||||
export function binaryToIP(binary: string): string {
|
||||
// Remove dots and spaces
|
||||
const cleanBinary = binary.replace(/[.\s]/g, '');
|
||||
|
||||
if (cleanBinary.length !== 32) {
|
||||
throw new Error('Binary string must be 32 bits');
|
||||
}
|
||||
|
||||
const octets = [];
|
||||
for (let i = 0; i < 32; i += 8) {
|
||||
const octetBinary = cleanBinary.slice(i, i + 8);
|
||||
octets.push(parseInt(octetBinary, 2));
|
||||
}
|
||||
|
||||
return octets.join('.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts hex string to IP address
|
||||
*/
|
||||
export function hexToIP(hex: string): string {
|
||||
// Remove 0x prefix and dots
|
||||
const cleanHex = hex.replace(/0x/g, '').replace(/\./g, '');
|
||||
|
||||
if (cleanHex.length !== 8) {
|
||||
throw new Error('Hex string must be 8 characters');
|
||||
}
|
||||
|
||||
const octets = [];
|
||||
for (let i = 0; i < 8; i += 2) {
|
||||
const octetHex = cleanHex.slice(i, i + 2);
|
||||
octets.push(parseInt(octetHex, 16));
|
||||
}
|
||||
|
||||
return octets.join('.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets IP class information
|
||||
*/
|
||||
export function getIPClass(ip: string): { class: string; type: string; description: string } {
|
||||
const firstOctet = parseInt(ip.split('.')[0]);
|
||||
|
||||
if (firstOctet >= 1 && firstOctet <= 126) {
|
||||
return {
|
||||
class: 'A',
|
||||
type: 'Unicast',
|
||||
description: 'Large networks'
|
||||
};
|
||||
} else if (firstOctet >= 128 && firstOctet <= 191) {
|
||||
return {
|
||||
class: 'B',
|
||||
type: 'Unicast',
|
||||
description: 'Medium networks'
|
||||
};
|
||||
} else if (firstOctet >= 192 && firstOctet <= 223) {
|
||||
return {
|
||||
class: 'C',
|
||||
type: 'Unicast',
|
||||
description: 'Small networks'
|
||||
};
|
||||
} else if (firstOctet >= 224 && firstOctet <= 239) {
|
||||
return {
|
||||
class: 'D',
|
||||
type: 'Multicast',
|
||||
description: 'Multicast addresses'
|
||||
};
|
||||
} else if (firstOctet >= 240 && firstOctet <= 255) {
|
||||
return {
|
||||
class: 'E',
|
||||
type: 'Reserved',
|
||||
description: 'Experimental/Reserved'
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
class: 'Invalid',
|
||||
type: 'Invalid',
|
||||
description: 'Invalid IP address'
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import type { ValidationResult } from '../types/ip.js';
|
||||
|
||||
/**
|
||||
* Validates an IPv4 address string
|
||||
*/
|
||||
export function validateIPv4(ip: string): ValidationResult {
|
||||
if (!ip || typeof ip !== 'string') {
|
||||
return { valid: false, error: 'IP address is required' };
|
||||
}
|
||||
|
||||
const octets = ip.trim().split('.');
|
||||
|
||||
if (octets.length !== 4) {
|
||||
return { valid: false, error: 'IPv4 address must have 4 octets' };
|
||||
}
|
||||
|
||||
for (let i = 0; i < octets.length; i++) {
|
||||
const octet = octets[i];
|
||||
|
||||
if (!/^\d+$/.test(octet)) {
|
||||
return { valid: false, error: `Octet ${i + 1} contains non-numeric characters` };
|
||||
}
|
||||
|
||||
const num = parseInt(octet, 10);
|
||||
|
||||
if (num < 0 || num > 255) {
|
||||
return { valid: false, error: `Octet ${i + 1} must be between 0-255` };
|
||||
}
|
||||
|
||||
if (octet.length > 1 && octet[0] === '0') {
|
||||
return { valid: false, error: `Octet ${i + 1} has leading zeros` };
|
||||
}
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates CIDR notation
|
||||
*/
|
||||
export function validateCIDR(cidr: string): ValidationResult {
|
||||
if (!cidr) {
|
||||
return { valid: false, error: 'CIDR notation is required' };
|
||||
}
|
||||
|
||||
const parts = cidr.split('/');
|
||||
|
||||
if (parts.length !== 2) {
|
||||
return { valid: false, error: 'CIDR must be in format IP/prefix' };
|
||||
}
|
||||
|
||||
const ipValidation = validateIPv4(parts[0]);
|
||||
if (!ipValidation.valid) {
|
||||
return ipValidation;
|
||||
}
|
||||
|
||||
const prefix = parseInt(parts[1], 10);
|
||||
if (isNaN(prefix) || prefix < 0 || prefix > 32) {
|
||||
return { valid: false, error: 'CIDR prefix must be between 0-32' };
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates subnet mask
|
||||
*/
|
||||
export function validateSubnetMask(mask: string): ValidationResult {
|
||||
const validation = validateIPv4(mask);
|
||||
if (!validation.valid) {
|
||||
return validation;
|
||||
}
|
||||
|
||||
const octets = mask.split('.').map(Number);
|
||||
const binary = octets.map(n => n.toString(2).padStart(8, '0')).join('');
|
||||
|
||||
// Check if mask is contiguous (all 1s followed by all 0s)
|
||||
if (!/^1*0*$/.test(binary)) {
|
||||
return { valid: false, error: 'Subnet mask must be contiguous' };
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import '../app.css';
|
||||
import favicon from '$lib/assets/favicon.svg';
|
||||
|
||||
let { children } = $props();
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<link rel="icon" href={favicon} />
|
||||
</svelte:head>
|
||||
|
||||
{@render children?.()}
|
||||
@@ -0,0 +1,174 @@
|
||||
<script lang="ts">
|
||||
import SubnetCalculator from '$lib/components/SubnetCalculator.svelte';
|
||||
import CIDRConverter from '$lib/components/CIDRConverter.svelte';
|
||||
import IPConverter from '$lib/components/IPConverter.svelte';
|
||||
import InfoPanel from '$lib/components/InfoPanel.svelte';
|
||||
|
||||
let activeTab = $state<'subnet' | 'cidr' | 'converter' | 'reference'>('subnet');
|
||||
let darkMode = $state(true); // Default to hacker theme
|
||||
|
||||
/**
|
||||
* Initialize theme from localStorage
|
||||
*/
|
||||
function initializeTheme() {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
const saved = localStorage.getItem('theme');
|
||||
if (saved === 'light') {
|
||||
darkMode = false;
|
||||
document.documentElement.classList.add('theme-light');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle theme
|
||||
*/
|
||||
function toggleTheme() {
|
||||
darkMode = !darkMode;
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem('theme', darkMode ? 'dark' : 'light');
|
||||
if (darkMode) {
|
||||
document.documentElement.classList.remove('theme-light');
|
||||
} else {
|
||||
document.documentElement.classList.add('theme-light');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize on mount
|
||||
$effect(() => {
|
||||
initializeTheme();
|
||||
});
|
||||
|
||||
const tabs = [
|
||||
{ id: 'subnet' as const, label: 'Subnet Calc' },
|
||||
{ id: 'cidr' as const, label: 'CIDR Convert' },
|
||||
{ id: 'converter' as const, label: 'IP Convert' },
|
||||
{ id: 'reference' as const, label: 'Reference' }
|
||||
];
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>IP Calc - Network Calculator</title>
|
||||
<meta name="description" content="IP address calculator with subnet calculations, CIDR conversion, and network analysis tools." />
|
||||
<meta name="keywords" content="IP calculator, subnet calculator, CIDR converter, network tools" />
|
||||
<meta property="og:title" content="IP Calc" />
|
||||
<meta property="og:description" content="Network calculator and IP tools" />
|
||||
<meta property="og:type" content="website" />
|
||||
</svelte:head>
|
||||
|
||||
<div class="page">
|
||||
<!-- Header -->
|
||||
<header class="header">
|
||||
<div class="container">
|
||||
<div class="header-content">
|
||||
<div class="logo">
|
||||
<div class="logo-icon">
|
||||
<svg fill="currentColor" viewBox="0 0 24 24">
|
||||
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h1>IP Calc</h1>
|
||||
<p class="subtitle">Network Calculator</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="theme-toggle"
|
||||
class:dark={darkMode}
|
||||
onclick={toggleTheme}
|
||||
aria-label={darkMode ? 'Switch to light mode' : 'Switch to dark mode'}
|
||||
>
|
||||
<div class="toggle-slider">
|
||||
{#if darkMode}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"/>
|
||||
</svg>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
<div class="container">
|
||||
<!-- Tab Navigation -->
|
||||
<nav class="tabs">
|
||||
{#each tabs as tab}
|
||||
<button
|
||||
type="button"
|
||||
class="tab"
|
||||
class:active={activeTab === tab.id}
|
||||
onclick={() => activeTab = tab.id}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
{/each}
|
||||
</nav>
|
||||
|
||||
<!-- Tab Content -->
|
||||
<div class="fade-in">
|
||||
{#if activeTab === 'subnet'}
|
||||
<SubnetCalculator />
|
||||
{:else if activeTab === 'cidr'}
|
||||
<CIDRConverter />
|
||||
{:else if activeTab === 'converter'}
|
||||
<IPConverter />
|
||||
{:else if activeTab === 'reference'}
|
||||
<InfoPanel />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="footer">
|
||||
<div class="footer-content">
|
||||
<p>Built with 🩷 and 🍺 by <a href="https://github.com/lissy93" target="_blank" rel="noopener noreferrer">Lissy93</a>. <a href="https://github.com/lissy93/ip-calc" target="_blank" rel="noopener noreferrer">View on GitHub</a></p>
|
||||
<p class="footer-sub"><a href="https://ip-calc.as93.net" target="_blank" rel="noopener noreferrer">IP-Calc</a> is licensed under <a href="https://github.com/lissy93/ip-calc/blob/main/LICENSE" target="_blank" rel="noopener noreferrer">MIT</a>, (C) <a href="https://github.com/lissy93" target="_blank" rel="noopener noreferrer">Alicia Sykes</a> 2025</p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding: var(--spacing-lg);
|
||||
border-top: 1px solid var(--border-primary);
|
||||
margin-top: var(--spacing-xl);
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.footer-content p {
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-sm);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.footer-sub {
|
||||
font-size: var(--font-size-xs) !important;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
transition: color var(--transition-fast);
|
||||
}
|
||||
|
||||
.footer a:hover {
|
||||
color: var(--color-primary-light);
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,168 @@
|
||||
@import './variables.scss';
|
||||
|
||||
// Reset and base styles
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 16px;
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
line-height: 1.5;
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-primary);
|
||||
transition: background-color var(--transition-normal), color var(--transition-normal);
|
||||
}
|
||||
|
||||
// Base typography
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
h1 { font-size: var(--font-size-2xl); }
|
||||
h2 { font-size: var(--font-size-xl); }
|
||||
h3 { font-size: var(--font-size-lg); }
|
||||
|
||||
p {
|
||||
margin-bottom: var(--spacing-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
// Links
|
||||
a {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
transition: color var(--transition-fast);
|
||||
|
||||
&:hover {
|
||||
color: var(--color-primary-hover);
|
||||
}
|
||||
}
|
||||
|
||||
// Form elements
|
||||
input, select, textarea {
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
transition: all var(--transition-fast);
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 2px rgba(219, 244, 101, 0.2);
|
||||
}
|
||||
|
||||
&::placeholder {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
// Buttons
|
||||
button {
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
transition: all var(--transition-fast);
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-primary);
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background-color: var(--surface-hover);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
&:active:not(:disabled) {
|
||||
background-color: var(--surface-active);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
// Primary button variant
|
||||
&.btn-primary {
|
||||
background-color: var(--color-primary);
|
||||
color: var(--bg-primary);
|
||||
border-color: var(--color-primary);
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background-color: var(--color-primary-hover);
|
||||
border-color: var(--color-primary-hover);
|
||||
}
|
||||
}
|
||||
|
||||
// Icon buttons
|
||||
&.btn-icon {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
svg {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Labels
|
||||
label {
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
display: block;
|
||||
}
|
||||
|
||||
// Code and monospace elements
|
||||
code, pre {
|
||||
font-family: var(--font-mono);
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: var(--spacing-md);
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
// Utility classes
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
@import './variables.scss';
|
||||
|
||||
// Layout components
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 var(--spacing-md);
|
||||
}
|
||||
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
|
||||
}
|
||||
|
||||
.main-content {
|
||||
padding: var(--spacing-lg) 0;
|
||||
}
|
||||
|
||||
// Header
|
||||
.header {
|
||||
background-color: var(--bg-secondary);
|
||||
border-bottom: 1px solid var(--border-primary);
|
||||
padding: var(--spacing-md) 0;
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
|
||||
.logo-icon {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
|
||||
border-radius: var(--radius-md);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
svg {
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
color: var(--bg-primary);
|
||||
}
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: var(--font-size-xl);
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cards
|
||||
.card {
|
||||
background-color: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-lg);
|
||||
box-shadow: var(--shadow-sm);
|
||||
|
||||
.card-header {
|
||||
margin-bottom: var(--spacing-md);
|
||||
|
||||
h2 {
|
||||
font-size: var(--font-size-lg);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tabs
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: var(--spacing-xs);
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-xs);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
|
||||
.tab {
|
||||
flex: 1;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border-radius: var(--radius-md);
|
||||
text-align: center;
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
transition: all var(--transition-fast);
|
||||
|
||||
&.active {
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--color-primary);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Form groups
|
||||
.form-group {
|
||||
margin-bottom: var(--spacing-md);
|
||||
|
||||
&.inline {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
gap: var(--spacing-sm);
|
||||
|
||||
.form-field {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-field {
|
||||
.field-input {
|
||||
position: relative;
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding-right: 2.5rem;
|
||||
}
|
||||
|
||||
.field-icon {
|
||||
position: absolute;
|
||||
right: var(--spacing-sm);
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
|
||||
&.success {
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: var(--color-error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.field-error {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--color-error);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.field-help {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--text-secondary);
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
}
|
||||
|
||||
// Grid layouts
|
||||
.grid {
|
||||
display: grid;
|
||||
gap: var(--spacing-md);
|
||||
|
||||
&.grid-2 {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
&.grid-3 {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
&.grid-4 {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
&.grid-2, &.grid-3, &.grid-4 {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Info panels
|
||||
.info-panel {
|
||||
background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-md);
|
||||
|
||||
&.success {
|
||||
border-color: var(--color-success);
|
||||
background: linear-gradient(135deg,
|
||||
rgba(35, 134, 54, 0.1),
|
||||
rgba(46, 160, 67, 0.05));
|
||||
}
|
||||
|
||||
&.info {
|
||||
border-color: var(--color-info);
|
||||
background: linear-gradient(135deg,
|
||||
rgba(9, 105, 218, 0.1),
|
||||
rgba(31, 111, 235, 0.05));
|
||||
}
|
||||
|
||||
&.warning {
|
||||
border-color: var(--color-warning);
|
||||
background: linear-gradient(135deg,
|
||||
rgba(210, 153, 34, 0.1),
|
||||
rgba(251, 133, 0, 0.05));
|
||||
}
|
||||
}
|
||||
|
||||
// Status indicators
|
||||
.status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
font-size: var(--font-size-xs);
|
||||
font-weight: 600;
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
|
||||
&.success {
|
||||
color: var(--color-success-light);
|
||||
background-color: rgba(35, 134, 54, 0.15);
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: var(--color-error-light);
|
||||
background-color: rgba(218, 54, 51, 0.15);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
color: var(--color-warning-light);
|
||||
background-color: rgba(210, 153, 34, 0.15);
|
||||
}
|
||||
|
||||
&.info {
|
||||
color: var(--color-info-light);
|
||||
background-color: rgba(9, 105, 218, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
// Loading and animations
|
||||
.loading {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
|
||||
.spinner {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
border: 2px solid var(--border-primary);
|
||||
border-top: 2px solid var(--color-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(0.5rem);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.fade-in {
|
||||
animation: fadeIn 0.3s ease-out;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// Theme Colors
|
||||
:root {
|
||||
// Background colors
|
||||
--bg-primary: #0d1117;
|
||||
--bg-secondary: #161b22;
|
||||
--bg-tertiary: #21262d;
|
||||
|
||||
// Text colors
|
||||
--text-primary: #c9d1d9;
|
||||
--text-secondary: #7d8590;
|
||||
|
||||
// Primary brand color
|
||||
--color-primary: #dbf465;
|
||||
--color-primary-hover: #c5e146;
|
||||
--color-primary-dark: #a8c237;
|
||||
|
||||
// Action colors
|
||||
--color-success: #238636;
|
||||
--color-success-light: #2ea043;
|
||||
--color-warning: #d29922;
|
||||
--color-warning-light: #fb8500;
|
||||
--color-error: #da3633;
|
||||
--color-error-light: #f85149;
|
||||
--color-info: #0969da;
|
||||
--color-info-light: #1f6feb;
|
||||
|
||||
// Border and surface colors
|
||||
--border-primary: #30363d;
|
||||
--border-secondary: #21262d;
|
||||
--surface-hover: #262c36;
|
||||
--surface-active: #2f3640;
|
||||
|
||||
// Shadows
|
||||
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
|
||||
--shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
|
||||
--shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
|
||||
|
||||
// Border radius
|
||||
--radius-sm: 4px;
|
||||
--radius-md: 6px;
|
||||
--radius-lg: 8px;
|
||||
|
||||
// Spacing (using rem for scalability)
|
||||
--spacing-xs: 0.25rem;
|
||||
--spacing-sm: 0.5rem;
|
||||
--spacing-md: 1rem;
|
||||
--spacing-lg: 1.5rem;
|
||||
--spacing-xl: 2rem;
|
||||
|
||||
// Font
|
||||
--font-mono: 'Roboto Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
|
||||
--font-size-xs: 0.75rem;
|
||||
--font-size-sm: 0.875rem;
|
||||
--font-size-md: 1rem;
|
||||
--font-size-lg: 1.125rem;
|
||||
--font-size-xl: 1.25rem;
|
||||
--font-size-2xl: 1.5rem;
|
||||
|
||||
// Transitions
|
||||
--transition-fast: 0.15s ease;
|
||||
--transition-normal: 0.2s ease;
|
||||
--transition-slow: 0.3s ease;
|
||||
}
|
||||
|
||||
// Light mode overrides (for future use)
|
||||
.theme-light {
|
||||
--bg-primary: #ffffff;
|
||||
--bg-secondary: #f6f8fa;
|
||||
--bg-tertiary: #f0f2f5;
|
||||
--text-primary: #24292f;
|
||||
--text-secondary: #656d76;
|
||||
--border-primary: #d1d9e0;
|
||||
--border-secondary: #d8dee4;
|
||||
--surface-hover: #f3f4f6;
|
||||
--surface-active: #e5e7ea;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# allow crawling everything by default
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -0,0 +1,18 @@
|
||||
import adapter from '@sveltejs/adapter-auto';
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://svelte.dev/docs/kit/integrations
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
|
||||
kit: {
|
||||
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
|
||||
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
||||
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler"
|
||||
}
|
||||
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
|
||||
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
|
||||
//
|
||||
// To make changes to top-level options such as include and exclude, we recommend extending
|
||||
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [sveltekit()]
|
||||
});
|
||||
Reference in new issue
Block a user