Refactored a lot of things.

This commit is contained in:
Alicia Sykes committed 2025-10-16 06:59:32 +01:00
1 parent d05f26d592
commit 5b5f0f7fe1
30 files changed
+2336 -1335

No files matched your search

@@ -0,0 +1,167 @@
<script lang="ts" generics="T extends string">
import { goto } from '$app/navigation';
import Icon from '$lib/components/global/Icon.svelte';
import { tooltip } from '$lib/actions/tooltip.js';
interface Option {
value: T;
label: string;
icon?: string;
href?: string;
}
interface Props {
options: Option[];
value: T;
onchange?: (value: T) => void;
class?: string;
hideLabel?: boolean;
}
let { options, value = $bindable(), onchange, class: className = '', hideLabel = false }: Props = $props();
let buttonsContainer: HTMLDivElement;
// Track the active indicator position and width
let indicatorStyle = $state('');
// Check if all options have icons
const allHaveIcons = $derived(options.every((opt) => opt.icon));
const shouldHideLabel = $derived(hideLabel && allHaveIcons);
// Update indicator position when value or hideLabel changes
$effect(() => {
if (buttonsContainer && value) {
// Use requestAnimationFrame to ensure DOM has updated after hideLabel changes
requestAnimationFrame(() => {
const buttons = Array.from(buttonsContainer.querySelectorAll('button'));
const activeIndex = options.findIndex((opt) => opt.value === value);
const button = buttons[activeIndex] as HTMLButtonElement | undefined;
if (button) {
updateIndicator(button);
}
});
}
});
function updateIndicator(button: HTMLButtonElement) {
if (!buttonsContainer) return;
const containerRect = buttonsContainer.getBoundingClientRect();
const buttonRect = button.getBoundingClientRect();
const left = buttonRect.left - containerRect.left;
const width = buttonRect.width;
indicatorStyle = `transform: translateX(${left}px); width: ${width}px;`;
}
function handleClick(option: Option) {
value = option.value;
if (option.href) {
goto(option.href);
} else if (onchange) {
onchange(option.value);
}
}
</script>
<div class="segmented-control {className}">
<div class="buttons-container" bind:this={buttonsContainer}>
<div class="active-indicator" style={indicatorStyle}></div>
{#each options as option (option.value)}
<button
class="segment-btn"
class:active={value === option.value}
class:icon-only={shouldHideLabel && option.icon}
onclick={() => handleClick(option)}
aria-pressed={value === option.value}
use:tooltip={shouldHideLabel ? option.label : undefined}
>
{#if option.icon}
<Icon name={option.icon} size="sm" />
{/if}
{#if !shouldHideLabel}
<span class="segment-label">{option.label}</span>
{/if}
</button>
{/each}
</div>
</div>
<style lang="scss">
.segmented-control {
display: inline-flex;
}
.buttons-container {
position: relative;
display: flex;
gap: var(--spacing-xs);
background: var(--bg-secondary);
padding: var(--spacing-xs);
border-radius: var(--radius-md);
border: 1px solid var(--border-primary);
}
.active-indicator {
position: absolute;
top: var(--spacing-xs);
left: var(--spacing-xs);
height: calc(100% - calc(var(--spacing-xs) * 2));
background: var(--color-primary);
border-radius: var(--radius-sm);
transition:
transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
pointer-events: none;
z-index: 0;
}
.segment-btn {
position: relative;
z-index: 1;
display: flex;
align-items: center;
gap: var(--spacing-xs);
padding: var(--spacing-xs) var(--spacing-sm);
background: transparent;
color: var(--text-secondary);
font-size: var(--font-size-sm);
border: none;
border-radius: var(--radius-sm);
cursor: pointer;
transition: color var(--transition-fast);
white-space: nowrap;
:global(svg) {
color: var(--text-secondary);
transition: color var(--transition-fast);
}
&:hover {
color: var(--text-primary);
:global(svg) {
color: var(--text-primary);
}
}
&.active {
color: var(--bg-primary);
background: var(--color-primary);
:global(svg) {
color: var(--bg-primary);
}
}
&.icon-only {
padding: var(--spacing-xs);
min-width: 2rem;
justify-content: center;
}
}
</style>
@@ -0,0 +1,78 @@
<script lang="ts" generics="T extends string">
import { onMount } from 'svelte';
import SegmentedControl from '$lib/components/global/SegmentedControl.svelte';
import type { Snippet } from 'svelte';
interface NavOption {
value: T;
label: string;
icon?: string;
href?: string;
}
interface Props {
title: string;
description: string;
navOptions?: NavOption[];
selectedNav?: T;
onNavChange?: (value: T) => void;
contentClass?: string;
children: Snippet;
hideLabels?: boolean;
}
let {
title,
description,
navOptions,
selectedNav = $bindable(),
onNavChange,
contentClass,
children,
hideLabels: propHideLabels = false,
}: Props = $props();
let hideLabels = $state(false);
function updateHideLabels() {
hideLabels = propHideLabels || window.innerWidth < 768;
}
onMount(() => {
updateHideLabels();
window.addEventListener('resize', updateHideLabels);
return () => window.removeEventListener('resize', updateHideLabels);
});
</script>
<div class="card">
<header class="card-header">
<div class="header-content">
<h2>{title}</h2>
<p>{description}</p>
</div>
{#if navOptions && selectedNav !== undefined}
<div class="header-controls">
<SegmentedControl options={navOptions} bind:value={selectedNav} onchange={onNavChange} hideLabel={hideLabels} />
</div>
{/if}
</header>
{#if contentClass}
<div class={contentClass}>
{@render children()}
</div>
{:else}
{@render children()}
{/if}
</div>
<style>
.card-header {
flex-direction: row;
gap: var(--spacing-md);
@media (max-width: 600px) {
flex-direction: column;
}
}
</style>
@@ -2,6 +2,7 @@
import { onMount } from 'svelte';
import ToolsGrid from '$lib/components/global/ToolsGrid.svelte';
import Icon from '$lib/components/global/Icon.svelte';
import SegmentedControl from '$lib/components/global/SegmentedControl.svelte';
import { bookmarks } from '$lib/stores/bookmarks';
import { frequentlyUsedTools, recentlyUsedTools } from '$lib/stores/toolUsage';
@@ -12,6 +13,12 @@
type ViewMode = 'bookmarks' | 'most-used' | 'recent';
let activeView = $state<ViewMode>('bookmarks');
const viewOptions = [
{ value: 'bookmarks' as const, label: 'Bookmarks', icon: 'bookmarks' },
{ value: 'most-used' as const, label: 'Most Used', icon: 'frequently-used' },
{ value: 'recent' as const, label: 'Recent', icon: 'clock' },
];
const bookmarkCount = $derived($bookmarks.length);
const mostUsedCount = $derived($frequentlyUsedTools.length);
const recentCount = $derived($recentlyUsedTools.length);
@@ -84,35 +91,7 @@
{/if}
</div>
<div class="view-toggle">
<button
class="toggle-btn"
class:active={activeView === 'bookmarks'}
onclick={() => (activeView = 'bookmarks')}
aria-pressed={activeView === 'bookmarks'}
>
<Icon name="bookmarks" size="sm" />
<span>Bookmarks</span>
</button>
<button
class="toggle-btn"
class:active={activeView === 'most-used'}
onclick={() => (activeView = 'most-used')}
aria-pressed={activeView === 'most-used'}
>
<Icon name="frequently-used" size="sm" />
<span>Most Used</span>
</button>
<button
class="toggle-btn"
class:active={activeView === 'recent'}
onclick={() => (activeView = 'recent')}
aria-pressed={activeView === 'recent'}
>
<Icon name="clock" size="sm" />
<span>Recent</span>
</button>
</div>
<SegmentedControl options={viewOptions} bind:value={activeView} onchange={(value) => (activeView = value)} />
</div>
<div class="bookmarks-grid">
@@ -196,60 +175,6 @@
}
}
.view-toggle {
display: flex;
gap: var(--spacing-xs);
background: var(--bg-secondary);
padding: var(--spacing-xs);
border-radius: var(--radius-md);
border: 1px solid var(--border-primary);
.toggle-btn {
display: flex;
align-items: center;
gap: var(--spacing-xs);
padding: var(--spacing-xs) var(--spacing-sm);
background: transparent;
color: var(--text-secondary);
font-size: var(--font-size-sm);
border: none;
border-radius: var(--radius-sm);
cursor: pointer;
transition: all var(--transition-fast);
white-space: nowrap;
:global(svg) {
color: var(--text-secondary);
transition: color var(--transition-fast);
}
&:hover {
background: var(--bg-tertiary);
color: var(--text-primary);
:global(svg) {
color: var(--text-primary);
}
}
&.active {
background: var(--color-primary);
color: var(--bg-primary);
:global(svg) {
color: var(--bg-primary);
}
}
@media (max-width: 640px) {
span {
display: none;
}
padding: var(--spacing-xs);
}
}
}
.bookmarks-grid {
animation: subtleFadeIn 0.2s ease-out;
}
@@ -839,4 +839,8 @@
align-items: stretch;
}
}
textarea {
background: var(--bg-primary);
}
</style>
+288 -297
View File
@@ -163,336 +163,326 @@
});
</script>
<div class="card">
<header class="card-header">
<h2>CIDR Containment Checker</h2>
<p>
Check if set A fully contains each item in set B. Supports many-to-many containment analysis with detailed
classification.
</p>
</header>
<!-- Options -->
<div class="options-section">
<h3>Options</h3>
<div class="options-grid">
<label class="checkbox-label">
<input type="checkbox" bind:checked={mergeContainers} />
<span class="checkbox-text">
Merge/normalize containers first
<Tooltip text="Combine overlapping ranges in set A before checking containment">
<Icon name="help" size="sm" />
</Tooltip>
</span>
</label>
<label class="checkbox-label">
<input type="checkbox" bind:checked={strictEquality} />
<span class="checkbox-text">
Strict equality counts as contain
<Tooltip text="Treat exact matches as 'equal' instead of 'inside'">
<Icon name="help" size="sm" />
</Tooltip>
</span>
</label>
</div>
</div>
<!-- Options -->
<div class="options-section">
<h3>Options</h3>
<div class="options-grid">
<label class="checkbox-label">
<input type="checkbox" bind:checked={mergeContainers} />
<span class="checkbox-text">
Merge/normalize containers first
<Tooltip text="Combine overlapping ranges in set A before checking containment">
<Icon name="help" size="sm" />
</Tooltip>
</span>
</label>
<label class="checkbox-label">
<input type="checkbox" bind:checked={strictEquality} />
<span class="checkbox-text">
Strict equality counts as contain
<Tooltip text="Treat exact matches as 'equal' instead of 'inside'">
<Icon name="help" size="sm" />
</Tooltip>
</span>
</label>
<!-- Input Section -->
<div class="input-section">
<div class="input-grid">
<!-- Set A -->
<div class="input-group">
<h3>
Set A (Containers)
<Tooltip text="The containing set - these ranges may contain items from Set B">
<Icon name="help" size="sm" />
</Tooltip>
</h3>
<div class="input-wrapper">
<textarea
bind:value={setA}
placeholder="192.168.0.0/16&#10;10.0.0.0/8"
class="input-textarea set-a"
rows="6"
oninput={handleInputChange}
></textarea>
</div>
</div>
<!-- Set B -->
<div class="input-group">
<h3>
Set B (Candidates)
<Tooltip text="Items to check for containment within Set A">
<Icon name="help" size="sm" />
</Tooltip>
</h3>
<div class="input-wrapper">
<textarea
bind:value={setB}
placeholder="192.168.1.0/24&#10;172.16.0.0/24"
class="input-textarea set-b"
rows="6"
oninput={handleInputChange}
></textarea>
</div>
</div>
</div>
<!-- Input Section -->
<div class="input-section">
<div class="input-grid">
<!-- Set A -->
<div class="input-group">
<h3>
Set A (Containers)
<Tooltip text="The containing set - these ranges may contain items from Set B">
<Icon name="help" size="sm" />
</Tooltip>
</h3>
<div class="input-wrapper">
<textarea
bind:value={setA}
placeholder="192.168.0.0/16&#10;10.0.0.0/8"
class="input-textarea set-a"
rows="6"
oninput={handleInputChange}
></textarea>
</div>
<div class="input-actions">
<button type="button" class="btn btn-secondary btn-sm" onclick={clearInputs}>
<Icon name="trash" size="sm" />
Clear All
</button>
</div>
<!-- Examples -->
<div class="card examples-card">
<details class="examples-details">
<summary class="examples-summary">
<Icon name="chevron-right" size="xs" />
<h4>Quick Examples</h4>
</summary>
<div class="examples-grid">
{#each examples as example, i (example.label)}
<button
class="example-card"
class:selected={selectedExampleIndex === i && !userModified}
onclick={() => setExample(example, i)}
>
<div class="example-label">{example.label}</div>
<div class="example-preview">
{example.setA.split('\n')[0]}... ⊆ {example.setB.split('\n')[0]}...
</div>
</button>
{/each}
</div>
</details>
</div>
</div>
<!-- Set B -->
<div class="input-group">
<h3>
Set B (Candidates)
<Tooltip text="Items to check for containment within Set A">
<Icon name="help" size="sm" />
</Tooltip>
</h3>
<div class="input-wrapper">
<textarea
bind:value={setB}
placeholder="192.168.1.0/24&#10;172.16.0.0/24"
class="input-textarea set-b"
rows="6"
oninput={handleInputChange}
></textarea>
</div>
<!-- Results Section -->
{#if result}
<div class="results-section">
{#if result.errors.length > 0}
<div class="info-panel error">
<h3>Parse Errors</h3>
<ul class="error-list">
{#each result.errors as error (error)}
<li>{error}</li>
{/each}
</ul>
</div>
</div>
{/if}
<div class="input-actions">
<button type="button" class="btn btn-secondary btn-sm" onclick={clearInputs}>
<Icon name="trash" size="sm" />
Clear All
</button>
</div>
<!-- Examples -->
<div class="card examples-card">
<details class="examples-details">
<summary class="examples-summary">
<Icon name="chevron-right" size="xs" />
<h4>Quick Examples</h4>
</summary>
<div class="examples-grid">
{#each examples as example, i (example.label)}
{#if result.checks.length > 0}
<!-- Summary Statistics -->
<div class="stats-section">
<div class="summary-header">
<h3>Containment Analysis</h3>
<div class="export-buttons">
<button
class="example-card"
class:selected={selectedExampleIndex === i && !userModified}
onclick={() => setExample(example, i)}
type="button"
class="btn btn-primary btn-sm"
class:copied={clipboard.isCopied('csv-export')}
onclick={exportAsCSV}
>
<div class="example-label">{example.label}</div>
<div class="example-preview">
{example.setA.split('\n')[0]}... ⊆ {example.setB.split('\n')[0]}...
</div>
<Icon name={clipboard.isCopied('csv-export') ? 'check' : 'csv-file'} size="sm" />
CSV
</button>
<button
type="button"
class="btn btn-secondary btn-sm"
class:copied={clipboard.isCopied('json-export')}
onclick={exportAsJSON}
>
<Icon name={clipboard.isCopied('json-export') ? 'check' : 'json-file'} size="sm" />
JSON
</button>
</div>
</div>
<div class="stats-grid">
<div class="stat-card containers">
<span class="stat-label">Containers (A)</span>
<span class="stat-value">{result.stats.setA.count} items</span>
<span class="stat-detail">{result.stats.setA.addresses} addresses</span>
</div>
<div class="stat-card candidates">
<span class="stat-label">Candidates (B)</span>
<span class="stat-value">{result.stats.totalChecked} items</span>
<span class="stat-detail">checked for containment</span>
</div>
<div class="stat-card inside">
<span class="stat-label">Inside</span>
<span class="stat-value">{result.stats.inside}</span>
<span class="stat-detail">fully contained</span>
</div>
<div class="stat-card equal">
<span class="stat-label">Equal</span>
<span class="stat-value">{result.stats.equal}</span>
<span class="stat-detail">exact matches</span>
</div>
<div class="stat-card partial">
<span class="stat-label">Partial</span>
<span class="stat-value">{result.stats.partial}</span>
<span class="stat-detail">partial overlap</span>
</div>
<div class="stat-card outside">
<span class="stat-label">Outside</span>
<span class="stat-value">{result.stats.outside}</span>
<span class="stat-detail">no overlap</span>
</div>
</div>
</div>
<!-- Containment Results Table -->
<div class="table-section">
<h4>Containment Results</h4>
<div class="results-table">
<div class="table-header">
<div class="col-input">Candidate</div>
<div class="col-status">Status</div>
<div class="col-coverage">Coverage</div>
<div class="col-containers">Containers</div>
<div class="col-gaps">Gaps</div>
</div>
{#each result.checks as check, index (`${check.input}-${index}`)}
{@const statusInfo = getStatusInfo(check.status)}
<div class="table-row status-{check.status}">
<div class="col-input">
<code class="candidate-input">{check.input}</code>
</div>
<div class="col-status">
<div class="status-badge" style="color: {statusInfo.color}">
<Icon name={statusInfo.icon} size="sm" />
{statusInfo.label}
</div>
</div>
<div class="col-coverage">
<div class="coverage-bar">
<div
class="coverage-fill"
style="width: {check.coverage}%; background-color: {statusInfo.color}"
></div>
<span class="coverage-text">{check.coverage}%</span>
</div>
</div>
<div class="col-containers">
{#if check.matchingContainers.length > 0}
<div class="container-list">
{#each check.matchingContainers as container (container)}
<code class="container-item">{container}</code>
{/each}
</div>
{:else}
<span class="no-containers">-</span>
{/if}
</div>
<div class="col-gaps">
{#if check.gaps.length > 0}
<div class="gaps-list">
{#each check.gaps as gap (gap)}
<code class="gap-item">{gap}</code>
{/each}
</div>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(`gaps-${check.input}`)}
onclick={() => clipboard.copy(check.gaps.join('\n'), `gaps-${check.input}`)}
>
<Icon name={clipboard.isCopied(`gaps-${check.input}`) ? 'check' : 'copy'} size="xs" />
</button>
{:else}
<span class="no-gaps">-</span>
{/if}
</div>
</div>
{/each}
</div>
</details>
</div>
</div>
</div>
<!-- Results Section -->
{#if result}
<div class="results-section">
{#if result.errors.length > 0}
<div class="info-panel error">
<h3>Parse Errors</h3>
<ul class="error-list">
{#each result.errors as error (error)}
<li>{error}</li>
{/each}
</ul>
</div>
{/if}
{#if result.checks.length > 0}
<!-- Summary Statistics -->
<div class="stats-section">
<div class="summary-header">
<h3>Containment Analysis</h3>
<div class="export-buttons">
<button
type="button"
class="btn btn-primary btn-sm"
class:copied={clipboard.isCopied('csv-export')}
onclick={exportAsCSV}
>
<Icon name={clipboard.isCopied('csv-export') ? 'check' : 'csv-file'} size="sm" />
CSV
</button>
<button
type="button"
class="btn btn-secondary btn-sm"
class:copied={clipboard.isCopied('json-export')}
onclick={exportAsJSON}
>
<Icon name={clipboard.isCopied('json-export') ? 'check' : 'json-file'} size="sm" />
JSON
</button>
<!-- Visualization -->
{#if result.visualization.length > 0}
<div class="visualization-section">
<h4>Containment Visualization</h4>
<div class="viz-legend">
<div class="legend-item">
<div class="legend-color candidate-color"></div>
<span>Candidate Range</span>
</div>
<div class="legend-item">
<div class="legend-color container-color"></div>
<span>Container Coverage</span>
</div>
<div class="legend-item">
<div class="legend-color gap-color"></div>
<span>Uncovered Gaps</span>
</div>
</div>
<div class="stats-grid">
<div class="stat-card containers">
<span class="stat-label">Containers (A)</span>
<span class="stat-value">{result.stats.setA.count} items</span>
<span class="stat-detail">{result.stats.setA.addresses} addresses</span>
</div>
<div class="stat-card candidates">
<span class="stat-label">Candidates (B)</span>
<span class="stat-value">{result.stats.totalChecked} items</span>
<span class="stat-detail">checked for containment</span>
</div>
<div class="stat-card inside">
<span class="stat-label">Inside</span>
<span class="stat-value">{result.stats.inside}</span>
<span class="stat-detail">fully contained</span>
</div>
<div class="stat-card equal">
<span class="stat-label">Equal</span>
<span class="stat-value">{result.stats.equal}</span>
<span class="stat-detail">exact matches</span>
</div>
<div class="stat-card partial">
<span class="stat-label">Partial</span>
<span class="stat-value">{result.stats.partial}</span>
<span class="stat-detail">partial overlap</span>
</div>
<div class="stat-card outside">
<span class="stat-label">Outside</span>
<span class="stat-value">{result.stats.outside}</span>
<span class="stat-detail">no overlap</span>
</div>
</div>
</div>
<!-- Containment Results Table -->
<div class="table-section">
<h4>Containment Results</h4>
<div class="results-table">
<div class="table-header">
<div class="col-input">Candidate</div>
<div class="col-status">Status</div>
<div class="col-coverage">Coverage</div>
<div class="col-containers">Containers</div>
<div class="col-gaps">Gaps</div>
</div>
{#each result.checks as check, index (`${check.input}-${index}`)}
<div class="visualization-list">
{#each result.visualization as viz, index (viz.candidate)}
{@const check = result.checks[index]}
{@const statusInfo = getStatusInfo(check.status)}
<div class="table-row status-{check.status}">
<div class="col-input">
<code class="candidate-input">{check.input}</code>
</div>
<div class="col-status">
<div class="status-badge" style="color: {statusInfo.color}">
<div class="viz-item status-{check.status}">
<div class="viz-header">
<code class="viz-candidate">{viz.candidate}</code>
<div class="viz-status" style="color: {statusInfo.color}">
<Icon name={statusInfo.icon} size="sm" />
{statusInfo.label}
{statusInfo.label} ({check.coverage}%)
</div>
</div>
<div class="col-coverage">
<div class="coverage-bar">
<div class="viz-bar-container">
<!-- Candidate base -->
<div class="viz-bar candidate-bar">
<div
class="coverage-fill"
style="width: {check.coverage}%; background-color: {statusInfo.color}"
class="viz-segment candidate-segment"
style="width: {getBarWidth(viz.candidateRange, viz.totalRange)}%; left: {getBarOffset(
viz.candidateRange,
viz.totalRange,
)}%"
use:tooltip={{ text: getSegmentTooltip(viz.candidateRange, 'candidate'), position: 'top' }}
></div>
<span class="coverage-text">{check.coverage}%</span>
</div>
</div>
<div class="col-containers">
{#if check.matchingContainers.length > 0}
<div class="container-list">
{#each check.matchingContainers as container (container)}
<code class="container-item">{container}</code>
{/each}
</div>
{:else}
<span class="no-containers">-</span>
{/if}
</div>
<div class="col-gaps">
{#if check.gaps.length > 0}
<div class="gaps-list">
{#each check.gaps as gap (gap)}
<code class="gap-item">{gap}</code>
{/each}
</div>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(`gaps-${check.input}`)}
onclick={() => clipboard.copy(check.gaps.join('\n'), `gaps-${check.input}`)}
>
<Icon name={clipboard.isCopied(`gaps-${check.input}`) ? 'check' : 'copy'} size="xs" />
</button>
{:else}
<span class="no-gaps">-</span>
{/if}
</div>
</div>
{/each}
</div>
</div>
<!-- Visualization -->
{#if result.visualization.length > 0}
<div class="visualization-section">
<h4>Containment Visualization</h4>
<div class="viz-legend">
<div class="legend-item">
<div class="legend-color candidate-color"></div>
<span>Candidate Range</span>
</div>
<div class="legend-item">
<div class="legend-color container-color"></div>
<span>Container Coverage</span>
</div>
<div class="legend-item">
<div class="legend-color gap-color"></div>
<span>Uncovered Gaps</span>
</div>
</div>
<div class="visualization-list">
{#each result.visualization as viz, index (viz.candidate)}
{@const check = result.checks[index]}
{@const statusInfo = getStatusInfo(check.status)}
<div class="viz-item status-{check.status}">
<div class="viz-header">
<code class="viz-candidate">{viz.candidate}</code>
<div class="viz-status" style="color: {statusInfo.color}">
<Icon name={statusInfo.icon} size="sm" />
{statusInfo.label} ({check.coverage}%)
</div>
</div>
<div class="viz-bar-container">
<!-- Candidate base -->
<div class="viz-bar candidate-bar">
<!-- Container overlays -->
<div class="viz-bar container-bar">
{#each viz.containers as container (`${container.start}-${container.end}`)}
<div
class="viz-segment candidate-segment"
style="width: {getBarWidth(viz.candidateRange, viz.totalRange)}%; left: {getBarOffset(
viz.candidateRange,
class="viz-segment container-segment"
style="width: {getBarWidth(container, viz.totalRange)}%; left: {getBarOffset(
container,
viz.totalRange,
)}%"
use:tooltip={{ text: getSegmentTooltip(viz.candidateRange, 'candidate'), position: 'top' }}
use:tooltip={{ text: getSegmentTooltip(container, 'container'), position: 'top' }}
></div>
</div>
{/each}
</div>
<!-- Container overlays -->
<div class="viz-bar container-bar">
{#each viz.containers as container (`${container.start}-${container.end}`)}
<div
class="viz-segment container-segment"
style="width: {getBarWidth(container, viz.totalRange)}%; left: {getBarOffset(
container,
viz.totalRange,
)}%"
use:tooltip={{ text: getSegmentTooltip(container, 'container'), position: 'top' }}
></div>
{/each}
</div>
<!-- Gap highlights -->
<div class="viz-bar gap-bar">
{#each viz.gaps as gap (`${gap.start}-${gap.end}`)}
<div
class="viz-segment gap-segment"
style="width: {getBarWidth(gap, viz.totalRange)}%; left: {getBarOffset(gap, viz.totalRange)}%"
use:tooltip={{ text: getSegmentTooltip(gap, 'gap'), position: 'bottom' }}
></div>
{/each}
</div>
<!-- Gap highlights -->
<div class="viz-bar gap-bar">
{#each viz.gaps as gap (`${gap.start}-${gap.end}`)}
<div
class="viz-segment gap-segment"
style="width: {getBarWidth(gap, viz.totalRange)}%; left: {getBarOffset(gap, viz.totalRange)}%"
use:tooltip={{ text: getSegmentTooltip(gap, 'gap'), position: 'bottom' }}
></div>
{/each}
</div>
</div>
{/each}
</div>
</div>
{/each}
</div>
{/if}
</div>
{/if}
</div>
{/if}
</div>
{/if}
</div>
{/if}
<style lang="scss">
/* Reuse base styles from previous components */
@@ -553,6 +543,7 @@
height: 140px;
font-family: var(--font-mono);
font-size: var(--font-size-sm);
background: var(--bg-primary);
resize: vertical;
&.set-a {
@@ -685,7 +676,7 @@
/* Stats grid */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: var(--spacing-md);
margin-bottom: var(--spacing-lg);
}
@@ -323,7 +323,7 @@
gap: var(--spacing-md);
h3 {
color: var(--color-success-light);
color: var(--color-primary);
margin: 0;
}
}
@@ -546,4 +546,9 @@
justify-content: center;
}
}
input,
textarea {
background: var(--bg-primary);
}
</style>
+279 -294
View File
@@ -190,327 +190,311 @@
});
</script>
<div class="card">
<header class="card-header">
<h2>CIDR Difference Calculator</h2>
<p>
Compute A - B where A and B are sets of IP addresses, CIDR blocks, or ranges. Shows minimal non-overlapping
results.
</p>
</header>
<!-- Alignment Mode -->
<div class="mode-section">
<h3>Alignment Mode</h3>
<div class="tabs-container">
<div class="tabs">
{#each alignmentModes as mode (mode.value)}
<button
type="button"
class="tab"
class:active={alignment === mode.value}
onclick={() => (alignment = mode.value)}
use:tooltip={{ text: mode.description, position: 'top' }}
>
{mode.label}
</button>
{/each}
</div>
{#if alignment === 'constrained'}
<div class="constraint-input">
<label
for="constrained-prefix"
use:tooltip={{ text: 'Force alignment to this prefix boundary', position: 'top' }}
>
Constrained prefix length
</label>
<input
id="constrained-prefix"
type="number"
bind:value={constrainedPrefix}
oninput={() => (userModified = true)}
min="8"
max="30"
class="input-field constraint-field"
/>
</div>
{/if}
<!-- Alignment Mode -->
<div class="mode-section">
<h3>Alignment Mode</h3>
<div class="tabs-container">
<div class="tabs">
{#each alignmentModes as mode (mode.value)}
<button
type="button"
class="tab"
class:active={alignment === mode.value}
onclick={() => (alignment = mode.value)}
use:tooltip={{ text: mode.description, position: 'top' }}
>
{mode.label}
</button>
{/each}
</div>
{#if alignment === 'constrained'}
<div class="constraint-input">
<label
for="constrained-prefix"
use:tooltip={{ text: 'Force alignment to this prefix boundary', position: 'top' }}
>
Constrained prefix length
</label>
<input
id="constrained-prefix"
type="number"
bind:value={constrainedPrefix}
oninput={() => (userModified = true)}
min="8"
max="30"
class="input-field constraint-field"
/>
</div>
{/if}
</div>
</div>
<!-- Input Section -->
<div class="input-section">
<div class="input-grid">
<!-- Set A -->
<div class="input-group">
<h3 use:tooltip={{ text: 'The base set of IP addresses, CIDR blocks, or ranges', position: 'top' }}>
Set A (Base)
</h3>
<div class="input-wrapper">
<textarea
bind:value={setA}
oninput={() => (userModified = true)}
placeholder="192.168.1.0/24&#10;10.0.0.0-10.0.0.100"
class="input-textarea set-a"
rows="6"
></textarea>
</div>
</div>
<!-- Set B -->
<div class="input-group">
<h3 use:tooltip={{ text: 'The set to subtract from Set A (can be empty)', position: 'top' }}>
Set B (Subtract)
</h3>
<div class="input-wrapper">
<textarea
bind:value={setB}
oninput={() => (userModified = true)}
placeholder="192.168.1.128/25&#10;10.0.0.50-10.0.0.75"
class="input-textarea set-b"
rows="6"
></textarea>
</div>
<!-- Input Section -->
<div class="input-section">
<div class="input-grid">
<!-- Set A -->
<div class="input-group">
<h3 use:tooltip={{ text: 'The base set of IP addresses, CIDR blocks, or ranges', position: 'top' }}>
Set A (Base)
</h3>
<div class="input-wrapper">
<textarea
bind:value={setA}
oninput={() => (userModified = true)}
placeholder="192.168.1.0/24&#10;10.0.0.0-10.0.0.100"
class="input-textarea set-a"
rows="6"
></textarea>
</div>
</div>
<div class="input-actions">
<button
type="button"
class="btn btn-secondary btn-sm"
onclick={clearInputs}
use:tooltip={{ text: 'Clear both input sets', position: 'top' }}
>
<Icon name="trash" size="sm" />
</button>
</div>
<!-- Examples -->
<div class="examples-section">
<h4>
Quick Examples
<Tooltip text="Click any example to load it into the input fields">
<Icon name="help" size="sm" />
</Tooltip>
</h4>
<div class="examples-grid">
{#each examples as example (example.label)}
<button
type="button"
class="example-btn"
class:selected={selectedExample === example.label}
onclick={() => setExample(example)}
>
{example.label}
</button>
{/each}
<!-- Set B -->
<div class="input-group">
<h3 use:tooltip={{ text: 'The set to subtract from Set A (can be empty)', position: 'top' }}>Set B (Subtract)</h3>
<div class="input-wrapper">
<textarea
bind:value={setB}
oninput={() => (userModified = true)}
placeholder="192.168.1.128/25&#10;10.0.0.50-10.0.0.75"
class="input-textarea set-b"
rows="6"
></textarea>
</div>
</div>
</div>
<!-- Results Section -->
{#if result}
<div class="results-section">
{#if result.errors.length > 0}
<div class="info-panel error">
<h3>Parse Errors</h3>
<ul class="error-list">
{#each result.errors as error (error)}
<li>{error}</li>
{/each}
</ul>
</div>
{/if}
<div class="input-actions">
<button
type="button"
class="btn btn-secondary btn-sm"
onclick={clearInputs}
use:tooltip={{ text: 'Clear both input sets', position: 'top' }}
>
<Icon name="trash" size="sm" />
</button>
</div>
{#if result.ipv4.length > 0 || result.ipv6.length > 0}
<!-- Statistics -->
<div class="stats-section">
<div class="summary-header">
<h3>Difference Results (A - B)</h3>
<div class="export-buttons">
<button
type="button"
class="btn btn-primary btn-sm"
class:copied={clipboard.isCopied('all-text')}
onclick={() => copyAllResults('text')}
>
<Icon name={clipboard.isCopied('all-text') ? 'check' : 'copy'} size="sm" />
Text
</button>
<button
type="button"
class="btn btn-secondary btn-sm"
class:copied={clipboard.isCopied('all-json')}
onclick={() => copyAllResults('json')}
>
<Icon name={clipboard.isCopied('all-json') ? 'check' : 'download'} size="sm" />
JSON
</button>
</div>
</div>
<!-- Examples -->
<div class="examples-section">
<h4>
Quick Examples
<Tooltip text="Click any example to load it into the input fields">
<Icon name="help" size="sm" />
</Tooltip>
</h4>
<div class="examples-grid">
{#each examples as example (example.label)}
<button
type="button"
class="example-btn"
class:selected={selectedExample === example.label}
onclick={() => setExample(example)}
>
{example.label}
</button>
{/each}
</div>
</div>
</div>
<div class="stats-grid">
<div class="stat-card input-a">
<span class="stat-label">Set A (Input)</span>
<span class="stat-value">{result.stats.inputA.count} items</span>
<span class="stat-detail">{result.stats.inputA.addresses} addresses</span>
</div>
<div class="stat-card input-b">
<span class="stat-label">Set B (Subtract)</span>
<span class="stat-value">{result.stats.inputB.count} items</span>
<span class="stat-detail">{result.stats.inputB.addresses} addresses</span>
</div>
<div class="stat-card result">
<span class="stat-label">Result (A - B)</span>
<span class="stat-value">{result.stats.output.count} CIDRs</span>
<span class="stat-detail">{result.stats.output.addresses} addresses</span>
</div>
<div
class="stat-card efficiency"
data-efficiency={result.stats.efficiency >= 80
? 'high'
: result.stats.efficiency >= 50
? 'medium'
: 'low'}
<!-- Results Section -->
{#if result}
<div class="results-section">
{#if result.errors.length > 0}
<div class="info-panel error">
<h3>Parse Errors</h3>
<ul class="error-list">
{#each result.errors as error (error)}
<li>{error}</li>
{/each}
</ul>
</div>
{/if}
{#if result.ipv4.length > 0 || result.ipv6.length > 0}
<!-- Statistics -->
<div class="stats-section">
<div class="summary-header">
<h3>Difference Results (A - B)</h3>
<div class="export-buttons">
<button
type="button"
class="btn btn-primary btn-sm"
class:copied={clipboard.isCopied('all-text')}
onclick={() => copyAllResults('text')}
>
<span class="stat-label">Efficiency</span>
<span class="stat-value">{result.stats.efficiency}%</span>
<span class="stat-detail">{result.stats.removed.addresses} removed</span>
</div>
<Icon name={clipboard.isCopied('all-text') ? 'check' : 'copy'} size="sm" />
Text
</button>
<button
type="button"
class="btn btn-secondary btn-sm"
class:copied={clipboard.isCopied('all-json')}
onclick={() => copyAllResults('json')}
>
<Icon name={clipboard.isCopied('all-json') ? 'check' : 'download'} size="sm" />
JSON
</button>
</div>
</div>
<!-- Visualization -->
{#if result.visualization.setA.length > 0}
<div class="visualization-section">
<h4>
Set Operation Visualization
<Tooltip text="Visual representation showing the relationship between sets A, B, and the result">
<Icon name="help" size="sm" />
</Tooltip>
</h4>
<div class="viz-legend">
<div class="legend-item">
<div class="legend-color set-a-color"></div>
<span>Set A (Base)</span>
</div>
<div class="legend-item">
<div class="legend-color set-b-color"></div>
<span>Set B (Subtract)</span>
</div>
<div class="legend-item">
<div class="legend-color result-color"></div>
<span>Result (A - B)</span>
</div>
<div class="stats-grid">
<div class="stat-card input-a">
<span class="stat-label">Set A (Input)</span>
<span class="stat-value">{result.stats.inputA.count} items</span>
<span class="stat-detail">{result.stats.inputA.addresses} addresses</span>
</div>
<div class="stat-card input-b">
<span class="stat-label">Set B (Subtract)</span>
<span class="stat-value">{result.stats.inputB.count} items</span>
<span class="stat-detail">{result.stats.inputB.addresses} addresses</span>
</div>
<div class="stat-card result">
<span class="stat-label">Result (A - B)</span>
<span class="stat-value">{result.stats.output.count} CIDRs</span>
<span class="stat-detail">{result.stats.output.addresses} addresses</span>
</div>
<div
class="stat-card efficiency"
data-efficiency={result.stats.efficiency >= 80 ? 'high' : result.stats.efficiency >= 50 ? 'medium' : 'low'}
>
<span class="stat-label">Efficiency</span>
<span class="stat-value">{result.stats.efficiency}%</span>
<span class="stat-detail">{result.stats.removed.addresses} removed</span>
</div>
</div>
</div>
<!-- Visualization -->
{#if result.visualization.setA.length > 0}
<div class="visualization-section">
<h4>
Set Operation Visualization
<Tooltip text="Visual representation showing the relationship between sets A, B, and the result">
<Icon name="help" size="sm" />
</Tooltip>
</h4>
<div class="viz-legend">
<div class="legend-item">
<div class="legend-color set-a-color"></div>
<span>Set A (Base)</span>
</div>
<div class="legend-item">
<div class="legend-color set-b-color"></div>
<span>Set B (Subtract)</span>
</div>
<div class="legend-item">
<div class="legend-color result-color"></div>
<span>Result (A - B)</span>
</div>
</div>
<div class="visualization-bar">
<!-- Set A (background) -->
{#each result.visualization.setA as range (`${range.start}-${range.end}`)}
<div
class="viz-segment set-a-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'A'), position: 'top' }}
></div>
{/each}
<div class="visualization-bar">
<!-- Set A (background) -->
{#each result.visualization.setA as range (`${range.start}-${range.end}`)}
<div
class="viz-segment set-a-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'A'), position: 'top' }}
></div>
{/each}
<!-- Set B (overlay) -->
{#each result.visualization.setB as range (`${range.start}-${range.end}`)}
<div
class="viz-segment set-b-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'B'), position: 'top' }}
></div>
{/each}
<!-- Set B (overlay) -->
{#each result.visualization.setB as range (`${range.start}-${range.end}`)}
<div
class="viz-segment set-b-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'B'), position: 'top' }}
></div>
{/each}
<!-- Result (final) -->
{#each result.visualization.result as range (`${range.start}-${range.end}`)}
<div
class="viz-segment result-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'result'), position: 'bottom' }}
></div>
<!-- Result (final) -->
{#each result.visualization.result as range (`${range.start}-${range.end}`)}
<div
class="viz-segment result-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'result'), position: 'bottom' }}
></div>
{/each}
</div>
</div>
{/if}
<!-- Results Grid -->
<div class="results-grid">
<!-- IPv4 Results -->
{#if result.ipv4.length > 0}
<div class="result-panel ipv4">
<div class="panel-header">
<h4>IPv4 Results ({result.ipv4.length})</h4>
<button
type="button"
class="btn btn-icon"
class:copied={clipboard.isCopied('ipv4')}
onclick={() => clipboard.copy((result?.ipv4 || []).join('\n'), 'ipv4')}
>
<Icon name={clipboard.isCopied('ipv4') ? 'check' : 'copy'} size="sm" />
</button>
</div>
<div class="cidr-list">
{#each result.ipv4 as cidr (cidr)}
<div class="cidr-item">
<code class="cidr-block">{cidr}</code>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(cidr)}
onclick={() => clipboard.copy(cidr, cidr)}
>
<Icon name={clipboard.isCopied(cidr) ? 'check' : 'copy'} size="xs" />
</button>
</div>
{/each}
</div>
</div>
{/if}
<!-- Results Grid -->
<div class="results-grid">
<!-- IPv4 Results -->
{#if result.ipv4.length > 0}
<div class="result-panel ipv4">
<div class="panel-header">
<h4>IPv4 Results ({result.ipv4.length})</h4>
<button
type="button"
class="btn btn-icon"
class:copied={clipboard.isCopied('ipv4')}
onclick={() => clipboard.copy((result?.ipv4 || []).join('\n'), 'ipv4')}
>
<Icon name={clipboard.isCopied('ipv4') ? 'check' : 'copy'} size="sm" />
</button>
</div>
<div class="cidr-list">
{#each result.ipv4 as cidr (cidr)}
<div class="cidr-item">
<code class="cidr-block">{cidr}</code>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(cidr)}
onclick={() => clipboard.copy(cidr, cidr)}
>
<Icon name={clipboard.isCopied(cidr) ? 'check' : 'copy'} size="xs" />
</button>
</div>
{/each}
</div>
<!-- IPv6 Results -->
{#if result.ipv6.length > 0}
<div class="result-panel ipv6">
<div class="panel-header">
<h4>IPv6 Results ({result.ipv6.length})</h4>
<button
type="button"
class="btn btn-icon"
class:copied={clipboard.isCopied('ipv6')}
onclick={() => clipboard.copy((result?.ipv6 || []).join('\n'), 'ipv6')}
>
<Icon name={clipboard.isCopied('ipv6') ? 'check' : 'copy'} size="sm" />
</button>
</div>
{/if}
<!-- IPv6 Results -->
{#if result.ipv6.length > 0}
<div class="result-panel ipv6">
<div class="panel-header">
<h4>IPv6 Results ({result.ipv6.length})</h4>
<button
type="button"
class="btn btn-icon"
class:copied={clipboard.isCopied('ipv6')}
onclick={() => clipboard.copy((result?.ipv6 || []).join('\n'), 'ipv6')}
>
<Icon name={clipboard.isCopied('ipv6') ? 'check' : 'copy'} size="sm" />
</button>
</div>
<div class="cidr-list">
{#each result.ipv6 as cidr (cidr)}
<div class="cidr-item">
<code class="cidr-block">{cidr}</code>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(cidr)}
onclick={() => clipboard.copy(cidr, cidr)}
>
<Icon name={clipboard.isCopied(cidr) ? 'check' : 'copy'} size="xs" />
</button>
</div>
{/each}
</div>
<div class="cidr-list">
{#each result.ipv6 as cidr (cidr)}
<div class="cidr-item">
<code class="cidr-block">{cidr}</code>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(cidr)}
onclick={() => clipboard.copy(cidr, cidr)}
>
<Icon name={clipboard.isCopied(cidr) ? 'check' : 'copy'} size="xs" />
</button>
</div>
{/each}
</div>
{/if}
</div>
{:else}
<div class="info-panel info">
<h3>No Results</h3>
<p>The difference A - B resulted in an empty set. Set B completely contains or covers Set A.</p>
</div>
{/if}
</div>
{/if}
</div>
</div>
{/if}
</div>
{:else}
<div class="info-panel info">
<h3>No Results</h3>
<p>The difference A - B resulted in an empty set. Set B completely contains or covers Set A.</p>
</div>
{/if}
</div>
{/if}
<style lang="scss">
/* Reusable tokens */
@@ -620,6 +604,7 @@
font-family: var(--font-mono);
font-size: var(--font-size-sm);
resize: vertical;
background: var(--bg-primary);
border-left: 4px solid var(--color-primary);
}
+285 -291
View File
@@ -176,321 +176,314 @@
});
</script>
<div class="card">
<header class="card-header">
<h2>CIDR Overlap Checker</h2>
<p>Determine if two sets of IP addresses, CIDR blocks, or ranges intersect and show the overlapping regions.</p>
</header>
<!-- Options -->
<div class="options-section">
<h3>Options</h3>
<div class="options-grid">
<label class="checkbox-label">
<input type="checkbox" bind:checked={mergeInputs} onchange={() => (userModified = true)} />
<span class="checkbox-text">
Merge overlapping inputs first
<Tooltip text="Combine overlapping ranges within each set before comparison">
<Icon name="help" size="sm" />
</Tooltip>
</span>
</label>
<label class="checkbox-label">
<input type="checkbox" bind:checked={showOnlyBoolean} onchange={() => (userModified = true)} />
<span class="checkbox-text">
Show only boolean result
<Tooltip text="Display just yes/no overlap instead of detailed intersection blocks">
<Icon name="help" size="sm" />
</Tooltip>
</span>
</label>
</div>
<!-- Options -->
<div class="options-section">
<h3>Options</h3>
<div class="options-grid">
<label class="checkbox-label">
<input type="checkbox" bind:checked={mergeInputs} onchange={() => (userModified = true)} />
<span class="checkbox-text">
Merge overlapping inputs first
<Tooltip text="Combine overlapping ranges within each set before comparison">
<Icon name="help" size="sm" />
</Tooltip>
</span>
</label>
<label class="checkbox-label">
<input type="checkbox" bind:checked={showOnlyBoolean} onchange={() => (userModified = true)} />
<span class="checkbox-text">
Show only boolean result
<Tooltip text="Display just yes/no overlap instead of detailed intersection blocks">
<Icon name="help" size="sm" />
</Tooltip>
</span>
</label>
</div>
</div>
<!-- Input Section -->
<div class="input-section">
<div class="input-grid">
<!-- Set A -->
<div class="input-group">
<h3>
Set A
<Tooltip text="First set of IP addresses, CIDR blocks, or ranges">
<Icon name="help" size="sm" />
</Tooltip>
</h3>
<div class="input-wrapper">
<textarea
bind:value={setA}
oninput={() => (userModified = true)}
placeholder="192.168.1.0/24&#10;10.0.0.0-10.0.0.100"
class="input-textarea set-a"
rows="6"
></textarea>
</div>
</div>
<!-- Set B -->
<div class="input-group">
<h3>
Set B
<Tooltip text="Second set of IP addresses, CIDR blocks, or ranges">
<Icon name="help" size="sm" />
</Tooltip>
</h3>
<div class="input-wrapper">
<textarea
bind:value={setB}
oninput={() => (userModified = true)}
placeholder="192.168.1.128/25&#10;10.0.0.50-10.0.0.150"
class="input-textarea set-b"
rows="6"
></textarea>
</div>
<!-- Input Section -->
<div class="input-section">
<div class="input-grid">
<!-- Set A -->
<div class="input-group">
<h3>
Set A
<Tooltip text="First set of IP addresses, CIDR blocks, or ranges">
<Icon name="help" size="sm" />
</Tooltip>
</h3>
<div class="input-wrapper">
<textarea
bind:value={setA}
oninput={() => (userModified = true)}
placeholder="192.168.1.0/24&#10;10.0.0.0-10.0.0.100"
class="input-textarea set-a"
rows="6"
></textarea>
</div>
</div>
<div class="input-actions">
<button type="button" class="btn btn-secondary btn-sm" onclick={clearInputs}>
<Icon name="trash" size="sm" />
Clear All
</button>
</div>
<!-- Examples -->
<div class="examples-section">
<h4>Quick Examples</h4>
<div class="examples-grid">
{#each examples as example (example.label)}
<button
type="button"
class="example-btn"
class:selected={selectedExample === example.label}
onclick={() => setExample(example)}
>
{example.label}
</button>
{/each}
<!-- Set B -->
<div class="input-group">
<h3>
Set B
<Tooltip text="Second set of IP addresses, CIDR blocks, or ranges">
<Icon name="help" size="sm" />
</Tooltip>
</h3>
<div class="input-wrapper">
<textarea
bind:value={setB}
oninput={() => (userModified = true)}
placeholder="192.168.1.128/25&#10;10.0.0.50-10.0.0.150"
class="input-textarea set-b"
rows="6"
></textarea>
</div>
</div>
</div>
<!-- Results Section -->
{#if result}
<div class="results-section">
{#if result.errors.length > 0}
<div class="info-panel error">
<h3>Parse Errors</h3>
<ul class="error-list">
{#each result.errors as error (error)}
<li>{error}</li>
{/each}
</ul>
<div class="input-actions">
<button type="button" class="btn btn-secondary btn-sm" onclick={clearInputs}>
<Icon name="trash" size="sm" />
Clear All
</button>
</div>
<!-- Examples -->
<div class="examples-section">
<h4>Quick Examples</h4>
<div class="examples-grid">
{#each examples as example (example.label)}
<button
type="button"
class="example-btn"
class:selected={selectedExample === example.label}
onclick={() => setExample(example)}
>
{example.label}
</button>
{/each}
</div>
</div>
</div>
<!-- Results Section -->
{#if result}
<div class="results-section">
{#if result.errors.length > 0}
<div class="info-panel error">
<h3>Parse Errors</h3>
<ul class="error-list">
{#each result.errors as error (error)}
<li>{error}</li>
{/each}
</ul>
</div>
{/if}
<!-- Overlap Status -->
<div class="status-section">
<div class="status-card {result.hasOverlap ? 'overlap' : 'no-overlap'}">
<div class="status-icon">
<Icon name={result.hasOverlap ? 'check-circle' : 'x-circle'} size="lg" />
</div>
<div class="status-content">
<h3>{result.hasOverlap ? 'Overlap Detected' : 'No Overlap'}</h3>
<p>
{result.hasOverlap
? `Sets A and B have overlapping address ranges (${result.stats.overlapPercent}% of smaller set)`
: 'Sets A and B do not share any common address ranges'}
</p>
</div>
</div>
</div>
{#if !showOnlyBoolean && (result.ipv4.length > 0 || result.ipv6.length > 0)}
<!-- Statistics -->
<div class="stats-section">
<div class="summary-header">
<h3>Intersection Results (A ∩ B)</h3>
<div class="export-buttons">
<button
type="button"
class="btn btn-primary btn-sm"
class:copied={clipboard.isCopied('all-text')}
onclick={() => copyAllResults('text')}
>
<Icon name={clipboard.isCopied('all-text') ? 'check' : 'copy'} size="sm" />
Text
</button>
<button
type="button"
class="btn btn-secondary btn-sm"
class:copied={clipboard.isCopied('all-json')}
onclick={() => copyAllResults('json')}
>
<Icon name={clipboard.isCopied('all-json') ? 'check' : 'download'} size="sm" />
JSON
</button>
</div>
</div>
<div class="stats-grid">
<div class="stat-card set-a">
<span class="stat-label">Set A</span>
<span class="stat-value">{result.stats.setA.count} items</span>
<span class="stat-detail">{result.stats.setA.addresses} addresses</span>
</div>
<div class="stat-card set-b">
<span class="stat-label">Set B</span>
<span class="stat-value">{result.stats.setB.count} items</span>
<span class="stat-detail">{result.stats.setB.addresses} addresses</span>
</div>
<div class="stat-card intersection">
<span class="stat-label">Intersection</span>
<span class="stat-value">{result.stats.intersection.count} CIDRs</span>
<span class="stat-detail">{result.stats.intersection.addresses} addresses</span>
</div>
<div class="stat-card overlap-percent">
<span class="stat-label">Overlap</span>
<span class="stat-value">{result.stats.overlapPercent}%</span>
<span class="stat-detail">of smaller set</span>
</div>
</div>
</div>
<!-- Visualization -->
{#if result.visualization.setA.length > 0 || result.visualization.setB.length > 0}
<div class="visualization-section">
<h4>Overlap Visualization</h4>
<div class="viz-legend">
<div class="legend-item">
<div class="legend-color set-a-color"></div>
<span>Set A</span>
</div>
<div class="legend-item">
<div class="legend-color set-b-color"></div>
<span>Set B</span>
</div>
<div class="legend-item">
<div class="legend-color intersection-color"></div>
<span>Intersection (A ∩ B)</span>
</div>
</div>
<div class="visualization-stack">
<!-- Set A Bar -->
<div class="viz-bar set-a-bar">
<div class="bar-label">Set A</div>
<div class="bar-segments">
{#each result.visualization.setA as range (`${range.start}-${range.end}`)}
<div
class="viz-segment set-a-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'A'), position: 'top' }}
></div>
{/each}
</div>
</div>
<!-- Set B Bar -->
<div class="viz-bar set-b-bar">
<div class="bar-label">Set B</div>
<div class="bar-segments">
{#each result.visualization.setB as range (`${range.start}-${range.end}`)}
<div
class="viz-segment set-b-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'B'), position: 'top' }}
></div>
{/each}
</div>
</div>
<!-- Intersection Highlights -->
<div class="viz-bar intersection-bar">
<div class="bar-label">A ∩ B</div>
<div class="bar-segments">
{#each result.visualization.intersection as range (`${range.start}-${range.end}`)}
<div
class="viz-segment intersection-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'intersection'), position: 'bottom' }}
></div>
{/each}
</div>
</div>
</div>
</div>
{/if}
<!-- Overlap Status -->
<div class="status-section">
<div class="status-card {result.hasOverlap ? 'overlap' : 'no-overlap'}">
<div class="status-icon">
<Icon name={result.hasOverlap ? 'check-circle' : 'x-circle'} size="lg" />
</div>
<div class="status-content">
<h3>{result.hasOverlap ? 'Overlap Detected' : 'No Overlap'}</h3>
<p>
{result.hasOverlap
? `Sets A and B have overlapping address ranges (${result.stats.overlapPercent}% of smaller set)`
: 'Sets A and B do not share any common address ranges'}
</p>
</div>
</div>
</div>
{#if !showOnlyBoolean && (result.ipv4.length > 0 || result.ipv6.length > 0)}
<!-- Statistics -->
<div class="stats-section">
<div class="summary-header">
<h3>Intersection Results (A ∩ B)</h3>
<div class="export-buttons">
<!-- Results Grid -->
<div class="results-grid">
<!-- IPv4 Results -->
{#if result.ipv4.length > 0}
<div class="result-panel ipv4">
<div class="panel-header">
<h4>IPv4 Intersection ({result.ipv4.length})</h4>
<button
type="button"
class="btn btn-primary btn-sm"
class:copied={clipboard.isCopied('all-text')}
onclick={() => copyAllResults('text')}
class="btn btn-icon"
class:copied={clipboard.isCopied('ipv4')}
onclick={() => clipboard.copy((result?.ipv4 || []).join('\n'), 'ipv4')}
>
<Icon name={clipboard.isCopied('all-text') ? 'check' : 'copy'} size="sm" />
Text
</button>
<button
type="button"
class="btn btn-secondary btn-sm"
class:copied={clipboard.isCopied('all-json')}
onclick={() => copyAllResults('json')}
>
<Icon name={clipboard.isCopied('all-json') ? 'check' : 'download'} size="sm" />
JSON
<Icon name={clipboard.isCopied('ipv4') ? 'check' : 'copy'} size="sm" />
</button>
</div>
</div>
<div class="stats-grid">
<div class="stat-card set-a">
<span class="stat-label">Set A</span>
<span class="stat-value">{result.stats.setA.count} items</span>
<span class="stat-detail">{result.stats.setA.addresses} addresses</span>
</div>
<div class="stat-card set-b">
<span class="stat-label">Set B</span>
<span class="stat-value">{result.stats.setB.count} items</span>
<span class="stat-detail">{result.stats.setB.addresses} addresses</span>
</div>
<div class="stat-card intersection">
<span class="stat-label">Intersection</span>
<span class="stat-value">{result.stats.intersection.count} CIDRs</span>
<span class="stat-detail">{result.stats.intersection.addresses} addresses</span>
</div>
<div class="stat-card overlap-percent">
<span class="stat-label">Overlap</span>
<span class="stat-value">{result.stats.overlapPercent}%</span>
<span class="stat-detail">of smaller set</span>
</div>
</div>
</div>
<!-- Visualization -->
{#if result.visualization.setA.length > 0 || result.visualization.setB.length > 0}
<div class="visualization-section">
<h4>Overlap Visualization</h4>
<div class="viz-legend">
<div class="legend-item">
<div class="legend-color set-a-color"></div>
<span>Set A</span>
</div>
<div class="legend-item">
<div class="legend-color set-b-color"></div>
<span>Set B</span>
</div>
<div class="legend-item">
<div class="legend-color intersection-color"></div>
<span>Intersection (A ∩ B)</span>
</div>
</div>
<div class="visualization-stack">
<!-- Set A Bar -->
<div class="viz-bar set-a-bar">
<div class="bar-label">Set A</div>
<div class="bar-segments">
{#each result.visualization.setA as range (`${range.start}-${range.end}`)}
<div
class="viz-segment set-a-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'A'), position: 'top' }}
></div>
{/each}
<div class="cidr-list">
{#each result.ipv4 as cidr (cidr)}
<div class="cidr-item">
<code class="cidr-block">{cidr}</code>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(cidr)}
onclick={() => clipboard.copy(cidr, cidr)}
>
<Icon name={clipboard.isCopied(cidr) ? 'check' : 'copy'} size="xs" />
</button>
</div>
</div>
<!-- Set B Bar -->
<div class="viz-bar set-b-bar">
<div class="bar-label">Set B</div>
<div class="bar-segments">
{#each result.visualization.setB as range (`${range.start}-${range.end}`)}
<div
class="viz-segment set-b-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'B'), position: 'top' }}
></div>
{/each}
</div>
</div>
<!-- Intersection Highlights -->
<div class="viz-bar intersection-bar">
<div class="bar-label">A ∩ B</div>
<div class="bar-segments">
{#each result.visualization.intersection as range (`${range.start}-${range.end}`)}
<div
class="viz-segment intersection-segment"
style="width: {getBarWidth(range)}%; left: {getBarOffset(range)}%"
use:tooltip={{ text: getSegmentTooltip(range, 'intersection'), position: 'bottom' }}
></div>
{/each}
</div>
</div>
{/each}
</div>
</div>
{/if}
<!-- Results Grid -->
<div class="results-grid">
<!-- IPv4 Results -->
{#if result.ipv4.length > 0}
<div class="result-panel ipv4">
<div class="panel-header">
<h4>IPv4 Intersection ({result.ipv4.length})</h4>
<button
type="button"
class="btn btn-icon"
class:copied={clipboard.isCopied('ipv4')}
onclick={() => clipboard.copy((result?.ipv4 || []).join('\n'), 'ipv4')}
>
<Icon name={clipboard.isCopied('ipv4') ? 'check' : 'copy'} size="sm" />
</button>
</div>
<div class="cidr-list">
{#each result.ipv4 as cidr (cidr)}
<div class="cidr-item">
<code class="cidr-block">{cidr}</code>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(cidr)}
onclick={() => clipboard.copy(cidr, cidr)}
>
<Icon name={clipboard.isCopied(cidr) ? 'check' : 'copy'} size="xs" />
</button>
</div>
{/each}
</div>
<!-- IPv6 Results -->
{#if result.ipv6.length > 0}
<div class="result-panel ipv6">
<div class="panel-header">
<h4>IPv6 Intersection ({result.ipv6.length})</h4>
<button
type="button"
class="btn btn-icon"
class:copied={clipboard.isCopied('ipv6')}
onclick={() => clipboard.copy((result?.ipv6 || []).join('\n'), 'ipv6')}
>
<Icon name={clipboard.isCopied('ipv6') ? 'check' : 'copy'} size="sm" />
</button>
</div>
{/if}
<!-- IPv6 Results -->
{#if result.ipv6.length > 0}
<div class="result-panel ipv6">
<div class="panel-header">
<h4>IPv6 Intersection ({result.ipv6.length})</h4>
<button
type="button"
class="btn btn-icon"
class:copied={clipboard.isCopied('ipv6')}
onclick={() => clipboard.copy((result?.ipv6 || []).join('\n'), 'ipv6')}
>
<Icon name={clipboard.isCopied('ipv6') ? 'check' : 'copy'} size="sm" />
</button>
</div>
<div class="cidr-list">
{#each result.ipv6 as cidr (cidr)}
<div class="cidr-item">
<code class="cidr-block">{cidr}</code>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(cidr)}
onclick={() => clipboard.copy(cidr, cidr)}
>
<Icon name={clipboard.isCopied(cidr) ? 'check' : 'copy'} size="xs" />
</button>
</div>
{/each}
</div>
<div class="cidr-list">
{#each result.ipv6 as cidr (cidr)}
<div class="cidr-item">
<code class="cidr-block">{cidr}</code>
<button
type="button"
class="btn btn-icon btn-xs"
class:copied={clipboard.isCopied(cidr)}
onclick={() => clipboard.copy(cidr, cidr)}
>
<Icon name={clipboard.isCopied(cidr) ? 'check' : 'copy'} size="xs" />
</button>
</div>
{/each}
</div>
{/if}
</div>
{/if}
</div>
{/if}
</div>
</div>
{/if}
</div>
{/if}
</div>
{/if}
<style lang="scss">
/* Reusable tokens */
@@ -579,6 +572,7 @@
height: 140px;
font-family: var(--font-mono);
font-size: var(--font-size-sm);
background: var(--bg-primary);
resize: vertical;
&.set-a {
@@ -257,7 +257,7 @@
onclick={() => (showPrivateKey = !showPrivateKey)}
use:tooltip={showPrivateKey ? 'Hide private key' : 'Show private key'}
>
<Icon name={showPrivateKey ? 'eye-off' : 'eye'} size="sm" />
<Icon name={showPrivateKey ? 'hide' : 'eye'} size="sm" />
{showPrivateKey ? 'Hide' : 'Show'}
</button>
<button
@@ -281,7 +281,7 @@
</div>
{:else}
<div class="key-hidden">
<Icon name="eye-off" size="sm" />
<Icon name="hide" size="sm" />
Private key hidden for security
</div>
{/if}
+46 -47
View File
@@ -311,50 +311,6 @@
</div>
</div>
{#if result.availableBlocks.length > 0}
<div class="free-blocks-grid">
{#each result.availableBlocks as block, index (index)}
{@const blockAddresses = (() => {
const match = block.match(/\/(\d+)$/);
if (!match) return 0;
const prefixLength = parseInt(match[1]);
const version = block.includes(':') ? 6 : 4;
const totalBits = version === 4 ? 32 : 128;
return Math.pow(2, totalBits - prefixLength);
})()}
<div class="free-block-card">
<div class="block-header">
<code class="block-cidr">{block}</code>
<button
class="copy-button {clipboard.isCopied(`block-${index}`) ? 'copied' : ''}"
onclick={() => clipboard.copy(block, `block-${index}`)}
aria-label="Copy CIDR block"
>
<Icon name={clipboard.isCopied(`block-${index}`) ? 'check' : 'copy'} size="xs" />
</button>
</div>
<div class="block-info">
<span class="address-count">
{formatNumber(blockAddresses)} addresses
</span>
{#if targetPrefix && blockAddresses >= Math.pow(2, 32 - targetPrefix)}
<span class="can-fit">
<Icon name="check-circle" size="xs" />
Can fit /{targetPrefix}
</span>
{/if}
</div>
</div>
{/each}
</div>
{:else}
<div class="no-gaps">
<Icon name="alert-circle" />
<h4>No Available Space</h4>
<p>All address space in the pools is allocated or there are no pools defined.</p>
</div>
{/if}
<!-- Address Space Visualization -->
{#if result.availableBlocks.length > 0 && result.visualization}
<div class="visualization-section">
@@ -428,6 +384,49 @@
</div>
</div>
{/if}
{#if result.availableBlocks.length > 0}
<div class="free-blocks-grid">
{#each result.availableBlocks as block, index (index)}
{@const blockAddresses = (() => {
const match = block.match(/\/(\d+)$/);
if (!match) return 0;
const prefixLength = parseInt(match[1]);
const version = block.includes(':') ? 6 : 4;
const totalBits = version === 4 ? 32 : 128;
return Math.pow(2, totalBits - prefixLength);
})()}
<div class="free-block-card">
<div class="block-header">
<code class="block-cidr">{block}</code>
<button
class="copy-button {clipboard.isCopied(`block-${index}`) ? 'copied' : ''}"
onclick={() => clipboard.copy(block, `block-${index}`)}
aria-label="Copy CIDR block"
>
<Icon name={clipboard.isCopied(`block-${index}`) ? 'check' : 'copy'} size="xs" />
</button>
</div>
<div class="block-info">
<span class="address-count">
{formatNumber(blockAddresses)} addresses
</span>
{#if targetPrefix && blockAddresses >= Math.pow(2, 32 - targetPrefix)}
<span class="can-fit">
<Icon name="check-circle" size="xs" />
Can fit /{targetPrefix}
</span>
{/if}
</div>
</div>
{/each}
</div>
{:else}
<div class="no-gaps">
<Icon name="alert-circle" />
<h4>No Available Space</h4>
<p>All address space in the pools is allocated or there are no pools defined.</p>
</div>
{/if}
{:else}
<div class="error-message">
<Icon name="alert-triangle" />
@@ -507,7 +506,7 @@
gap: var(--spacing-md);
h3 {
color: var(--color-success-light);
color: var(--color-primary);
margin: 0;
}
}
@@ -560,7 +559,7 @@
font-family: var(--font-mono);
font-size: var(--font-size-md);
font-weight: 600;
color: var(--color-success-light);
color: var(--color-success);
background-color: var(--bg-tertiary);
padding: var(--spacing-xs);
border-radius: var(--radius-sm);
@@ -656,7 +655,7 @@
border-radius: var(--radius-lg);
h4 {
color: var(--color-info-light);
color: var(--text-primary);
margin-bottom: var(--spacing-md);
text-align: center;
}
@@ -6,11 +6,9 @@
interface Props {
mode: 'expand' | 'compress';
title: string;
description: string;
}
let { mode, title, description }: Props = $props();
let { mode }: Props = $props();
let inputAddress = $state('2001:db8::1');
let outputAddress = $state('');
@@ -92,210 +90,132 @@
});
</script>
<div class="card converter-card">
<header class="card-header">
<div class="header-content">
<div class="header-text">
<h2>{title}</h2>
<p>{description}</p>
</div>
<div class="header-actions">
<a
href={mode === 'expand'
? '/ip-address-convertor/notation/ipv6-compress'
: '/ip-address-convertor/notation/ipv6-expand'}
class="mode-switch-btn"
title="Switch to {mode === 'expand' ? 'Compress' : 'Expand'} mode"
<!-- Input Section -->
<div class="converter-section">
<h3>Input IPv6 Address</h3>
<div class="input-group">
<div class="form-group">
<label for="ipv6-input">
IPv6 Address
<Tooltip
text={mode === 'expand'
? 'Enter compressed IPv6 address to expand'
: 'Enter expanded IPv6 address to compress'}
>
<Icon name={mode === 'expand' ? 'ipv6-compress' : 'ipv6-expand'} size="sm" />
<span>{mode === 'expand' ? 'Compress' : 'Expand'}</span>
</a>
</div>
</div>
</header>
<!-- Input Section -->
<div class="converter-section">
<h3>Input IPv6 Address</h3>
<div class="input-group">
<div class="form-group">
<label for="ipv6-input">
IPv6 Address
<Tooltip
text={mode === 'expand'
? 'Enter compressed IPv6 address to expand'
: 'Enter expanded IPv6 address to compress'}
>
<Icon name="help" size="sm" />
</Tooltip>
</label>
<div class="input-wrapper">
<input
id="ipv6-input"
type="text"
bind:value={inputAddress}
oninput={handleInput}
placeholder={mode === 'expand' ? '2001:db8::1' : '2001:0db8:0000:0000:0000:0000:0000:0001'}
class="ipv6-input"
/>
<button type="button" class="btn btn-secondary btn-md" onclick={clearAll}>
<Icon name="trash" size="md" />
</button>
</div>
{#if conversionError}
<p class="error-message">{conversionError}</p>
{/if}
<Icon name="help" size="sm" />
</Tooltip>
</label>
<div class="input-wrapper">
<input
id="ipv6-input"
type="text"
bind:value={inputAddress}
oninput={handleInput}
placeholder={mode === 'expand' ? '2001:db8::1' : '2001:0db8:0000:0000:0000:0000:0000:0001'}
class="ipv6-input"
/>
<button type="button" class="btn btn-secondary btn-md" onclick={clearAll}>
<Icon name="trash" size="md" />
</button>
</div>
{#if conversionError}
<p class="error-message">{conversionError}</p>
{/if}
</div>
</div>
<!-- Examples Section -->
<div class="examples-section">
<details class="examples-details">
<summary class="examples-summary">
<Icon name="chevron-right" size="xs" />
<h3>Common Examples</h3>
</summary>
<div class="examples-grid">
{#each exampleAddresses as example, index (`example-${index}`)}
<button
type="button"
class="example-btn"
class:selected={selectedExampleIndex === index}
onclick={() => setExample(mode === 'expand' ? example.compressed : example.expanded, index)}
>
<div class="example-label">{example.label}</div>
<code class="example-address">
{mode === 'expand' ? example.compressed : example.expanded}
</code>
</button>
{/each}
</div>
</details>
</div>
<!-- Output Section -->
{#if outputAddress && !conversionError}
<div class="output-section">
<h3>Converted Address</h3>
<div class="conversion-result">
<div class="result-card success">
<div class="result-header">
<h4>
<Icon name={mode === 'expand' ? 'maximize' : 'minimize'} size="sm" />
{mode === 'expand' ? 'Expanded Format' : 'Compressed Format'}
</h4>
</div>
<div class="result-content">
<div class="address-display">
<div class="address-wrapper">
<code class="converted-address">{outputAddress}</code>
<button
type="button"
class="btn btn-icon copy-btn"
class:copied={clipboard.isCopied('output')}
onclick={() => clipboard.copy(outputAddress, 'output')}
>
<Icon name={clipboard.isCopied('output') ? 'check' : 'copy'} size="sm" />
</button>
</div>
</div>
<!-- Comparison View -->
<div class="comparison-view">
<div class="comparison-item">
<span class="comparison-label">Input ({mode === 'expand' ? 'Compressed' : 'Expanded'}):</span>
<code class="comparison-address input">{inputAddress}</code>
</div>
<div class="comparison-item">
<span class="comparison-label">Output ({mode === 'expand' ? 'Expanded' : 'Compressed'}):</span>
<code class="comparison-address output">{outputAddress}</code>
</div>
</div>
<!-- Character Count -->
<div class="stats-grid">
<div class="stat-item">
<span class="stat-label">Input Length</span>
<span class="stat-value">{inputAddress.length} characters</span>
</div>
<div class="stat-item">
<span class="stat-label">Output Length</span>
<span class="stat-value">{outputAddress.length} characters</span>
</div>
<div class="stat-item">
<span class="stat-label">Difference</span>
<span class="stat-value {outputAddress.length > inputAddress.length ? 'expanded' : 'compressed'}">
{outputAddress.length > inputAddress.length ? '+' : ''}{outputAddress.length - inputAddress.length} characters
</span>
</div>
</div>
</div>
</div>
</div>
</div>
{/if}
</div>
<!-- Examples Section -->
<div class="examples-section">
<details class="examples-details">
<summary class="examples-summary">
<Icon name="chevron-right" size="xs" />
<h3>Common Examples</h3>
</summary>
<div class="examples-grid">
{#each exampleAddresses as example, index (`example-${index}`)}
<button
type="button"
class="example-btn"
class:selected={selectedExampleIndex === index}
onclick={() => setExample(mode === 'expand' ? example.compressed : example.expanded, index)}
>
<div class="example-label">{example.label}</div>
<code class="example-address">
{mode === 'expand' ? example.compressed : example.expanded}
</code>
</button>
{/each}
</div>
</details>
</div>
<!-- Output Section -->
{#if outputAddress && !conversionError}
<div class="output-section">
<h3>Converted Address</h3>
<div class="conversion-result">
<div class="result-card success">
<div class="result-header">
<h4>
<Icon name={mode === 'expand' ? 'maximize' : 'minimize'} size="sm" />
{mode === 'expand' ? 'Expanded Format' : 'Compressed Format'}
</h4>
</div>
<div class="result-content">
<div class="address-display">
<div class="address-wrapper">
<code class="converted-address">{outputAddress}</code>
<button
type="button"
class="btn btn-icon copy-btn"
class:copied={clipboard.isCopied('output')}
onclick={() => clipboard.copy(outputAddress, 'output')}
>
<Icon name={clipboard.isCopied('output') ? 'check' : 'copy'} size="sm" />
</button>
</div>
</div>
<!-- Comparison View -->
<div class="comparison-view">
<div class="comparison-item">
<span class="comparison-label">Input ({mode === 'expand' ? 'Compressed' : 'Expanded'}):</span>
<code class="comparison-address input">{inputAddress}</code>
</div>
<div class="comparison-item">
<span class="comparison-label">Output ({mode === 'expand' ? 'Expanded' : 'Compressed'}):</span>
<code class="comparison-address output">{outputAddress}</code>
</div>
</div>
<!-- Character Count -->
<div class="stats-grid">
<div class="stat-item">
<span class="stat-label">Input Length</span>
<span class="stat-value">{inputAddress.length} characters</span>
</div>
<div class="stat-item">
<span class="stat-label">Output Length</span>
<span class="stat-value">{outputAddress.length} characters</span>
</div>
<div class="stat-item">
<span class="stat-label">Difference</span>
<span class="stat-value {outputAddress.length > inputAddress.length ? 'expanded' : 'compressed'}">
{outputAddress.length > inputAddress.length ? '+' : ''}{outputAddress.length - inputAddress.length} characters
</span>
</div>
</div>
</div>
</div>
</div>
</div>
{/if}
<style>
.converter-card {
max-width: none;
}
.header-content {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: var(--spacing-lg);
}
.header-text {
flex: 1;
}
.header-actions {
display: flex;
flex-shrink: 0;
}
.mode-switch-btn {
display: flex;
align-items: center;
gap: var(--spacing-sm);
padding: var(--spacing-sm) var(--spacing-md);
background-color: var(--bg-secondary);
border: 2px solid var(--border-primary);
border-radius: var(--radius-md);
color: var(--text-primary);
text-decoration: none;
font-weight: 600;
font-size: var(--font-size-sm);
transition: all var(--transition-fast);
&:hover {
background-color: var(--surface-hover);
border-color: var(--color-primary);
color: var(--color-primary);
transform: translateY(-2px);
box-shadow: var(--shadow-sm);
}
&:active {
transform: translateY(0);
}
:global(.icon) {
transition: transform var(--transition-fast);
}
&:hover :global(.icon) {
transform: scale(1.1);
}
}
.converter-section,
.examples-section,
.output-section {
@@ -602,22 +522,6 @@
}
@media (max-width: 768px) {
.header-content {
flex-direction: column;
align-items: stretch;
gap: var(--spacing-md);
}
.header-actions {
justify-content: center;
}
.mode-switch-btn {
justify-content: center;
padding: var(--spacing-md);
font-size: var(--font-size-md);
}
.examples-grid {
grid-template-columns: 1fr;
}
@@ -7,7 +7,22 @@
} from '$lib/utils/ipv6-subnet-calculations.js';
import Tooltip from '$lib/components/global/Tooltip.svelte';
import Icon from '$lib/components/global/Icon.svelte';
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import { useClipboard } from '$lib/composables';
import { goto } from '$app/navigation';
const versionOptions = [
{ value: 'ipv4' as const, label: 'IPv4' },
{ value: 'ipv6' as const, label: 'IPv6' },
];
let selectedVersion = $state<'ipv4' | 'ipv6'>('ipv6');
function handleVersionChange(version: 'ipv4' | 'ipv6') {
if (version === 'ipv4') {
goto('/subnetting/ipv4-subnet-calculator');
}
}
let networkAddress = $state('2001:db8::/64');
let prefixLength = $state(64);
@@ -88,12 +103,14 @@
// activePreset is now derived automatically
</script>
<div class="card ipv6-calc-card">
<header class="card-header">
<h2>IPv6 Subnet Calculator</h2>
<p>Calculate IPv6 subnet information with 128-bit addressing and modern network prefix notation.</p>
</header>
<ToolContentContainer
title="IPv6 Subnet Calculator"
description="Calculate IPv6 subnet information with 128-bit addressing and modern network prefix notation."
navOptions={versionOptions}
bind:selectedNav={selectedVersion}
onNavChange={handleVersionChange}
contentClass="ipv6-calc-card"
>
<!-- Input Section -->
<div class="input-section">
<h3>Network Configuration</h3>
@@ -414,13 +431,13 @@
</div>
</div>
{/if}
</div>
</ToolContentContainer>
<style>
.ipv6-calc-card .btn :global(.icon) {
width: 1rem;
height: 1rem;
.btn {
vertical-align: middle;
display: flex;
gap: var(--spacing-sm);
}
.input-section {
@@ -480,7 +480,7 @@
class="btn btn-secondary btn-xs"
onclick={() => (showVisualization = !showVisualization)}
>
<Icon name="eye-off" size="sm" />
<Icon name="hide" size="sm" />
Hide
</button>
</div>
@@ -6,10 +6,25 @@
import NetworkVisualizer from '$lib/components/tools/NetworkVisualizer.svelte';
import Tooltip from '$lib/components/global/Tooltip.svelte';
import SvgIcon from '$lib/components/global/SvgIcon.svelte';
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import { tooltip } from '$lib/actions/tooltip.js';
import { useClipboard } from '$lib/composables';
import { goto } from '$app/navigation';
import type { SubnetInfo } from '$lib/types/ip.js';
const versionOptions = [
{ value: 'ipv4' as const, label: 'IPv4' },
{ value: 'ipv6' as const, label: 'IPv6' },
];
let selectedVersion = $state<'ipv4' | 'ipv6'>('ipv4');
function handleVersionChange(version: 'ipv4' | 'ipv6') {
if (version === 'ipv6') {
goto('/subnetting/ipv6-subnet-calculator');
}
}
let cidrInput = $state('192.168.1.0/24');
let subnetInfo: SubnetInfo | null = $state(null);
let isCalculating = $state(false);
@@ -38,12 +53,13 @@
const clipboard = useClipboard();
</script>
<div class="card">
<header class="card-header">
<h2>Subnet Calculator</h2>
<p>Calculate network, broadcast, and host information for any subnet.</p>
</header>
<ToolContentContainer
title="Subnet Calculator"
description="Calculate network, broadcast, and host information for any subnet."
navOptions={versionOptions}
bind:selectedNav={selectedVersion}
onNavChange={handleVersionChange}
>
<!-- Input -->
<div class="form-group">
<CIDRInput bind:value={cidrInput} label="Network Address (CIDR)" placeholder="192.168.1.0/24" />
@@ -251,7 +267,7 @@
</ul>
</div>
</section>
</div>
</ToolContentContainer>
<style lang="scss">
.explainer-section {
@@ -283,6 +299,10 @@
}
}
.value-copy {
flex: none;
}
.explainer-card {
cursor: default;
}
+12 -10
View File
@@ -3,6 +3,7 @@
import { tooltip } from '$lib/actions/tooltip.js';
import _Tooltip from '$lib/components/global/Tooltip.svelte';
import Icon from '$lib/components/global/Icon.svelte';
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import { useClipboard } from '$lib/composables';
import { formatNumber } from '$lib/utils/formatters';
@@ -210,12 +211,10 @@
});
</script>
<div class="card">
<header class="card-header">
<h2>Subnet Planner (VLSM)</h2>
<p>Design Variable Length Subnet Mask (VLSM) allocations with drag-and-drop reordering and space optimization.</p>
</header>
<ToolContentContainer
title="Subnet Planner (VLSM)"
description="Design Variable Length Subnet Mask (VLSM) allocations with drag-and-drop reordering and space optimization."
>
<!-- Strategy Selection -->
<div class="strategy-section">
<h3>Allocation Strategy</h3>
@@ -447,7 +446,7 @@
class="btn btn-secondary btn-xs"
onclick={() => (showVisualization = !showVisualization)}
>
<Icon name="eye-off" size="xs" />
<Icon name="hide" size="xs" />
Hide
</button>
</div>
@@ -574,7 +573,7 @@
{/if}
</div>
{/if}
</div>
</ToolContentContainer>
<style lang="scss">
/* Reusable tokens */
@@ -627,7 +626,6 @@
.options {
.checkbox-label {
display: flex;
align-items: flex-start;
gap: var(--spacing-sm);
cursor: pointer;
@@ -1153,7 +1151,7 @@
}
/* Responsive */
@media (max-width: 768px) {
@media (max-width: 600px) {
.requests-header {
flex-direction: column;
gap: var(--spacing-sm);
@@ -1162,7 +1160,11 @@
.request-item {
flex-direction: column;
align-items: flex-start;
gap: var(--spacing-sm);
.drag-handle {
display: none;
}
.request-fields {
width: 100%;
@@ -8,6 +8,7 @@
} from '$lib/utils/supernet-calculations.js';
import IPInput from './IPInput.svelte';
import Icon from '$lib/components/global/Icon.svelte';
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import { tooltip } from '$lib/actions/tooltip.js';
import { useClipboard } from '$lib/composables';
import { formatNumber } from '$lib/utils/formatters';
@@ -164,14 +165,11 @@
});
</script>
<div class="card supernet-calc-car">
<header class="card-header">
<h2>Supernet Calculator</h2>
<p>
Aggregate multiple networks into a single supernet for route summarization and efficient routing table management.
</p>
</header>
<ToolContentContainer
title="Supernet Calculator"
description="Aggregate multiple networks into a single supernet for route summarization and efficient routing table management."
contentClass="supernet-calc-car"
>
<!-- Quick Examples -->
<div class="card examples-card">
<details class="examples-details">
@@ -530,7 +528,7 @@
{/if}
</div>
{/if}
</div>
</ToolContentContainer>
<style>
.supernet-calc-car .btn {
@@ -10,6 +10,7 @@
import IPInput from './IPInput.svelte';
import Tooltip from '$lib/components/global/Tooltip.svelte';
import Icon from '$lib/components/global/Icon.svelte';
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import { useClipboard } from '$lib/composables';
import { tooltip } from '$lib/actions/tooltip.js';
import { SvelteSet } from 'svelte/reactivity';
@@ -135,12 +136,10 @@
});
</script>
<div class="card">
<header class="card-header">
<h2>VLSM Calculator</h2>
<p>Design efficient subnets with Variable Length Subnet Masking for optimal address space utilization.</p>
</header>
<ToolContentContainer
title="VLSM Calculator"
description="Design efficient subnets with Variable Length Subnet Masking for optimal address space utilization."
>
<!-- Network Configuration -->
<div class="network-config">
<h3>Network Configuration</h3>
@@ -414,7 +413,7 @@
{/if}
</div>
{/if}
</div>
</ToolContentContainer>
<style>
.btn {
+1
View File
@@ -261,6 +261,7 @@ export const iconMap: Record<string, string> = {
wifi: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d=""/><path d="M72.9 245.4C136.4 182.7 223.7 144 320.1 144C416.5 144 503.7 182.7 567.3 245.4C576.7 254.7 591.9 254.6 601.2 245.2C610.5 235.8 610.4 220.6 601 211.3C528.8 140 429.5 96 320.1 96C210.7 96 111.3 140 39.1 211.3C29.7 220.6 29.6 235.8 38.9 245.2C48.2 254.6 63.4 254.7 72.8 245.4zM320.1 320C373.7 320 421.7 343.9 454 381.7C462.6 391.8 477.8 393 487.8 384.4C497.8 375.8 499.1 360.6 490.5 350.6C449.5 302.6 388.3 272 320.1 272C251.9 272 190.8 302.5 149.7 350.6C141.1 360.7 142.3 375.8 152.4 384.4C162.5 393 177.6 391.8 186.2 381.7C218.5 343.9 266.5 320 320.1 320zM368.1 496C368.1 469.5 346.6 448 320.1 448C293.6 448 272.1 469.5 272.1 496C272.1 522.5 293.6 544 320.1 544C346.6 544 368.1 522.5 368.1 496z"/></svg>`,
sliders: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M112 432C112 449.7 126.3 464 144 464C161.7 464 176 449.7 176 432C176 414.3 161.7 400 144 400C126.3 400 112 414.3 112 432zM464 208C464 225.7 478.3 240 496 240C513.7 240 528 225.7 528 208C528 190.3 513.7 176 496 176C478.3 176 464 190.3 464 208z"/><path d="M144 464C126.3 464 112 449.7 112 432C112 414.3 126.3 400 144 400C161.7 400 176 414.3 176 432C176 449.7 161.7 464 144 464zM220.3 408C210.1 375.5 179.8 352 144 352C99.8 352 64 387.8 64 432C64 476.2 99.8 512 144 512C179.8 512 210.1 488.5 220.3 456L552 456C565.3 456 576 445.3 576 432C576 418.7 565.3 408 552 408L220.3 408zM528 208C528 225.7 513.7 240 496 240C478.3 240 464 225.7 464 208C464 190.3 478.3 176 496 176C513.7 176 528 190.3 528 208zM419.7 184L88 184C74.7 184 64 194.7 64 208C64 221.3 74.7 232 88 232L419.7 232C429.9 264.5 460.2 288 496 288C540.2 288 576 252.2 576 208C576 163.8 540.2 128 496 128C460.2 128 429.9 151.5 419.7 184z"/></svg>`,
'mac-lookup': `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M48 160L48 480C48 488.8 55.2 496 64 496L384 496C392.8 496 400 488.8 400 480L400 160C400 151.2 392.8 144 384 144L64 144C55.2 144 48 151.2 48 160zM96 216C96 202.7 106.7 192 120 192C133.3 192 144 202.7 144 216L144 296C144 309.3 133.3 320 120 320C106.7 320 96 309.3 96 296L96 216zM192 216C192 202.7 202.7 192 216 192C229.3 192 240 202.7 240 216L240 296C240 309.3 229.3 320 216 320C202.7 320 192 309.3 192 296L192 216z"/><path d="M384 144C392.8 144 400 151.2 400 160L400 480C400 488.8 392.8 496 384 496L64 496C55.2 496 48 488.8 48 480L48 160C48 151.2 55.2 144 64 144L384 144zM64 96C28.7 96 0 124.7 0 160L0 480C0 515.3 28.7 544 64 544L384 544C419.3 544 448 515.3 448 480L448 160C448 124.7 419.3 96 384 96L64 96zM120 192C106.7 192 96 202.7 96 216L96 296C96 309.3 106.7 320 120 320C133.3 320 144 309.3 144 296L144 216C144 202.7 133.3 192 120 192zM216 192C202.7 192 192 202.7 192 216L192 296C192 309.3 202.7 320 216 320C229.3 320 240 309.3 240 296L240 216C240 202.7 229.3 192 216 192zM597.3 172C608.3 164.6 611.3 149.7 604 138.7C596.7 127.7 581.7 124.7 570.7 132L522.7 164C511.7 171.4 508.7 186.3 516 197.3C523.3 208.3 538.3 211.3 549.3 204L597.3 172zM536 296C522.7 296 512 306.7 512 320C512 333.3 522.7 344 536 344L616 344C629.3 344 640 333.3 640 320C640 306.7 629.3 296 616 296L536 296zM549.3 436C538.3 428.6 523.4 431.6 516 442.7C508.6 453.8 511.6 468.6 522.7 476L570.7 508C581.7 515.4 596.6 512.4 604 501.3C611.4 490.2 608.4 475.4 597.3 468L549.3 436z"/></svg>`,
binary: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d=""/><path d="M456 88L456 240L488 240C501.3 240 512 250.7 512 264C512 277.3 501.3 288 488 288L376 288C362.7 288 352 277.3 352 264C352 250.7 362.7 240 376 240L408 240L408 121.3L391.6 126.8C379 131 365.4 124.2 361.2 111.6C357 99 363.8 85.4 376.4 81.2L424.4 65.2C431.7 62.8 439.8 64 446 68.5C452.2 73 456 80.3 456 88zM232 376L232 528L264 528C277.3 528 288 538.7 288 552C288 565.3 277.3 576 264 576L152 576C138.7 576 128 565.3 128 552C128 538.7 138.7 528 152 528L184 528L184 409.3L167.6 414.8C155 419 141.4 412.2 137.2 399.6C133 387 139.8 373.4 152.4 369.2L200.4 353.2C207.7 350.8 215.8 352 222 356.5C228.2 361 232 368.3 232 376zM128 128C128 92.7 156.7 64 192 64L256 64C291.3 64 320 92.7 320 128L320 224C320 259.3 291.3 288 256 288L192 288C156.7 288 128 259.3 128 224L128 128zM192 112C183.2 112 176 119.2 176 128L176 224C176 232.8 183.2 240 192 240L256 240C264.8 240 272 232.8 272 224L272 128C272 119.2 264.8 112 256 112L192 112zM384 352L448 352C483.3 352 512 380.7 512 416L512 512C512 547.3 483.3 576 448 576L384 576C348.7 576 320 547.3 320 512L320 416C320 380.7 348.7 352 384 352zM368 416L368 512C368 520.8 375.2 528 384 528L448 528C456.8 528 464 520.8 464 512L464 416C464 407.2 456.8 400 448 400L384 400C375.2 400 368 407.2 368 416z"/></svg>`,
// '': ``,
asterisk: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d=""/><path d="M320 64C333.3 64 344 74.7 344 88L344 278.3L508 183.2C519.5 176.5 534.2 180.5 540.8 191.9C547.4 203.3 543.5 218.1 532.1 224.7L367.8 320L532 415.2C543.5 421.8 547.4 436.5 540.7 448C534 459.5 519.4 463.4 507.9 456.7L344 361.7L344 552C344 565.3 333.3 576 320 576C306.7 576 296 565.3 296 552L296 361.7L132 456.8C120.5 463.5 105.8 459.5 99.2 448.1C92.6 436.7 96.5 421.9 108 415.2L272.2 320L108 224.8C96.5 218.1 92.6 203.4 99.2 192C105.8 180.6 120.5 176.6 132 183.3L296 278.3L296 88C296 74.7 306.7 64 320 64z"/></svg>`,
certificate: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2025 Fonticons, Inc.--><path opacity=".4" d="M208 128C208 119.2 215.2 112 224 112L336 112L336 200C336 239.8 368.2 272 408 272L496 272L496 512C496 520.8 488.8 528 480 528L288 528L288 504.8C317.8 473.3 336 430.8 336 384C336 303.4 281.9 235.5 208 214.6L208 128z"/><path d="M224 112L336 112L336 200C336 239.8 368.2 272 408 272L496 272L496 512C496 520.8 488.8 528 480 528L288 528L288 576L480 576C515.3 576 544 547.3 544 512L544 250.5C544 233.5 537.3 217.2 525.3 205.2L402.7 82.7C390.7 70.7 374.5 64 357.5 64L224 64C188.7 64 160 92.7 160 128L160 208C176.6 208 192.7 210.3 208 214.6L208 128C208 119.2 215.2 112 224 112zM384 131.9L476.1 224L408 224C394.7 224 384 213.3 384 200L384 131.9zM288 384C288 313.3 230.7 256 160 256C89.3 256 32 313.3 32 384C32 424.4 50.7 460.5 80 483.9L80 589C80 599.5 88.5 608 99 608C102.3 608 105.5 607.1 108.4 605.5L160 576L211.6 605.5C214.5 607.1 217.7 608 221 608C231.5 608 240 599.5 240 589L240 483.9C269.3 460.4 288 424.4 288 384zM160 336C186.5 336 208 357.5 208 384C208 410.5 186.5 432 160 432C133.5 432 112 410.5 112 384C112 357.5 133.5 336 160 336z"/></svg>`,
+7 -33
View File
@@ -2,6 +2,7 @@
import { convertRangeToCIDR, type RangeConversionResult } from '$lib/utils/range-to-cidr.js';
import { tooltip } from '$lib/actions/tooltip.js';
import Icon from '$lib/components/global/Icon.svelte';
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
let startIP = $state('192.168.1.10');
let endIP = $state('192.168.1.50');
@@ -95,12 +96,10 @@
});
</script>
<div class="card">
<header class="card-header">
<h2>IP Range to CIDR Converter</h2>
<p>Convert an IP address range (start IP → end IP) into the minimal set of CIDR blocks that cover the range</p>
</header>
<ToolContentContainer
title="IP Range to CIDR Converter"
description="Convert an IP address range (start IP → end IP) into the minimal set of CIDR blocks that cover the range"
>
<!-- Quick Examples -->
<div class="card examples-card">
<details class="examples-details">
@@ -286,35 +285,9 @@
<p>Useful for converting firewall rules, ACLs, or vendor-provided IP ranges to CIDR format.</p>
</div>
</div>
</div>
</ToolContentContainer>
<style lang="scss">
.card {
max-width: 90rem;
margin: 0 auto;
padding: var(--spacing-xl);
background: var(--bg-secondary);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-md);
}
.card-header {
margin-bottom: var(--spacing-xl);
h2 {
font-size: var(--font-size-2xl);
font-weight: 700;
color: var(--text-primary);
margin-bottom: var(--spacing-sm);
}
p {
font-size: var(--font-size-md);
color: var(--text-secondary);
line-height: 1.6;
}
}
// Examples card (matches diagnostics pages style)
.examples-card {
background: var(--bg-tertiary);
@@ -323,6 +296,7 @@
margin-bottom: var(--spacing-lg);
box-shadow: var(--shadow-sm);
overflow: hidden;
padding: 0;
.examples-details {
border: none;
+50 -10
View File
@@ -1,14 +1,54 @@
<script lang="ts">
import ToolsGrid from '$lib/components/global/ToolsGrid.svelte';
import { SUB_NAV, type NavGroup } from '$lib/constants/nav';
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import CIDRDiff from '$lib/components/tools/CIDRDiff.svelte';
import CIDROverlap from '$lib/components/tools/CIDROverlap.svelte';
import CIDRContains from '$lib/components/tools/CIDRContains.svelte';
// Extract set operations tools from the CIDR section
const cidrNav = SUB_NAV['/cidr'] || [];
const setOperationsGroup = cidrNav.find(
(item): item is NavGroup => 'title' in item && item.title === 'Set Operations',
);
const setOperationTools = setOperationsGroup?.items || [];
type ToolType = 'diff' | 'overlap' | 'contains';
let selectedTool = $state<ToolType>('diff');
const navOptions = [
{ value: 'diff' as const, label: 'Difference', icon: 'minus' },
{ value: 'overlap' as const, label: 'Overlap', icon: 'intersection' },
{ value: 'contains' as const, label: 'Contains', icon: 'containment' },
];
const toolDescriptions: Record<ToolType, { title: string; description: string }> = {
diff: {
title: 'CIDR Difference (A - B)',
description:
'Compute A - B where A and B are sets of IP addresses, CIDR blocks, or ranges. Shows minimal non-overlapping results.',
},
overlap: {
title: 'CIDR Overlap Checker (A ∩ B)',
description:
'Determine if two sets of IP addresses, CIDR blocks, or ranges intersect and show the overlapping regions.',
},
contains: {
title: 'CIDR Containment Checker (A ⊇ B)',
description:
'Check if set A fully contains each item in set B. Supports many-to-many containment analysis with detailed classification.',
},
};
function handleNavChange(value: ToolType) {
selectedTool = value;
}
</script>
<h2>Set Operation Tools</h2>
<ToolsGrid tools={setOperationTools} />
<ToolContentContainer
title={toolDescriptions[selectedTool].title}
description={toolDescriptions[selectedTool].description}
{navOptions}
bind:selectedNav={selectedTool}
onNavChange={handleNavChange}
>
{#if selectedTool === 'diff'}
<CIDRDiff />
{:else if selectedTool === 'overlap'}
<CIDROverlap />
{:else if selectedTool === 'contains'}
<CIDRContains />
{/if}
</ToolContentContainer>
@@ -1,7 +1,52 @@
<script lang="ts">
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import CIDRContains from '$lib/components/tools/CIDRContains.svelte';
import { SUB_NAV } from '$lib/constants/nav';
type ToolType = 'diff' | 'overlap' | 'contains';
let selectedTool = $state<ToolType>('contains');
// Extract set operations nav items from nav.ts
const setOperationsGroup = SUB_NAV['/cidr'].find((item) => 'title' in item && item.title === 'Set Operations');
const navItems = setOperationsGroup && 'items' in setOperationsGroup ? setOperationsGroup.items : [];
// Map icon names from nav.ts to match what the component expects
const iconMap: Record<string, string> = {
diff: 'minus',
intersection: 'intersection',
containment: 'containment',
};
// Map nav items to SegmentedControl format with hrefs
const navOptions = navItems.map((item) => ({
value: item.href.split('/').pop() as ToolType,
label: item.label.split(' ')[0], // Extract first word (Difference, Overlap, Contains)
icon: iconMap[item.icon || ''] || item.icon,
href: item.href,
}));
// Map nav items to tool descriptions
const toolDescriptions: Record<ToolType, { title: string; description: string }> = navItems.reduce(
(acc, item) => {
const key = item.href.split('/').pop() as ToolType;
acc[key] = {
title: item.label,
description: item.description || '',
};
return acc;
},
{} as Record<ToolType, { title: string; description: string }>,
);
</script>
<div class="page-container">
<ToolContentContainer
title={toolDescriptions[selectedTool].title}
description={toolDescriptions[selectedTool].description}
{navOptions}
hideLabels={true}
bind:selectedNav={selectedTool}
>
<CIDRContains />
</div>
</ToolContentContainer>
@@ -1,7 +1,52 @@
<script lang="ts">
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import CIDRDiff from '$lib/components/tools/CIDRDiff.svelte';
import { SUB_NAV } from '$lib/constants/nav';
type ToolType = 'diff' | 'overlap' | 'contains';
let selectedTool = $state<ToolType>('diff');
// Extract set operations nav items from nav.ts
const setOperationsGroup = SUB_NAV['/cidr'].find((item) => 'title' in item && item.title === 'Set Operations');
const navItems = setOperationsGroup && 'items' in setOperationsGroup ? setOperationsGroup.items : [];
// Map icon names from nav.ts to match what the component expects
const iconMap: Record<string, string> = {
diff: 'minus',
intersection: 'intersection',
containment: 'containment',
};
// Map nav items to SegmentedControl format with hrefs
const navOptions = navItems.map((item) => ({
value: item.href.split('/').pop() as ToolType,
label: item.label.split(' ')[0], // Extract first word (Difference, Overlap, Contains)
icon: iconMap[item.icon || ''] || item.icon,
href: item.href,
}));
// Map nav items to tool descriptions
const toolDescriptions: Record<ToolType, { title: string; description: string }> = navItems.reduce(
(acc, item) => {
const key = item.href.split('/').pop() as ToolType;
acc[key] = {
title: item.label,
description: item.description || '',
};
return acc;
},
{} as Record<ToolType, { title: string; description: string }>,
);
</script>
<div class="page-container">
<ToolContentContainer
title={toolDescriptions[selectedTool].title}
description={toolDescriptions[selectedTool].description}
{navOptions}
hideLabels={true}
bind:selectedNav={selectedTool}
>
<CIDRDiff />
</div>
</ToolContentContainer>
@@ -1,7 +1,52 @@
<script lang="ts">
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import CIDROverlap from '$lib/components/tools/CIDROverlap.svelte';
import { SUB_NAV } from '$lib/constants/nav';
type ToolType = 'diff' | 'overlap' | 'contains';
let selectedTool = $state<ToolType>('overlap');
// Extract set operations nav items from nav.ts
const setOperationsGroup = SUB_NAV['/cidr'].find((item) => 'title' in item && item.title === 'Set Operations');
const navItems = setOperationsGroup && 'items' in setOperationsGroup ? setOperationsGroup.items : [];
// Map icon names from nav.ts to match what the component expects
const iconMap: Record<string, string> = {
diff: 'minus',
intersection: 'intersection',
containment: 'containment',
};
// Map nav items to SegmentedControl format with hrefs
const navOptions = navItems.map((item) => ({
value: item.href.split('/').pop() as ToolType,
label: item.label.split(' ')[0],
icon: iconMap[item.icon || ''] || item.icon,
href: item.href,
}));
// Map nav items to tool descriptions
const toolDescriptions: Record<ToolType, { title: string; description: string }> = navItems.reduce(
(acc, item) => {
const key = item.href.split('/').pop() as ToolType;
acc[key] = {
title: item.label,
description: item.description || '',
};
return acc;
},
{} as Record<ToolType, { title: string; description: string }>,
);
</script>
<div class="page-container">
<ToolContentContainer
title={toolDescriptions[selectedTool].title}
description={toolDescriptions[selectedTool].description}
{navOptions}
hideLabels={true}
bind:selectedNav={selectedTool}
>
<CIDROverlap />
</div>
</ToolContentContainer>
@@ -1,9 +1,45 @@
<script lang="ts">
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import IPv6NotationConverter from '$lib/components/tools/IPv6NotationConverter.svelte';
type NotationType = 'expand' | 'compress';
let selectedTool = $state<NotationType>('compress');
const navOptions = [
{
value: 'expand' as const,
label: 'Expand',
icon: 'ipv6-expand',
href: '/ip-address-convertor/notation/ipv6-expand',
},
{
value: 'compress' as const,
label: 'Compress',
icon: 'ipv6-compress',
href: '/ip-address-convertor/notation/ipv6-compress',
},
];
const toolDescriptions: Record<NotationType, { title: string; description: string }> = {
expand: {
title: 'IPv6 Address Expander',
description:
'Convert compressed IPv6 addresses to their full 128-bit hexadecimal representation. This tool expands short IPv6 notation by adding leading zeros and replacing :: with the appropriate number of zero groups.',
},
compress: {
title: 'IPv6 Address Compressor',
description:
'Convert expanded IPv6 addresses to their compressed, shortened format. This tool uses :: notation to represent consecutive zero groups and removes leading zeros for a cleaner, more readable IPv6 address.',
},
};
</script>
<IPv6NotationConverter
mode="compress"
title="IPv6 Address Compressor"
description="Convert expanded IPv6 addresses to their compressed, shortened format. This tool uses :: notation to represent consecutive zero groups and removes leading zeros for a cleaner, more readable IPv6 address."
/>
<ToolContentContainer
title={toolDescriptions[selectedTool].title}
description={toolDescriptions[selectedTool].description}
{navOptions}
bind:selectedNav={selectedTool}
>
<IPv6NotationConverter mode="compress" />
</ToolContentContainer>
@@ -1,9 +1,45 @@
<script lang="ts">
import ToolContentContainer from '$lib/components/global/ToolContentContainer.svelte';
import IPv6NotationConverter from '$lib/components/tools/IPv6NotationConverter.svelte';
type NotationType = 'expand' | 'compress';
let selectedTool = $state<NotationType>('expand');
const navOptions = [
{
value: 'expand' as const,
label: 'Expand',
icon: 'ipv6-expand',
href: '/ip-address-convertor/notation/ipv6-expand',
},
{
value: 'compress' as const,
label: 'Compress',
icon: 'ipv6-compress',
href: '/ip-address-convertor/notation/ipv6-compress',
},
];
const toolDescriptions: Record<NotationType, { title: string; description: string }> = {
expand: {
title: 'IPv6 Address Expander',
description:
'Convert compressed IPv6 addresses to their full 128-bit hexadecimal representation. This tool expands short IPv6 notation by adding leading zeros and replacing :: with the appropriate number of zero groups.',
},
compress: {
title: 'IPv6 Address Compressor',
description:
'Convert expanded IPv6 addresses to their compressed, shortened format. This tool uses :: notation to represent consecutive zero groups and removes leading zeros for a cleaner, more readable IPv6 address.',
},
};
</script>
<IPv6NotationConverter
mode="expand"
title="IPv6 Address Expander"
description="Convert compressed IPv6 addresses to their full 128-bit hexadecimal representation. This tool expands short IPv6 notation by adding leading zeros and replacing :: with the appropriate number of zero groups."
/>
<ToolContentContainer
title={toolDescriptions[selectedTool].title}
description={toolDescriptions[selectedTool].description}
{navOptions}
bind:selectedNav={selectedTool}
>
<IPv6NotationConverter mode="expand" />
</ToolContentContainer>
@@ -1,8 +1,8 @@
<script lang="ts">
import IPv6SubnetCalculator from '$lib/components/tools/IPv6SubnetCalculator.svelte';
import Icon from '$lib/components/global/Icon.svelte';
import '$lib/../styles/pages.scss';
import Icon from '$lib/components/global/Icon.svelte';
</script>
<div class="page-container">
+33
View File
@@ -164,6 +164,10 @@ pre {
display: flex;
align-items: center;
justify-content: space-between;
&.col {
flex-direction: column;
align-items: flex-start;
}
}
.logo {
@@ -215,6 +219,35 @@ pre {
.card-header {
margin-bottom: var(--spacing-md);
display: flex;
// flex-direction: row;
justify-content: space-between;
align-items: flex-start;
@media (max-width: 768px) {
flex-direction: column;
align-items: center;
text-align: center;
p {
text-align: left;
}
}
}
.card-header .header-content {
flex: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.card-header .header-controls {
flex-shrink: 0;
@media (max-width: 768px) {
margin: 0 auto;
}
}
.card-header h2 {
+22
View File
@@ -1,4 +1,15 @@
/* Page Layout Styles */
.page-header-controls {
display: flex;
justify-content: flex-end;
margin-bottom: var(--spacing-lg);
animation: fadeIn 0.3s ease-out;
@media (max-width: 768px) {
justify-content: center;
}
}
.header-actions {
display: flex;
align-items: center;
@@ -125,3 +136,14 @@
}
}
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-5px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
+277
View File
@@ -0,0 +1,277 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { useClipboard } from '$lib/composables/useClipboard.svelte';
import { errorManager } from '$lib/utils/error-manager';
// Mock navigator.clipboard
const mockClipboard = {
writeText: vi.fn(),
};
Object.assign(navigator, {
clipboard: mockClipboard,
});
// Mock errorManager
vi.mock('$lib/utils/error-manager', () => ({
errorManager: {
captureException: vi.fn(),
},
}));
describe('useClipboard', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.useFakeTimers();
});
afterEach(() => {
vi.restoreAllMocks();
vi.useRealTimers();
});
describe('copy()', () => {
it('should successfully copy text to clipboard', async () => {
mockClipboard.writeText.mockResolvedValueOnce(undefined);
const clipboard = useClipboard();
const result = await clipboard.copy('test text');
expect(result).toBe(true);
expect(mockClipboard.writeText).toHaveBeenCalledWith('test text');
expect(mockClipboard.writeText).toHaveBeenCalledTimes(1);
});
it('should set copied state to true after copying', async () => {
mockClipboard.writeText.mockResolvedValueOnce(undefined);
const clipboard = useClipboard();
expect(clipboard.isCopied()).toBe(false);
await clipboard.copy('test text');
expect(clipboard.isCopied()).toBe(true);
});
it('should auto-reset copied state after default timeout (1500ms)', async () => {
mockClipboard.writeText.mockResolvedValueOnce(undefined);
const clipboard = useClipboard();
await clipboard.copy('test text');
expect(clipboard.isCopied()).toBe(true);
// Fast-forward time by 1500ms
vi.advanceTimersByTime(1500);
expect(clipboard.isCopied()).toBe(false);
});
it('should respect custom auto-reset timeout', async () => {
mockClipboard.writeText.mockResolvedValueOnce(undefined);
const clipboard = useClipboard(3000);
await clipboard.copy('test text');
expect(clipboard.isCopied()).toBe(true);
// After 1500ms, should still be copied
vi.advanceTimersByTime(1500);
expect(clipboard.isCopied()).toBe(true);
// After 3000ms total, should be reset
vi.advanceTimersByTime(1500);
expect(clipboard.isCopied()).toBe(false);
});
it('should handle multiple copy IDs independently', async () => {
mockClipboard.writeText.mockResolvedValue(undefined);
const clipboard = useClipboard();
await clipboard.copy('text 1', 'id1');
await clipboard.copy('text 2', 'id2');
expect(clipboard.isCopied('id1')).toBe(true);
expect(clipboard.isCopied('id2')).toBe(true);
// Advance time to reset id1
vi.advanceTimersByTime(1500);
expect(clipboard.isCopied('id1')).toBe(false);
expect(clipboard.isCopied('id2')).toBe(false);
});
it('should handle clipboard API failures gracefully', async () => {
const error = new Error('Clipboard access denied');
mockClipboard.writeText.mockRejectedValueOnce(error);
const clipboard = useClipboard();
const result = await clipboard.copy('test text');
expect(result).toBe(false);
expect(clipboard.isCopied()).toBe(false);
expect(errorManager.captureException).toHaveBeenCalledWith(
error,
'warn',
expect.objectContaining({
component: 'Clipboard',
action: 'copy',
id: 'default',
})
);
});
it('should log errors with custom ID', async () => {
const error = new Error('Clipboard error');
mockClipboard.writeText.mockRejectedValueOnce(error);
const clipboard = useClipboard();
await clipboard.copy('test text', 'custom-id');
expect(errorManager.captureException).toHaveBeenCalledWith(
error,
'warn',
expect.objectContaining({
component: 'Clipboard',
action: 'copy',
id: 'custom-id',
})
);
});
});
describe('isCopied()', () => {
it('should return false by default', () => {
const clipboard = useClipboard();
expect(clipboard.isCopied()).toBe(false);
});
it('should return false for non-existent ID', () => {
const clipboard = useClipboard();
expect(clipboard.isCopied('non-existent')).toBe(false);
});
it('should track multiple IDs separately', async () => {
mockClipboard.writeText.mockResolvedValue(undefined);
const clipboard = useClipboard();
await clipboard.copy('text 1', 'id1');
expect(clipboard.isCopied('id1')).toBe(true);
expect(clipboard.isCopied('id2')).toBe(false);
expect(clipboard.isCopied()).toBe(false);
});
});
describe('reset()', () => {
it('should manually reset copied state for specific ID', async () => {
mockClipboard.writeText.mockResolvedValueOnce(undefined);
const clipboard = useClipboard();
await clipboard.copy('test text', 'test-id');
expect(clipboard.isCopied('test-id')).toBe(true);
clipboard.reset('test-id');
expect(clipboard.isCopied('test-id')).toBe(false);
});
it('should reset default ID when no ID specified', async () => {
mockClipboard.writeText.mockResolvedValueOnce(undefined);
const clipboard = useClipboard();
await clipboard.copy('test text');
expect(clipboard.isCopied()).toBe(true);
clipboard.reset();
expect(clipboard.isCopied()).toBe(false);
});
it('should not affect other IDs', async () => {
mockClipboard.writeText.mockResolvedValue(undefined);
const clipboard = useClipboard();
await clipboard.copy('text 1', 'id1');
await clipboard.copy('text 2', 'id2');
clipboard.reset('id1');
expect(clipboard.isCopied('id1')).toBe(false);
expect(clipboard.isCopied('id2')).toBe(true);
});
});
describe('resetAll()', () => {
it('should reset all copied states', async () => {
mockClipboard.writeText.mockResolvedValue(undefined);
const clipboard = useClipboard();
await clipboard.copy('text 1', 'id1');
await clipboard.copy('text 2', 'id2');
await clipboard.copy('text 3', 'id3');
expect(clipboard.isCopied('id1')).toBe(true);
expect(clipboard.isCopied('id2')).toBe(true);
expect(clipboard.isCopied('id3')).toBe(true);
clipboard.resetAll();
expect(clipboard.isCopied('id1')).toBe(false);
expect(clipboard.isCopied('id2')).toBe(false);
expect(clipboard.isCopied('id3')).toBe(false);
});
it('should clear copiedStates object', async () => {
mockClipboard.writeText.mockResolvedValue(undefined);
const clipboard = useClipboard();
await clipboard.copy('text', 'test');
clipboard.resetAll();
expect(clipboard.copiedStates).toEqual({});
});
});
describe('copiedStates getter', () => {
it('should expose copiedStates as readonly', async () => {
mockClipboard.writeText.mockResolvedValue(undefined);
const clipboard = useClipboard();
await clipboard.copy('text 1', 'id1');
await clipboard.copy('text 2', 'id2');
const states = clipboard.copiedStates;
expect(states).toEqual({
id1: true,
id2: true,
});
});
});
describe('concurrent copy operations', () => {
it('should handle rapid successive copies', async () => {
mockClipboard.writeText.mockResolvedValue(undefined);
const clipboard = useClipboard();
await clipboard.copy('text 1');
await clipboard.copy('text 2');
await clipboard.copy('text 3');
expect(clipboard.isCopied()).toBe(true);
expect(mockClipboard.writeText).toHaveBeenCalledTimes(3);
});
it('should handle simultaneous copies with different IDs', async () => {
mockClipboard.writeText.mockResolvedValue(undefined);
const clipboard = useClipboard();
await Promise.all([
clipboard.copy('text 1', 'id1'),
clipboard.copy('text 2', 'id2'),
clipboard.copy('text 3', 'id3'),
]);
expect(clipboard.isCopied('id1')).toBe(true);
expect(clipboard.isCopied('id2')).toBe(true);
expect(clipboard.isCopied('id3')).toBe(true);
});
});
});
+359
View File
@@ -0,0 +1,359 @@
import { describe, it, expect } from 'vitest';
import {
formatBytes,
formatNumber,
getStatusClass,
formatMilliseconds,
formatPercentage,
} from '$lib/utils/formatters';
describe('formatters', () => {
describe('formatBytes()', () => {
it('should format zero as "0 B"', () => {
expect(formatBytes(0)).toBe('0 B');
});
it('should format bytes (< 1024)', () => {
expect(formatBytes(1)).toBe('1 B');
expect(formatBytes(512)).toBe('512 B');
expect(formatBytes(1023)).toBe('1023 B');
});
it('should format kilobytes', () => {
expect(formatBytes(1024)).toBe('1 KB');
expect(formatBytes(1536)).toBe('1.5 KB');
expect(formatBytes(2048)).toBe('2 KB');
expect(formatBytes(1048575)).toBe('1024 KB');
});
it('should format megabytes', () => {
expect(formatBytes(1048576)).toBe('1 MB');
expect(formatBytes(1572864)).toBe('1.5 MB');
expect(formatBytes(5242880)).toBe('5 MB');
});
it('should format gigabytes', () => {
expect(formatBytes(1073741824)).toBe('1 GB');
expect(formatBytes(1610612736)).toBe('1.5 GB');
expect(formatBytes(5368709120)).toBe('5 GB');
});
it('should format terabytes', () => {
expect(formatBytes(1099511627776)).toBe('1 TB');
expect(formatBytes(1649267441664)).toBe('1.5 TB');
});
it('should round to 2 decimal places', () => {
expect(formatBytes(1234)).toBe('1.21 KB');
expect(formatBytes(1234567)).toBe('1.18 MB');
expect(formatBytes(1234567890)).toBe('1.15 GB');
});
it('should handle very small values', () => {
expect(formatBytes(1)).toBe('1 B');
expect(formatBytes(10)).toBe('10 B');
});
it('should handle fractional bytes', () => {
expect(formatBytes(1024.5)).toBe('1 KB');
expect(formatBytes(1536.7)).toBe('1.5 KB');
});
});
describe('formatNumber()', () => {
it('should format zero', () => {
expect(formatNumber(0)).toBe('0');
});
it('should format single digit numbers', () => {
expect(formatNumber(1)).toBe('1');
expect(formatNumber(9)).toBe('9');
});
it('should format small numbers without separators', () => {
expect(formatNumber(10)).toBe('10');
expect(formatNumber(99)).toBe('99');
expect(formatNumber(999)).toBe('999');
});
it('should format thousands with separators', () => {
expect(formatNumber(1000)).toBe('1,000');
expect(formatNumber(1234)).toBe('1,234');
expect(formatNumber(9999)).toBe('9,999');
});
it('should format millions with separators', () => {
expect(formatNumber(1000000)).toBe('1,000,000');
expect(formatNumber(1234567)).toBe('1,234,567');
});
it('should format billions with separators', () => {
expect(formatNumber(1000000000)).toBe('1,000,000,000');
expect(formatNumber(1234567890)).toBe('1,234,567,890');
});
it('should handle negative numbers', () => {
expect(formatNumber(-1)).toBe('-1');
expect(formatNumber(-1000)).toBe('-1,000');
expect(formatNumber(-1234567)).toBe('-1,234,567');
});
it('should handle decimal numbers', () => {
expect(formatNumber(1234.56)).toBe('1,234.56');
expect(formatNumber(1000000.123)).toBe('1,000,000.123');
});
it('should handle very large numbers', () => {
expect(formatNumber(1000000000000)).toBe('1,000,000,000,000');
expect(formatNumber(999999999999999)).toBe('999,999,999,999,999');
});
it('should handle fractional values', () => {
expect(formatNumber(0.5)).toBe('0.5');
expect(formatNumber(0.123)).toBe('0.123');
expect(formatNumber(1.5)).toBe('1.5');
});
});
describe('getStatusClass()', () => {
describe('2xx - Success', () => {
it('should return "success" for 200 OK', () => {
expect(getStatusClass(200)).toBe('success');
});
it('should return "success" for 201 Created', () => {
expect(getStatusClass(201)).toBe('success');
});
it('should return "success" for 204 No Content', () => {
expect(getStatusClass(204)).toBe('success');
});
it('should return "success" for any 2xx code', () => {
expect(getStatusClass(299)).toBe('success');
});
});
describe('3xx - Redirection', () => {
it('should return "warning" for 301 Moved Permanently', () => {
expect(getStatusClass(301)).toBe('warning');
});
it('should return "warning" for 302 Found', () => {
expect(getStatusClass(302)).toBe('warning');
});
it('should return "warning" for 304 Not Modified', () => {
expect(getStatusClass(304)).toBe('warning');
});
it('should return "warning" for any 3xx code', () => {
expect(getStatusClass(399)).toBe('warning');
});
});
describe('4xx - Client Error', () => {
it('should return "error" for 400 Bad Request', () => {
expect(getStatusClass(400)).toBe('error');
});
it('should return "error" for 401 Unauthorized', () => {
expect(getStatusClass(401)).toBe('error');
});
it('should return "error" for 403 Forbidden', () => {
expect(getStatusClass(403)).toBe('error');
});
it('should return "error" for 404 Not Found', () => {
expect(getStatusClass(404)).toBe('error');
});
it('should return "error" for any 4xx code', () => {
expect(getStatusClass(499)).toBe('error');
});
});
describe('5xx - Server Error', () => {
it('should return "error" for 500 Internal Server Error', () => {
expect(getStatusClass(500)).toBe('error');
});
it('should return "error" for 502 Bad Gateway', () => {
expect(getStatusClass(502)).toBe('error');
});
it('should return "error" for 503 Service Unavailable', () => {
expect(getStatusClass(503)).toBe('error');
});
it('should return "error" for any 5xx code', () => {
expect(getStatusClass(599)).toBe('error');
});
});
describe('Edge cases', () => {
it('should return empty string for codes < 200', () => {
expect(getStatusClass(100)).toBe('');
expect(getStatusClass(199)).toBe('');
});
it('should return empty string for 0', () => {
expect(getStatusClass(0)).toBe('');
});
it('should return empty string for negative codes', () => {
expect(getStatusClass(-1)).toBe('');
});
it('should handle 600+ codes as error', () => {
expect(getStatusClass(600)).toBe('error');
expect(getStatusClass(999)).toBe('error');
});
});
});
describe('formatMilliseconds()', () => {
it('should format with default 0 decimals', () => {
expect(formatMilliseconds(0)).toBe('0ms');
expect(formatMilliseconds(1)).toBe('1ms');
expect(formatMilliseconds(100)).toBe('100ms');
expect(formatMilliseconds(1234)).toBe('1234ms');
});
it('should format with 1 decimal place', () => {
expect(formatMilliseconds(1234, 1)).toBe('1234.0ms');
expect(formatMilliseconds(1234.5, 1)).toBe('1234.5ms');
expect(formatMilliseconds(1234.56, 1)).toBe('1234.6ms');
});
it('should format with 2 decimal places', () => {
expect(formatMilliseconds(1234, 2)).toBe('1234.00ms');
expect(formatMilliseconds(1234.5, 2)).toBe('1234.50ms');
expect(formatMilliseconds(1234.56, 2)).toBe('1234.56ms');
expect(formatMilliseconds(1234.567, 2)).toBe('1234.57ms');
});
it('should format with 3 decimal places', () => {
expect(formatMilliseconds(1234.567, 3)).toBe('1234.567ms');
expect(formatMilliseconds(1234.5678, 3)).toBe('1234.568ms');
});
it('should handle zero with decimals', () => {
expect(formatMilliseconds(0, 2)).toBe('0.00ms');
expect(formatMilliseconds(0, 3)).toBe('0.000ms');
});
it('should handle negative values', () => {
expect(formatMilliseconds(-100)).toBe('-100ms');
expect(formatMilliseconds(-100, 2)).toBe('-100.00ms');
});
it('should handle very small values', () => {
expect(formatMilliseconds(0.1, 2)).toBe('0.10ms');
expect(formatMilliseconds(0.001, 3)).toBe('0.001ms');
});
it('should handle large values', () => {
expect(formatMilliseconds(60000)).toBe('60000ms');
expect(formatMilliseconds(60000, 1)).toBe('60000.0ms');
});
});
describe('formatPercentage()', () => {
it('should format with default 0 decimals', () => {
expect(formatPercentage(0)).toBe('0%');
expect(formatPercentage(0.5)).toBe('50%');
expect(formatPercentage(0.75)).toBe('75%');
expect(formatPercentage(1)).toBe('100%');
});
it('should format with 1 decimal place', () => {
expect(formatPercentage(0.5, 1)).toBe('50.0%');
expect(formatPercentage(0.755, 1)).toBe('75.5%');
expect(formatPercentage(0.7567, 1)).toBe('75.7%');
});
it('should format with 2 decimal places', () => {
expect(formatPercentage(0.5, 2)).toBe('50.00%');
expect(formatPercentage(0.7567, 2)).toBe('75.67%');
expect(formatPercentage(0.123456, 2)).toBe('12.35%');
});
it('should format with 3 decimal places', () => {
expect(formatPercentage(0.123456, 3)).toBe('12.346%');
expect(formatPercentage(0.999999, 3)).toBe('100.000%');
});
it('should handle 0 percent', () => {
expect(formatPercentage(0)).toBe('0%');
expect(formatPercentage(0, 2)).toBe('0.00%');
});
it('should handle 100 percent', () => {
expect(formatPercentage(1)).toBe('100%');
expect(formatPercentage(1, 2)).toBe('100.00%');
});
it('should handle values > 1', () => {
expect(formatPercentage(1.5)).toBe('150%');
expect(formatPercentage(2)).toBe('200%');
expect(formatPercentage(2.5, 1)).toBe('250.0%');
});
it('should handle negative values', () => {
expect(formatPercentage(-0.5)).toBe('-50%');
expect(formatPercentage(-0.25, 2)).toBe('-25.00%');
});
it('should handle very small percentages', () => {
expect(formatPercentage(0.001)).toBe('0%');
expect(formatPercentage(0.001, 1)).toBe('0.1%');
expect(formatPercentage(0.001, 2)).toBe('0.10%');
});
it('should handle very large percentages', () => {
expect(formatPercentage(10)).toBe('1000%');
expect(formatPercentage(100)).toBe('10000%');
});
it('should round correctly', () => {
expect(formatPercentage(0.456, 0)).toBe('46%');
expect(formatPercentage(0.454, 0)).toBe('45%');
expect(formatPercentage(0.9999, 2)).toBe('99.99%');
});
});
describe('Integration scenarios', () => {
it('should format network efficiency metrics consistently', () => {
const totalAddresses = 256;
const usableHosts = 254;
const utilization = usableHosts / totalAddresses;
expect(formatNumber(totalAddresses)).toBe('256');
expect(formatNumber(usableHosts)).toBe('254');
expect(formatPercentage(utilization, 1)).toBe('99.2%');
});
it('should format file sizes consistently', () => {
const sizes = [512, 1536, 5242880];
const formatted = sizes.map(formatBytes);
expect(formatted).toEqual(['512 B', '1.5 KB', '5 MB']);
});
it('should format HTTP response metrics', () => {
const statuses = [200, 301, 404, 500];
const classes = statuses.map(getStatusClass);
expect(classes).toEqual(['success', 'warning', 'error', 'error']);
});
it('should format timing data consistently', () => {
const responseTime = 1234.567;
expect(formatMilliseconds(responseTime)).toBe('1235ms');
expect(formatMilliseconds(responseTime, 2)).toBe('1234.57ms');
});
});
});