From 143608db37eff9c52c88e12c4d9173bcb0b4a3d0 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 7 Mar 2026 06:35:29 +0000 Subject: [PATCH] Add centralized unit definitions --- .../src/lib/components/Calculator.svelte | 2 + .../lib/components/QuickDefinitionCard.svelte | 67 +++++++++++++++++++ hdyc-svelte/src/lib/data/unitDefinitions.ts | 54 +++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 hdyc-svelte/src/lib/components/QuickDefinitionCard.svelte create mode 100644 hdyc-svelte/src/lib/data/unitDefinitions.ts diff --git a/hdyc-svelte/src/lib/components/Calculator.svelte b/hdyc-svelte/src/lib/components/Calculator.svelte index 2ca4bce..69c76e8 100644 --- a/hdyc-svelte/src/lib/components/Calculator.svelte +++ b/hdyc-svelte/src/lib/components/Calculator.svelte @@ -3,6 +3,7 @@ import type { CalculatorDef } from '$lib/data/calculators'; import { page } from '$app/stores'; import { onMount } from 'svelte'; + import QuickDefinitionCard from '$lib/components/QuickDefinitionCard.svelte'; import QuickConversionExample from '$lib/components/QuickConversionExample.svelte'; import QuickConversionTable from '$lib/components/QuickConversionTable.svelte'; @@ -116,6 +117,7 @@ + diff --git a/hdyc-svelte/src/lib/data/unitDefinitions.ts b/hdyc-svelte/src/lib/data/unitDefinitions.ts new file mode 100644 index 0000000..9ebc14b --- /dev/null +++ b/hdyc-svelte/src/lib/data/unitDefinitions.ts @@ -0,0 +1,54 @@ +import { calculators } from './calculators'; + +const domainDescriptions: Record = { + length: 'linear or spatial distance measurement', + weight: 'mass or force quantity', + temperature: 'thermal energy level', + volume: 'three-dimensional capacity', + area: 'two-dimensional surface measurement', + speed: 'rate of change of position', + pressure: 'force exerted per unit area', + energy: 'capacity to do work', + power: 'rate of energy transfer', + data: 'digital information volume', + time: 'temporal duration', + angle: 'angular measurement', + 'number-systems': 'numeric representation systems', + radiation: 'ionizing emission metrics', + electrical: 'electricity-related magnitude', + force: 'force or torque measurement', + light: 'luminous intensity', + other: 'specialized measurement', +}; + +const definitions: Record = {}; + +const formatLabel = (label: string): string => { + if (!label) return ''; + return label + .replace(/\b([A-Z])/g, ' $1') + .replace(/\s+/g, ' ') + .trim(); +}; + +const buildDefinition = (label: string, categoryKey: string): string => { + if (!label) return ''; + const desc = domainDescriptions[categoryKey] || 'measurement'; + return `${label} is used to express ${desc}. Understanding ${label} keeps calculations aligned across the ${categoryKey} domain.`; +}; + +calculators.forEach(calc => { + const { category, labels } = calc; + Object.values(labels).forEach(label => { + if (!label) return; + if (!definitions[label]) { + definitions[label] = buildDefinition(label, category); + } + }); +}); + +export function getDefinition(label: string): string | undefined { + return definitions[label]; +} + +export const unitDefinitions = definitions;