From 5b5f0f7fe1de706dbe8efdb0306337b32aef4107 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Thu, 16 Oct 2025 06:59:32 +0100 Subject: [PATCH] Refactored a lot of things. --- .../components/global/SegmentedControl.svelte | 167 +++++ .../global/ToolContentContainer.svelte | 78 +++ .../components/home/HomepageBookmarks.svelte | 91 +-- src/lib/components/tools/CIDRCompare.svelte | 4 + src/lib/components/tools/CIDRContains.svelte | 585 +++++++++--------- .../components/tools/CIDRDeaggregate.svelte | 7 +- src/lib/components/tools/CIDRDiff.svelte | 573 +++++++++-------- src/lib/components/tools/CIDROverlap.svelte | 576 +++++++++-------- .../components/tools/DKIMKeyGenerator.svelte | 4 +- .../components/tools/FreeSpaceFinder.svelte | 93 ++- .../tools/IPv6NotationConverter.svelte | 336 ++++------ .../tools/IPv6SubnetCalculator.svelte | 37 +- src/lib/components/tools/NextAvailable.svelte | 2 +- .../components/tools/SubnetCalculator.svelte | 34 +- src/lib/components/tools/SubnetPlanner.svelte | 22 +- .../tools/SupernetCalculator.svelte | 16 +- .../components/tools/VLSMCalculator.svelte | 13 +- src/lib/constants/icon-map.ts | 1 + src/routes/cidr/range-to-cidr/+page.svelte | 40 +- src/routes/cidr/set-operations/+page.svelte | 60 +- .../cidr/set-operations/contains/+page.svelte | 49 +- .../cidr/set-operations/diff/+page.svelte | 49 +- .../cidr/set-operations/overlap/+page.svelte | 49 +- .../notation/ipv6-compress/+page.svelte | 46 +- .../notation/ipv6-expand/+page.svelte | 46 +- .../ipv6-subnet-calculator/+page.svelte | 2 +- src/styles/base.scss | 33 + src/styles/pages.scss | 22 + tests/unit/composables/useClipboard.test.ts | 277 +++++++++ tests/unit/utils/formatters.test.ts | 359 +++++++++++ 30 files changed, 2336 insertions(+), 1335 deletions(-) create mode 100644 src/lib/components/global/SegmentedControl.svelte create mode 100644 src/lib/components/global/ToolContentContainer.svelte create mode 100644 tests/unit/composables/useClipboard.test.ts create mode 100644 tests/unit/utils/formatters.test.ts diff --git a/src/lib/components/global/SegmentedControl.svelte b/src/lib/components/global/SegmentedControl.svelte new file mode 100644 index 0000000..2db1d72 --- /dev/null +++ b/src/lib/components/global/SegmentedControl.svelte @@ -0,0 +1,167 @@ + + +
+
+
+ {#each options as option (option.value)} + + {/each} +
+
+ + diff --git a/src/lib/components/global/ToolContentContainer.svelte b/src/lib/components/global/ToolContentContainer.svelte new file mode 100644 index 0000000..9acd4e2 --- /dev/null +++ b/src/lib/components/global/ToolContentContainer.svelte @@ -0,0 +1,78 @@ + + +
+
+
+

{title}

+

{description}

+
+ {#if navOptions && selectedNav !== undefined} +
+ +
+ {/if} +
+ + {#if contentClass} +
+ {@render children()} +
+ {:else} + {@render children()} + {/if} +
+ + diff --git a/src/lib/components/home/HomepageBookmarks.svelte b/src/lib/components/home/HomepageBookmarks.svelte index 7b8071d..5640518 100644 --- a/src/lib/components/home/HomepageBookmarks.svelte +++ b/src/lib/components/home/HomepageBookmarks.svelte @@ -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('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} -
- - - -
+ (activeView = value)} />
@@ -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; } diff --git a/src/lib/components/tools/CIDRCompare.svelte b/src/lib/components/tools/CIDRCompare.svelte index 442b4b6..6916453 100644 --- a/src/lib/components/tools/CIDRCompare.svelte +++ b/src/lib/components/tools/CIDRCompare.svelte @@ -839,4 +839,8 @@ align-items: stretch; } } + + textarea { + background: var(--bg-primary); + } diff --git a/src/lib/components/tools/CIDRContains.svelte b/src/lib/components/tools/CIDRContains.svelte index 0611729..d90bb8a 100644 --- a/src/lib/components/tools/CIDRContains.svelte +++ b/src/lib/components/tools/CIDRContains.svelte @@ -163,336 +163,326 @@ }); -
-
-

CIDR Containment Checker

-

- Check if set A fully contains each item in set B. Supports many-to-many containment analysis with detailed - classification. -

-
+ +
+

Options

+
+ + +
+
- -
-

Options

-
- - + +
+
+ +
+

+ Set A (Containers) + + + +

+
+ +
+
+ + +
+

+ Set B (Candidates) + + + +

+
+ +
- -
-
- -
-

- Set A (Containers) - - - -

-
- -
+
+ +
+ + +
+
+ + +

Quick Examples

+
+
+ {#each examples as example, i (example.label)} + + {/each}
+
+
+
- -
-

- Set B (Candidates) - - - -

-
- -
+ +{#if result} +
+ {#if result.errors.length > 0} +
+

Parse Errors

+
    + {#each result.errors as error (error)} +
  • {error}
  • + {/each} +
-
+ {/if} -
- -
- - -
-
- - -

Quick Examples

-
-
- {#each examples as example, i (example.label)} + {#if result.checks.length > 0} + +
+
+

Containment Analysis

+
+ +
+
+ +
+
+ Containers (A) + {result.stats.setA.count} items + {result.stats.setA.addresses} addresses +
+
+ Candidates (B) + {result.stats.totalChecked} items + checked for containment +
+
+ Inside + {result.stats.inside} + fully contained +
+
+ Equal + {result.stats.equal} + exact matches +
+
+ Partial + {result.stats.partial} + partial overlap +
+
+ Outside + {result.stats.outside} + no overlap +
+
+
+ + +
+

Containment Results

+
+
+
Candidate
+
Status
+
Coverage
+
Containers
+
Gaps
+
+ + {#each result.checks as check, index (`${check.input}-${index}`)} + {@const statusInfo = getStatusInfo(check.status)} +
+
+ {check.input} +
+
+
+ + {statusInfo.label} +
+
+
+
+
+ {check.coverage}% +
+
+
+ {#if check.matchingContainers.length > 0} +
+ {#each check.matchingContainers as container (container)} + {container} + {/each} +
+ {:else} + - + {/if} +
+
+ {#if check.gaps.length > 0} +
+ {#each check.gaps as gap (gap)} + {gap} + {/each} +
+ + {:else} + - + {/if} +
+
{/each}
-
-
-
+
- - {#if result} -
- {#if result.errors.length > 0} -
-

Parse Errors

-
    - {#each result.errors as error (error)} -
  • {error}
  • - {/each} -
-
- {/if} - - {#if result.checks.length > 0} - -
-
-

Containment Analysis

-
- - + + {#if result.visualization.length > 0} +
+

Containment Visualization

+
+
+
+ Candidate Range +
+
+
+ Container Coverage +
+
+
+ Uncovered Gaps
-
-
- Containers (A) - {result.stats.setA.count} items - {result.stats.setA.addresses} addresses -
-
- Candidates (B) - {result.stats.totalChecked} items - checked for containment -
-
- Inside - {result.stats.inside} - fully contained -
-
- Equal - {result.stats.equal} - exact matches -
-
- Partial - {result.stats.partial} - partial overlap -
-
- Outside - {result.stats.outside} - no overlap -
-
-
- - -
-

Containment Results

-
-
-
Candidate
-
Status
-
Coverage
-
Containers
-
Gaps
-
- - {#each result.checks as check, index (`${check.input}-${index}`)} +
+ {#each result.visualization as viz, index (viz.candidate)} + {@const check = result.checks[index]} {@const statusInfo = getStatusInfo(check.status)} -
-
- {check.input} -
-
-
+
+
+ {viz.candidate} +
- {statusInfo.label} + {statusInfo.label} ({check.coverage}%)
-
-
+ +
+ +
- {check.coverage}% -
-
-
- {#if check.matchingContainers.length > 0} -
- {#each check.matchingContainers as container (container)} - {container} - {/each} -
- {:else} - - - {/if} -
-
- {#if check.gaps.length > 0} -
- {#each check.gaps as gap (gap)} - {gap} - {/each} -
- - {:else} - - - {/if} -
-
- {/each} -
-
- - - {#if result.visualization.length > 0} -
-

Containment Visualization

-
-
-
- Candidate Range -
-
-
- Container Coverage -
-
-
- Uncovered Gaps -
-
- -
- {#each result.visualization as viz, index (viz.candidate)} - {@const check = result.checks[index]} - {@const statusInfo = getStatusInfo(check.status)} -
-
- {viz.candidate} -
- - {statusInfo.label} ({check.coverage}%) -
-
- -
+ +
+ {#each viz.containers as container (`${container.start}-${container.end}`)}
-
+ {/each} +
- -
- {#each viz.containers as container (`${container.start}-${container.end}`)} -
- {/each} -
- - -
- {#each viz.gaps as gap (`${gap.start}-${gap.end}`)} -
- {/each} -
+ +
+ {#each viz.gaps as gap (`${gap.start}-${gap.end}`)} +
+ {/each}
- {/each} -
+
+ {/each}
- {/if} +
{/if} -
- {/if} -
+ {/if} +
+{/if} diff --git a/src/lib/components/tools/CIDRDiff.svelte b/src/lib/components/tools/CIDRDiff.svelte index fffd867..e322430 100644 --- a/src/lib/components/tools/CIDRDiff.svelte +++ b/src/lib/components/tools/CIDRDiff.svelte @@ -190,327 +190,311 @@ }); -
-
-

CIDR Difference Calculator

-

- Compute A - B where A and B are sets of IP addresses, CIDR blocks, or ranges. Shows minimal non-overlapping - results. -

-
- - -
-

Alignment Mode

-
-
- {#each alignmentModes as mode (mode.value)} - - {/each} -
- - {#if alignment === 'constrained'} -
- - (userModified = true)} - min="8" - max="30" - class="input-field constraint-field" - /> -
- {/if} + +
+

Alignment Mode

+
+
+ {#each alignmentModes as mode (mode.value)} + + {/each}
+ + {#if alignment === 'constrained'} +
+ + (userModified = true)} + min="8" + max="30" + class="input-field constraint-field" + /> +
+ {/if}
+
- -
-
- -
-

- Set A (Base) -

-
- -
-
- - -
-

- Set B (Subtract) -

-
- -
+ +
+
+ +
+

+ Set A (Base) +

+
+
-
- -
- - -
-

- Quick Examples - - - -

-
- {#each examples as example (example.label)} - - {/each} + +
+

Set B (Subtract)

+
+
- - {#if result} -
- {#if result.errors.length > 0} -
-

Parse Errors

-
    - {#each result.errors as error (error)} -
  • {error}
  • - {/each} -
-
- {/if} +
+ +
- {#if result.ipv4.length > 0 || result.ipv6.length > 0} - -
-
-

Difference Results (A - B)

-
- - -
-
+ +
+

+ Quick Examples + + + +

+
+ {#each examples as example (example.label)} + + {/each} +
+
+
-
-
- Set A (Input) - {result.stats.inputA.count} items - {result.stats.inputA.addresses} addresses -
-
- Set B (Subtract) - {result.stats.inputB.count} items - {result.stats.inputB.addresses} addresses -
-
- Result (A - B) - {result.stats.output.count} CIDRs - {result.stats.output.addresses} addresses -
-
= 80 - ? 'high' - : result.stats.efficiency >= 50 - ? 'medium' - : 'low'} + +{#if result} +
+ {#if result.errors.length > 0} +
+

Parse Errors

+
    + {#each result.errors as error (error)} +
  • {error}
  • + {/each} +
+
+ {/if} + + {#if result.ipv4.length > 0 || result.ipv6.length > 0} + +
+
+

Difference Results (A - B)

+
+
+ + Text + +
- - {#if result.visualization.setA.length > 0} -
-

- Set Operation Visualization - - - -

-
-
-
- Set A (Base) -
-
-
- Set B (Subtract) -
-
-
- Result (A - B) -
+
+
+ Set A (Input) + {result.stats.inputA.count} items + {result.stats.inputA.addresses} addresses +
+
+ Set B (Subtract) + {result.stats.inputB.count} items + {result.stats.inputB.addresses} addresses +
+
+ Result (A - B) + {result.stats.output.count} CIDRs + {result.stats.output.addresses} addresses +
+
= 80 ? 'high' : result.stats.efficiency >= 50 ? 'medium' : 'low'} + > + Efficiency + {result.stats.efficiency}% + {result.stats.removed.addresses} removed +
+
+
+ + + {#if result.visualization.setA.length > 0} +
+

+ Set Operation Visualization + + + +

+
+
+
+ Set A (Base)
+
+
+ Set B (Subtract) +
+
+
+ Result (A - B) +
+
-
- - {#each result.visualization.setA as range (`${range.start}-${range.end}`)} -
- {/each} +
+ + {#each result.visualization.setA as range (`${range.start}-${range.end}`)} +
+ {/each} - - {#each result.visualization.setB as range (`${range.start}-${range.end}`)} -
- {/each} + + {#each result.visualization.setB as range (`${range.start}-${range.end}`)} +
+ {/each} - - {#each result.visualization.result as range (`${range.start}-${range.end}`)} -
+ + {#each result.visualization.result as range (`${range.start}-${range.end}`)} +
+ {/each} +
+
+ {/if} + + +
+ + {#if result.ipv4.length > 0} +
+
+

IPv4 Results ({result.ipv4.length})

+ +
+
+ {#each result.ipv4 as cidr (cidr)} +
+ {cidr} + +
{/each}
{/if} - -
- - {#if result.ipv4.length > 0} -
-
-

IPv4 Results ({result.ipv4.length})

- -
-
- {#each result.ipv4 as cidr (cidr)} -
- {cidr} - -
- {/each} -
+ + {#if result.ipv6.length > 0} +
+
+

IPv6 Results ({result.ipv6.length})

+
- {/if} - - - {#if result.ipv6.length > 0} -
-
-

IPv6 Results ({result.ipv6.length})

- -
-
- {#each result.ipv6 as cidr (cidr)} -
- {cidr} - -
- {/each} -
+
+ {#each result.ipv6 as cidr (cidr)} +
+ {cidr} + +
+ {/each}
- {/if} -
- {:else} -
-

No Results

-

The difference A - B resulted in an empty set. Set B completely contains or covers Set A.

-
- {/if} -
- {/if} -
+
+ {/if} +
+ {:else} +
+

No Results

+

The difference A - B resulted in an empty set. Set B completely contains or covers Set A.

+
+ {/if} +
+{/if}