mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-22 05:51:46 +03:00
Implemented color settings for user
This commit is contained in:
1 parent
1911ceae69
commit
db43e6aed7
7 files changed
+560
-44
No files matched your search
@@ -7,6 +7,8 @@
|
||||
import { navbarDisplay, navbarDisplayOptions, type NavbarDisplayMode } from '$lib/stores/navbarDisplay';
|
||||
import { homepageLayout, homepageLayoutOptions, type HomepageLayoutMode } from '$lib/stores/homepageLayout';
|
||||
import { customCss } from '$lib/stores/customCss';
|
||||
import { siteCustomization } from '$lib/stores/siteCustomization';
|
||||
import { primaryColor } from '$lib/stores/primaryColor';
|
||||
|
||||
interface Props {
|
||||
standalone?: boolean;
|
||||
@@ -26,6 +28,33 @@
|
||||
let validationErrors = $state<string[]>([]);
|
||||
let validationWarnings = $state<string[]>([]);
|
||||
let lastStoreValue = $state('');
|
||||
let siteTitleInput = $state('');
|
||||
let siteDescriptionInput = $state('');
|
||||
let siteIconUrlInput = $state('');
|
||||
let primaryColorInput = $state('');
|
||||
let lastColorStoreValue = $state('');
|
||||
let siteCustomizationErrors = $state<string[]>([]);
|
||||
let showCustomColorInput = $state(false);
|
||||
|
||||
// Preset color palette - bright & vivid
|
||||
const colorPalette = [
|
||||
'#1a75ff',
|
||||
'#7711ff',
|
||||
'#dd11ff',
|
||||
'#ff1aaa',
|
||||
'#ff1a1a',
|
||||
'#ff4422',
|
||||
'#ff7711',
|
||||
'#ffaa00',
|
||||
'#ffdd00',
|
||||
'#aadd00',
|
||||
'#11dd00',
|
||||
'#00ff77',
|
||||
'#00dddd',
|
||||
'#11bbff',
|
||||
'#44aaff',
|
||||
'#7777ff',
|
||||
];
|
||||
|
||||
// Sync cssInput with store when store changes (not when textarea changes)
|
||||
$effect(() => {
|
||||
@@ -35,6 +64,21 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Sync site customization inputs with store
|
||||
$effect(() => {
|
||||
siteTitleInput = $siteCustomization.title;
|
||||
siteDescriptionInput = $siteCustomization.description;
|
||||
siteIconUrlInput = $siteCustomization.iconUrl;
|
||||
});
|
||||
|
||||
// Sync primary color input with store (only when store changes)
|
||||
$effect(() => {
|
||||
if ($primaryColor !== lastColorStoreValue) {
|
||||
primaryColorInput = $primaryColor;
|
||||
lastColorStoreValue = $primaryColor;
|
||||
}
|
||||
});
|
||||
|
||||
// Language selection
|
||||
let selectedLanguage = $state('en');
|
||||
const languages = [
|
||||
@@ -98,6 +142,49 @@
|
||||
validationErrors = [];
|
||||
validationWarnings = [];
|
||||
}
|
||||
|
||||
// Handle site customization
|
||||
function handleApplySiteCustomization() {
|
||||
const data = {
|
||||
title: siteTitleInput.trim(),
|
||||
description: siteDescriptionInput.trim(),
|
||||
iconUrl: siteIconUrlInput.trim(),
|
||||
};
|
||||
|
||||
const validation = siteCustomization.validate(data);
|
||||
siteCustomizationErrors = validation.errors;
|
||||
|
||||
if (validation.isValid) {
|
||||
siteCustomization.set(data);
|
||||
// Reload to apply title/description/icon changes
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-save color when changed (only when user changes it, store validates)
|
||||
$effect(() => {
|
||||
const trimmed = primaryColorInput.trim();
|
||||
// Only save if different from store (prevents loop) - store handles validation
|
||||
if (trimmed && trimmed !== $primaryColor) {
|
||||
primaryColor.set(trimmed);
|
||||
lastColorStoreValue = trimmed;
|
||||
} else if (!trimmed && $primaryColor) {
|
||||
primaryColor.clear();
|
||||
lastColorStoreValue = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Reset color to default
|
||||
function handleResetColor() {
|
||||
primaryColorInput = '';
|
||||
}
|
||||
|
||||
function handleClearSiteCustomization() {
|
||||
siteCustomization.clear();
|
||||
siteCustomizationErrors = [];
|
||||
// Reload to apply changes
|
||||
window.location.reload();
|
||||
}
|
||||
</script>
|
||||
|
||||
{#snippet accessibilityOption(option: AccessibilityOption)}
|
||||
@@ -246,8 +333,110 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Custom CSS (only in standalone mode) -->
|
||||
<!-- Site Customization (only in standalone mode) -->
|
||||
{#if standalone}
|
||||
<div class="settings-section site-branding-section">
|
||||
<h3>Site Branding</h3>
|
||||
<p class="section-description">Customize the site title, description, and icon.</p>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="site-title">Site Title</label>
|
||||
<input
|
||||
id="site-title"
|
||||
type="text"
|
||||
bind:value={siteTitleInput}
|
||||
placeholder="Networking Toolbox"
|
||||
maxlength="100"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="site-description">Description</label>
|
||||
<input
|
||||
id="site-description"
|
||||
type="text"
|
||||
bind:value={siteDescriptionInput}
|
||||
placeholder="Your companion for all-things networking"
|
||||
maxlength="300"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="site-icon-url">Icon URL</label>
|
||||
<input
|
||||
id="site-icon-url"
|
||||
type="text"
|
||||
bind:value={siteIconUrlInput}
|
||||
placeholder="/favicon.svg or https://example.com/icon.png"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if siteCustomizationErrors.length > 0}
|
||||
<div class="validation-messages errors">
|
||||
<Icon name="alert-triangle" size="sm" />
|
||||
<div>
|
||||
{#each siteCustomizationErrors as error (error)}
|
||||
<p>{error}</p>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="css-actions">
|
||||
<button class="action-btn apply" onclick={handleApplySiteCustomization}>
|
||||
<Icon name="check" size="sm" />
|
||||
Apply
|
||||
</button>
|
||||
<button class="action-btn clear" onclick={handleClearSiteCustomization}>
|
||||
<Icon name="x" size="sm" />
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Primary Color (only in standalone mode) -->
|
||||
<div class="settings-section color-section">
|
||||
<h3>Primary Color</h3>
|
||||
<p class="section-description">Choose a primary color for the interface.</p>
|
||||
|
||||
<div class="color-palette">
|
||||
{#each colorPalette as color (color)}
|
||||
<button
|
||||
class="color-swatch"
|
||||
class:active={primaryColorInput === color}
|
||||
style="background-color: {color};"
|
||||
onclick={() => (primaryColorInput = color)}
|
||||
aria-label="Select color {color}"
|
||||
></button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="color-actions">
|
||||
<button class="custom-color-toggle" onclick={() => (showCustomColorInput = !showCustomColorInput)}>
|
||||
<Icon name="palette" size="sm" />
|
||||
Use Custom Color
|
||||
</button>
|
||||
<button class="action-btn clear" onclick={handleResetColor}>
|
||||
<Icon name="undo" size="sm" />
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if showCustomColorInput}
|
||||
<div class="custom-color-inputs" transition:slide={{ duration: 200 }}>
|
||||
<div class="color-picker-wrapper">
|
||||
<label for="color-picker">Color Picker</label>
|
||||
<input id="color-picker" type="color" bind:value={primaryColorInput} />
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label for="custom-hex">Hex Code</label>
|
||||
<input id="custom-hex" type="text" bind:value={primaryColorInput} placeholder="#2563eb" maxlength="7" />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Custom CSS (only in standalone mode) -->
|
||||
<div class="settings-section custom-css-section">
|
||||
<h3>Custom CSS</h3>
|
||||
<p class="section-description">Add your own CSS to customize the appearance globally.</p>
|
||||
@@ -292,7 +481,7 @@
|
||||
Apply
|
||||
</button>
|
||||
<button class="action-btn clear" onclick={handleClearCustomCss}>
|
||||
<Icon name="x" size="sm" />
|
||||
<Icon name="undo" size="sm" />
|
||||
Clear
|
||||
</button>
|
||||
</div>
|
||||
@@ -364,6 +553,12 @@
|
||||
&.accessibility-section {
|
||||
grid-row: span 2;
|
||||
}
|
||||
&.site-branding-section {
|
||||
grid-column: span 2;
|
||||
}
|
||||
&.color-section {
|
||||
grid-row: span 1;
|
||||
}
|
||||
&.custom-css-section {
|
||||
grid-column: span 2;
|
||||
}
|
||||
@@ -371,6 +566,8 @@
|
||||
@media (max-width: 768px) {
|
||||
&.theme-section,
|
||||
&.accessibility-section,
|
||||
&.site-branding-section,
|
||||
&.color-section,
|
||||
&.custom-css-section {
|
||||
grid-row: span 1;
|
||||
grid-column: span 1;
|
||||
@@ -737,13 +934,202 @@
|
||||
}
|
||||
}
|
||||
|
||||
.site-branding-section,
|
||||
.color-section,
|
||||
.custom-css-section {
|
||||
.section-description {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
margin: 0 0 var(--spacing-md) 0;
|
||||
}
|
||||
}
|
||||
|
||||
.site-branding-section,
|
||||
.color-section {
|
||||
.form-field {
|
||||
margin-bottom: var(--spacing-md);
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-primary);
|
||||
transition: all var(--transition-normal);
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary), transparent 85%);
|
||||
}
|
||||
|
||||
&::placeholder {
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.color-section {
|
||||
.color-palette {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
|
||||
gap: var(--spacing-sm);
|
||||
margin-bottom: var(--spacing-md);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.color-swatch {
|
||||
aspect-ratio: 1;
|
||||
border: 2px solid transparent;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
position: relative;
|
||||
outline: 1px solid var(--border-primary);
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
&.active {
|
||||
outline: 2px solid var(--text-primary);
|
||||
box-shadow: 0 0 0 3px var(--bg-secondary);
|
||||
|
||||
&::after {
|
||||
content: '✓';
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
font-size: 1.2rem;
|
||||
text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.color-actions {
|
||||
display: flex;
|
||||
gap: var(--spacing-sm);
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
.custom-color-toggle {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-sm);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
|
||||
&:hover {
|
||||
background: var(--surface-hover);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.custom-color-inputs {
|
||||
display: flex;
|
||||
gap: var(--spacing-sm);
|
||||
margin-bottom: var(--spacing-md);
|
||||
overflow: hidden;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.color-picker-wrapper {
|
||||
flex: 0 0 auto;
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
input[type='color'] {
|
||||
width: 80px;
|
||||
height: 40px;
|
||||
padding: 2px;
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
background: var(--bg-tertiary);
|
||||
|
||||
&:hover {
|
||||
border-color: var(--border-secondary);
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary), transparent 85%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
display: inline-flex;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
border: 1px solid var(--border-primary);
|
||||
|
||||
&.apply {
|
||||
background: var(--color-primary);
|
||||
color: var(--bg-primary);
|
||||
border-color: var(--color-primary);
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--color-primary), black 10%);
|
||||
border-color: color-mix(in srgb, var(--color-primary), black 10%);
|
||||
}
|
||||
}
|
||||
|
||||
&.clear {
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
|
||||
&:hover {
|
||||
background: var(--surface-hover);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-secondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.custom-css-section {
|
||||
.css-editor {
|
||||
width: 100%;
|
||||
min-height: 200px;
|
||||
@@ -824,41 +1210,6 @@
|
||||
.css-actions {
|
||||
display: flex;
|
||||
gap: var(--spacing-sm);
|
||||
|
||||
.action-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
border: 1px solid var(--border-primary);
|
||||
|
||||
&.apply {
|
||||
background: var(--color-primary);
|
||||
color: var(--bg-primary);
|
||||
border-color: var(--color-primary);
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--color-primary), black 10%);
|
||||
border-color: color-mix(in srgb, var(--color-primary), black 10%);
|
||||
}
|
||||
}
|
||||
|
||||
&.clear {
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
|
||||
&:hover {
|
||||
background: var(--surface-hover);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-secondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,19 +9,32 @@
|
||||
*/
|
||||
|
||||
import { env } from '$env/dynamic/public';
|
||||
import { browser } from '$app/environment';
|
||||
import type { HomepageLayoutMode } from '$lib/stores/homepageLayout';
|
||||
import type { NavbarDisplayMode } from '$lib/stores/navbarDisplay';
|
||||
import type { ThemeOption } from '$lib/stores/theme';
|
||||
|
||||
// Site Branding
|
||||
export const SITE_NAME = env.NTB_SITE_NAME;
|
||||
export const SITE_TITLE = env.NTB_SITE_TITLE;
|
||||
export const SITE_DESCRIPTION = env.NTB_SITE_DESCRIPTION;
|
||||
// Get user customization from localStorage (browser only)
|
||||
function getUserCustomization() {
|
||||
if (!browser) return null;
|
||||
try {
|
||||
const stored = localStorage.getItem('user-site-customization');
|
||||
return stored ? JSON.parse(stored) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const userCustom = getUserCustomization();
|
||||
|
||||
// Site Branding - prioritize user customization, then env vars
|
||||
export const SITE_TITLE = userCustom?.title || env.NTB_SITE_TITLE;
|
||||
export const SITE_DESCRIPTION = userCustom?.description || env.NTB_SITE_DESCRIPTION;
|
||||
|
||||
/**
|
||||
* Logo/icon to display in the navbar, specified as a path to an image
|
||||
*/
|
||||
export const SITE_ICON = env.NTB_SITE_ICON ?? '';
|
||||
export const SITE_ICON = userCustom?.iconUrl || env.NTB_SITE_ICON || '';
|
||||
|
||||
/**
|
||||
* Default homepage layout
|
||||
|
||||
@@ -291,6 +291,8 @@ export const iconMap: Record<string, string> = {
|
||||
// 'list-check': ``,
|
||||
share: `<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 320C112 346.5 133.5 368 160 368C186.5 368 208 346.5 208 320C208 293.5 186.5 272 160 272C133.5 272 112 293.5 112 320zM400 160C400 186.5 421.5 208 448 208C474.5 208 496 186.5 496 160C496 133.5 474.5 112 448 112C421.5 112 400 133.5 400 160zM400 480C400 506.5 421.5 528 448 528C474.5 528 496 506.5 496 480C496 453.5 474.5 432 448 432C421.5 432 400 453.5 400 480z"/><path d="M496 160C496 133.5 474.5 112 448 112C421.5 112 400 133.5 400 160C400 186.5 421.5 208 448 208C474.5 208 496 186.5 496 160zM544 160C544 213 501 256 448 256C420.6 256 395.9 244.5 378.4 226.1L252.9 295.8C254.9 303.5 256 311.6 256 320C256 328.4 254.9 336.5 252.9 344.2L378.4 413.9C395.9 395.5 420.6 384 448 384C501 384 544 427 544 480C544 533 501 576 448 576C395 576 352 533 352 480C352 471.7 353.1 463.5 355.1 455.8L229.6 386.1C212.1 404.5 187.4 416 160 416C107 416 64 373 64 320C64 267 107 224 160 224C187.4 224 212.1 235.5 229.6 253.9L355.1 184.2C353.1 176.5 352 168.4 352 160C352 107 395 64 448 64C501 64 544 107 544 160zM208 320C208 293.5 186.5 272 160 272C133.5 272 112 293.5 112 320C112 346.5 133.5 368 160 368C186.5 368 208 346.5 208 320zM448 528C474.5 528 496 506.5 496 480C496 453.5 474.5 432 448 432C421.5 432 400 453.5 400 480C400 506.5 421.5 528 448 528z"/></svg>`,
|
||||
'clipboard-list': `<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="M203.7 133.8C211.3 122.9 208.7 108 197.8 100.4C186.9 92.8 172 95.4 164.4 106.3L124.7 162.8L105 143C95.6 133.7 80.4 133.7 71 143C61.6 152.3 61.7 167.6 71 177L111 217C116 222 123 224.6 130.1 223.9C137.2 223.2 143.6 219.6 147.7 213.8L203.7 133.8zM203.7 293.8C211.3 282.9 208.7 268 197.8 260.4C186.9 252.8 172 255.4 164.4 266.3L124.7 322.8L105 303C95.6 293.6 80.4 293.6 71.1 303C61.8 312.4 61.7 327.6 71 337L111 377C116 382 123 384.6 130.1 383.9C137.2 383.2 143.6 379.6 147.7 373.8L203.7 293.8zM256 160C256 173.3 266.7 184 280 184L552 184C565.3 184 576 173.3 576 160C576 146.7 565.3 136 552 136L280 136C266.7 136 256 146.7 256 160zM256 320C256 333.3 266.7 344 280 344L552 344C565.3 344 576 333.3 576 320C576 306.7 565.3 296 552 296L280 296C266.7 296 256 306.7 256 320zM224 480C224 493.3 234.7 504 248 504L552 504C565.3 504 576 493.3 576 480C576 466.7 565.3 456 552 456L248 456C234.7 456 224 466.7 224 480zM160 480C160 462.3 145.7 448 128 448C110.3 448 96 462.3 96 480C96 497.7 110.3 512 128 512C145.7 512 160 497.7 160 480z"/></svg>`,
|
||||
palette: `<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 320C112 434.9 205.1 528 320 528C322.9 528 325.8 527.9 328.6 527.8C329.4 527.8 329.8 527.6 330.2 527.4C330.6 527.2 331.3 526.7 332.2 525.6C334.1 523.3 336 519.1 336 513.8C336 512.1 335.4 508.2 330.4 496.7C329.9 495.5 329.2 494 328.5 492.4C324.3 482.9 317.4 467.4 314.1 451.8C312.7 445.4 312 438.7 312 432C312 379 355 336 408 336L505.9 336C513.6 336 520 333.3 523.7 330.2C527 327.5 527.9 324.9 527.9 322.2C527.9 321.5 527.9 320.8 527.9 320C527.9 205.1 434.8 112 319.9 112C205 112 112 205.1 112 320zM224 320C224 337.7 209.7 352 192 352C174.3 352 160 337.7 160 320C160 302.3 174.3 288 192 288C209.7 288 224 302.3 224 320zM256 224C256 241.7 241.7 256 224 256C206.3 256 192 241.7 192 224C192 206.3 206.3 192 224 192C241.7 192 256 206.3 256 224zM352 192C352 209.7 337.7 224 320 224C302.3 224 288 209.7 288 192C288 174.3 302.3 160 320 160C337.7 160 352 174.3 352 192zM448 224C448 241.7 433.7 256 416 256C398.3 256 384 241.7 384 224C384 206.3 398.3 192 416 192C433.7 192 448 206.3 448 224z"/><path d="M528 322.2C528 324.9 527 327.4 523.8 330.2C520 333.3 513.7 336 506 336L408 336C355 336 312 379 312 432C312 438.8 312.7 445.4 314.1 451.8C317.4 467.5 324.3 482.9 328.5 492.4L328.5 492.4C329.2 494 329.9 495.4 330.4 496.7C335.4 508.2 336 512.1 336 513.8C336 519.1 334.1 523.3 332.2 525.6C331.3 526.7 330.6 527.2 330.2 527.4C329.9 527.6 329.4 527.7 328.6 527.8C325.7 527.9 322.9 528 320 528C205.1 528 112 434.9 112 320C112 205.1 205.1 112 320 112C434.9 112 528 205.1 528 320C528 320.7 528 321.4 528 322.2zM576 322.7C576 321.8 576 320.9 576 320C576 178.6 461.4 64 320 64C178.6 64 64 178.6 64 320C64 461.4 178.6 576 320 576C323.5 576 327.1 575.9 330.6 575.8C362.4 574.5 384 545.7 384 513.8C384 499.3 377.9 485.5 371.9 471.8C367.6 462 363.2 452.1 361.1 441.9C360.4 438.7 360.1 435.4 360.1 432C360.1 405.5 381.6 384 408.1 384L506 384C542.5 384 575.7 359.2 576.1 322.7zM224 320C224 302.3 209.7 288 192 288C174.3 288 160 302.3 160 320C160 337.7 174.3 352 192 352C209.7 352 224 337.7 224 320zM224 256C241.7 256 256 241.7 256 224C256 206.3 241.7 192 224 192C206.3 192 192 206.3 192 224C192 241.7 206.3 256 224 256zM352 192C352 174.3 337.7 160 320 160C302.3 160 288 174.3 288 192C288 209.7 302.3 224 320 224C337.7 224 352 209.7 352 192zM416 256C433.7 256 448 241.7 448 224C448 206.3 433.7 192 416 192C398.3 192 384 206.3 384 224C384 241.7 398.3 256 416 256z"/></svg>`,
|
||||
undo: `<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="M172.9 208L195.5 513.2C196.1 521.6 203.1 528 211.5 528L428.6 528C437 528 443.9 521.5 444.6 513.2L467.1 208L172.9 208zM223 319L287 255C296.4 245.6 311.6 245.6 320.9 255C330.2 264.4 330.3 279.6 320.9 288.9L297.9 311.9L328 311.9C376.6 311.9 416 351.3 416 399.9L416 423.9C416 437.2 405.3 447.9 392 447.9C378.7 447.9 368 437.2 368 423.9L368 399.9C368 377.8 350.1 359.9 328 359.9L297.9 359.9L320.9 382.9C330.3 392.3 330.3 407.5 320.9 416.8C311.5 426.1 296.3 426.2 287 416.8L223 352.8C213.6 343.4 213.6 328.2 223 318.9z"/><path d="M232.2 68.8C236.9 56.3 248.8 48 262.2 48L377.8 48C391.1 48 403.1 56.3 407.8 68.8L424 112L520 112C533.3 112 544 122.7 544 136C544 149.3 533.3 160 520 160L120 160C106.7 160 96 149.3 96 136C96 122.7 106.7 112 120 112L216 112L232.2 68.8zM147.6 516.8L124.7 208L172.9 208L195.5 513.2C196.1 521.6 203.1 528 211.5 528L428.6 528C437 528 443.9 521.5 444.6 513.2L467.2 208L515.3 208L492.4 516.7C489.9 550.1 462.1 576 428.6 576L211.5 576C178 576 150.2 550.1 147.7 516.7zM321 255C330.4 264.4 330.4 279.6 321 288.9L298 311.9L328.1 311.9C376.7 311.9 416.1 351.3 416.1 399.9L416.1 423.9C416.1 437.2 405.4 447.9 392.1 447.9C378.8 447.9 368.1 437.2 368.1 423.9L368.1 399.9C368.1 377.8 350.2 359.9 328.1 359.9L298 359.9L321 382.9C330.4 392.3 330.4 407.5 321 416.8C311.6 426.1 296.4 426.2 287.1 416.8L223.1 352.8C213.7 343.4 213.7 328.2 223.1 318.9L287.1 254.9C296.5 245.5 311.7 245.5 321 254.9z"/></svg>`,
|
||||
// 'edit-3': ``,
|
||||
// 'mail-check': ``,
|
||||
// 'eye': ``,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SITE_NAME, SITE_TITLE, SITE_DESCRIPTION } from '$lib/config/customizable-settings';
|
||||
import { SITE_TITLE, SITE_DESCRIPTION } from '$lib/config/customizable-settings';
|
||||
|
||||
export const site = {
|
||||
name: SITE_NAME || 'Networking Toolbox',
|
||||
name: SITE_TITLE || 'Networking Toolbox',
|
||||
title: SITE_TITLE || 'Networking Toolbox',
|
||||
description: 'A free set of online tools to help with IP addressing and subnetting.',
|
||||
longDescription:
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
const STORAGE_KEY = 'user-primary-color';
|
||||
const HEX_PATTERN = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
|
||||
|
||||
function createPrimaryColorStore() {
|
||||
const { subscribe, set } = writable<string>('');
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
init: () => {
|
||||
if (!browser) return;
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
// Only load if it's a valid hex color
|
||||
if (stored && HEX_PATTERN.test(stored)) {
|
||||
set(stored);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load primary color:', e);
|
||||
}
|
||||
},
|
||||
set: (color: string) => {
|
||||
if (!browser) return;
|
||||
try {
|
||||
if (color && color.trim()) {
|
||||
const trimmed = color.trim();
|
||||
// Only save valid hex colors
|
||||
if (HEX_PATTERN.test(trimmed)) {
|
||||
localStorage.setItem(STORAGE_KEY, trimmed);
|
||||
set(trimmed);
|
||||
}
|
||||
} else {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
set('');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to save primary color:', e);
|
||||
}
|
||||
},
|
||||
clear: () => {
|
||||
if (!browser) return;
|
||||
try {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
set('');
|
||||
} catch (e) {
|
||||
console.error('Failed to clear primary color:', e);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const primaryColor = createPrimaryColorStore();
|
||||
@@ -0,0 +1,81 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
const STORAGE_KEY = 'user-site-customization';
|
||||
|
||||
interface SiteCustomization {
|
||||
title: string;
|
||||
description: string;
|
||||
iconUrl: string;
|
||||
}
|
||||
|
||||
interface ValidationResult {
|
||||
isValid: boolean;
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
const defaults: SiteCustomization = {
|
||||
title: '',
|
||||
description: '',
|
||||
iconUrl: '',
|
||||
};
|
||||
|
||||
function validateSiteCustomization(data: SiteCustomization): ValidationResult {
|
||||
const errors: string[] = [];
|
||||
|
||||
// Validate lengths
|
||||
if (data.title.length > 100) errors.push('Site title too long (max 100 characters)');
|
||||
if (data.description.length > 300) errors.push('Description too long (max 300 characters)');
|
||||
|
||||
// Validate icon URL if provided
|
||||
if (data.iconUrl.trim()) {
|
||||
try {
|
||||
const url = new URL(data.iconUrl, window.location.origin);
|
||||
// Only allow http, https, data URLs
|
||||
if (!['http:', 'https:', 'data:'].includes(url.protocol)) {
|
||||
errors.push('Icon URL must use http, https, or data protocol');
|
||||
}
|
||||
} catch {
|
||||
// If it's not a full URL, check if it's a valid relative path
|
||||
if (!data.iconUrl.startsWith('/') && !data.iconUrl.startsWith('./')) {
|
||||
errors.push('Invalid icon URL format');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { isValid: errors.length === 0, errors };
|
||||
}
|
||||
|
||||
function createSiteCustomizationStore() {
|
||||
const { subscribe, set } = writable<SiteCustomization>(defaults);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
init: () => {
|
||||
if (!browser) return;
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
if (stored) {
|
||||
try {
|
||||
const parsed = JSON.parse(stored);
|
||||
const loadedData = { ...defaults, ...parsed };
|
||||
set(loadedData);
|
||||
} catch (e) {
|
||||
console.error('Failed to parse site customization:', e);
|
||||
}
|
||||
}
|
||||
},
|
||||
set: (data: SiteCustomization) => {
|
||||
if (!browser) return;
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
|
||||
set(data);
|
||||
},
|
||||
clear: () => {
|
||||
if (!browser) return;
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
set(defaults);
|
||||
},
|
||||
validate: validateSiteCustomization,
|
||||
};
|
||||
}
|
||||
|
||||
export const siteCustomization = createSiteCustomizationStore();
|
||||
@@ -17,6 +17,8 @@
|
||||
import { accessibility } from '$lib/stores/accessibility';
|
||||
import { theme } from '$lib/stores/theme';
|
||||
import { customCss } from '$lib/stores/customCss';
|
||||
import { siteCustomization } from '$lib/stores/siteCustomization';
|
||||
import { primaryColor } from '$lib/stores/primaryColor';
|
||||
import { ALL_PAGES } from '$lib/constants/nav';
|
||||
import { initializeOfflineSupport } from '$lib/stores/offline';
|
||||
import { bookmarks } from '$lib/stores/bookmarks';
|
||||
@@ -113,6 +115,8 @@
|
||||
accessibility.init();
|
||||
bookmarks.init();
|
||||
customCss.init();
|
||||
siteCustomization.init();
|
||||
primaryColor.init();
|
||||
initializeOfflineSupport();
|
||||
|
||||
// Add global keyboard shortcuts
|
||||
@@ -188,6 +192,17 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Apply custom primary color
|
||||
$effect(() => {
|
||||
if (typeof document === 'undefined') return;
|
||||
const color = $primaryColor;
|
||||
if (color && color.trim()) {
|
||||
document.documentElement.style.setProperty('--color-primary', color);
|
||||
} else {
|
||||
document.documentElement.style.removeProperty('--color-primary');
|
||||
}
|
||||
});
|
||||
|
||||
/* Uses the server-generated breadcrumb data, to build a JSON-LD breadcrumb object */
|
||||
function jsonLdTag(data: unknown, type = 'application/ld+json', nonce?: string) {
|
||||
if (!data) return '';
|
||||
|
||||
Reference in new issue
Block a user