Remove src param compatibility from shared links

This commit is contained in:
Codex Agent
2026-03-08 19:53:18 +00:00
parent afe72b9ee1
commit a1758a9074

View File

@@ -26,16 +26,20 @@
let footerControlsEl: HTMLDivElement | null = null;
let tooltipX = 20;
let copyStatusMessage = '';
let initializedSlug: string | null = null;
$: has3 = ['3col', '3col-mul'].includes(config.type) || !!config.labels.in3;
$: isTextInput = ['base', 'text-bin', 'bin-text', 'dec-frac', 'dms-dd', 'dd-dms'].includes(config.type);
// Clear inputs on config (route) change
$: if (config) {
if (!paramsInitializing) clear();
// Clear inputs only when navigating to a different calculator slug.
$: if (config?.slug) {
if (initializedSlug === null) {
initializedSlug = config.slug;
} else if (initializedSlug !== config.slug) {
initializedSlug = config.slug;
clear();
}
}
let paramsInitializing = true;
function handleInput(source: 1 | 2 | 3, options?: { preserveSwap?: boolean }) {
if (!options?.preserveSwap) {
@@ -81,7 +85,6 @@
const v2 = toQueryValue(val2);
const v3 = toQueryValue(val3);
const source: 1 | 2 | 3 = has3 ? activeField : (activeField === 2 ? 2 : 1);
params.set('src', String(source));
if (!has3) {
const sourceValue = source === 1 ? v1 : v2;
@@ -189,26 +192,28 @@
onMount(() => {
const params = new URLSearchParams($page.url.search);
const srcParam = Number(params.get('src'));
const shareSource = srcParam === 1 || srcParam === 2 || srcParam === 3 ? srcParam : null;
const hasV1 = params.has('v1');
const hasV2 = params.has('v2');
const hasV3 = has3 && params.has('v3');
if (shareSource !== null) {
if (params.has('v1')) val1 = params.get('v1') ?? '';
if (params.has('v2')) val2 = params.get('v2') ?? '';
if (params.has('v3') && has3) val3 = params.get('v3') ?? '';
const sourceToApply: 1 | 2 | 3 = has3 ? shareSource : (shareSource === 2 ? 2 : 1);
handleInput(sourceToApply);
} else if (params.has('v1')) {
if (has3 && hasV2 && hasV3) {
val2 = params.get('v2') ?? '';
val3 = params.get('v3') ?? '';
handleInput(3);
} else if (has3 && hasV1 && hasV2) {
val1 = params.get('v1') ?? '';
val2 = params.get('v2') ?? '';
handleInput(1);
} else if (hasV1) {
val1 = params.get('v1') ?? '';
handleInput(1);
} else if (params.has('v2')) {
} else if (hasV2) {
val2 = params.get('v2') ?? '';
handleInput(2);
} else if (params.has('v3') && has3) {
} else if (hasV3) {
val3 = params.get('v3') ?? '';
handleInput(3);
}
setTimeout(() => { paramsInitializing = false; }, 0);
});
onDestroy(() => {