Skip to content

Commit aa26ad2

Browse files
committed
chore: package sanitation — prune dead code, tighten internal types
Dead code removed: - 11 unused tracking wrapper functions in `lib/analytics/index.ts` (trackToolEngaged, trackToolSessionSummary, trackPageScrollDepth, trackLearnPanelScrollDepth, trackOutboundClick, trackMobileControlsToggle, trackFileUploadError, trackJsError, trackWebGLError, trackCapabilityCheck) plus `getGlobalProperties`. Consumers can call `dispatch()` directly when needed; the wrappers added zero behaviour and rotted into "exported but never imported" cruft. Their type imports are pruned too. - `OverlayRect` type and `overlayRects` mutable export from the megapixels-size-visualizer drawOverlay — leftover hit-test scratch buffer from a sensor-size-comparison copy/paste; never read. - Legacy `ToolEducation` / `Challenge` / `ChallengeOption` / `ProTip` types in `lib/data/education/types.ts` — pre-i18n schema kept after the skeleton refactor took over; nothing consumes them. - `DOF_SCENE_PRESETS` "backward-compat alias for existing DoF Calculator component (until Task 8 renames it)" — Task 8 happened long ago. The only consumer was its own test file. - `ALL_MP_IDS` / `ALL_SENSOR_IDS` intermediate arrays — only the `_SET` variants were ever read; inlined the source. - Duplicate local `formatDist` helpers in HyperfocalMiniTable and HyperfocalBadge — both reimplemented the dof-diagram-helpers version (minus the `isFinite` infinity guard). Now import the shared one, gaining the ∞ formatting for free. API surface tightened (removed `export` from internal-only types): - `FramingPreset`, `GlossaryEntry`, `FaqSkeleton`, `ToolFaqs`, `WbPreset`, `WbScene`, `ExposureScene`, `PrintSizePreset`, `SceneObject`, `SceneDef`, `ScenePickerScene`, `MagnifierState`, `SceneAssets`, `PillBounds`, `GeoArrays`, `BokehCircle`, `MIN_DIST`, `MAX_DIST`. Each was only referenced inside its own module; making them file-local stops them from looking like a public contract. Bug hardening: - `loadCustomSensors` now validates that the parsed JSON is an array before iterating. Previously a corrupted/non-array localStorage value would partially mutate `COMMON_MP` before throwing into the catch — unlikely in practice but messy. Verified: 868 unit tests, 122 chromium smoke specs, type-check, lint, and production build (720 static pages) all pass.
1 parent 9010812 commit aa26ad2

22 files changed

Lines changed: 24 additions & 182 deletions

File tree

src/app/[locale]/color-scheme-generator/_components/useMagnifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useState, useRef, useCallback } from 'react'
44

5-
export interface MagnifierState {
5+
interface MagnifierState {
66
vpX: number
77
vpY: number
88
hex: string

src/app/[locale]/exposure-simulator/_components/useExposureRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from './webglHelpers'
1212
import { runRenderPipeline, cleanupResources } from './renderPipeline'
1313

14-
export interface SceneAssets {
14+
interface SceneAssets {
1515
photo: string
1616
depthMap: string
1717
motionMask: string

src/app/[locale]/fov-simulator/_components/canvasTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { LensConfig } from '@/lib/types'
22

3-
export interface PillBounds {
3+
interface PillBounds {
44
x: number
55
y: number
66
w: number

src/app/[locale]/hyperfocal-simulator/_components/HyperfocalBadge.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
'use client'
22

33
import { useTranslations } from 'next-intl'
4+
import { formatDist } from '@/components/shared/dof-diagram-helpers'
45

56
interface HyperfocalBadgeProps {
67
isAtHyperfocal: boolean
78
nearLimit: number
89
}
910

10-
function formatDist(m: number): string {
11-
if (m < 1) return `${(m * 100).toFixed(0)} cm`
12-
return `${m.toFixed(2)} m`
13-
}
14-
1511
export function HyperfocalBadge({ isAtHyperfocal, nearLimit }: HyperfocalBadgeProps) {
1612
const t = useTranslations('toolUI.hyperfocal-simulator')
1713
if (!isAtHyperfocal) return null

src/app/[locale]/hyperfocal-simulator/_components/HyperfocalMiniTable.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
import { useTranslations } from 'next-intl'
44
import { calcHyperfocal } from '@/lib/math/dof'
55
import { APERTURES } from '@/lib/data/camera'
6+
import { formatDist } from '@/components/shared/dof-diagram-helpers'
67

78
interface HyperfocalMiniTableProps {
89
focalLength: number
910
aperture: number
1011
coc: number
1112
}
1213

13-
function formatDist(m: number): string {
14-
if (m < 1) return `${(m * 100).toFixed(0)} cm`
15-
return `${m.toFixed(2)} m`
16-
}
17-
1814
export function HyperfocalMiniTable({ focalLength, aperture, coc }: HyperfocalMiniTableProps) {
1915
const t = useTranslations('toolUI.hyperfocal-simulator')
2016
return (

src/app/[locale]/megapixels-size-visualizer/_components/drawOverlay.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { mpToPixelDimensions } from '@/lib/math/resolution'
33
import { printSizeMm } from '@/lib/math/megapixel'
44
import { drawRect, rgba, roundRect } from './drawHelpers'
55

6-
export type OverlayRect = { id: string; x: number; y: number; w: number; h: number }
7-
export let overlayRects: OverlayRect[] = []
8-
96
export function drawOverlay(
107
ctx: CanvasRenderingContext2D,
118
canvasWidth: number,
@@ -17,7 +14,6 @@ export function drawOverlay(
1714
_units: UnitSystem,
1815
hoveredId: string | null,
1916
): { contentHeight: number; pxPerMm: number } {
20-
overlayRects = []
2117
if (visibleMps.length === 0) {
2218
return { contentHeight: 300, pxPerMm: 0 }
2319
}
@@ -64,8 +60,6 @@ export function drawOverlay(
6460

6561
const alpha = hoveredId && hoveredId !== mp.id ? 0.3 : 1
6662
drawRect(ctx, x, y, w, h, mp.color, alpha)
67-
68-
overlayRects.push({ id: mp.id, x, y, w, h })
6963
}
7064

7165
// Labels: pills in a column to the left of the largest rectangle, with leader lines

src/app/[locale]/megapixels-size-visualizer/_components/megapixelTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ export type PrintTableControlsProps = {
3838
onBitDepthChange: (b: BitDepth) => void
3939
}
4040

41-
export { type UnitSystem, type CustomMegapixel, type ViewingDistance, type BitDepth }

src/app/[locale]/perspective-compression-simulator/_components/compressionGeometry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GROUND_COLOR, GRID_COLOR } from './compressionConstants'
22

3-
export interface GeoArrays {
3+
interface GeoArrays {
44
positions: number[]
55
normals: number[]
66
colors: number[]

src/app/[locale]/sensor-size-comparison/_components/sensorSizeHelpers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import type { StoredCustomSensor } from './sensorSizeTypes'
66
export let customColorIdx = 0
77
export function setCustomColorIdx(n: number) { customColorIdx = n }
88

9-
export const ALL_SENSOR_IDS = SENSORS.map((s) => s.id)
10-
export const ALL_SENSOR_ID_SET = new Set(ALL_SENSOR_IDS)
9+
export const ALL_SENSOR_ID_SET = new Set(SENSORS.map((s) => s.id))
1110

1211
export function rgba(hex: string, a: number): string {
1312
const n = parseInt(hex.replace('#', ''), 16)
@@ -64,7 +63,9 @@ export function loadCustomSensors(): Required<SensorPreset>[] {
6463
try {
6564
const raw = localStorage.getItem(STORAGE_KEY)
6665
if (!raw) return []
67-
const stored: StoredCustomSensor[] = JSON.parse(raw)
66+
const parsed = JSON.parse(raw)
67+
if (!Array.isArray(parsed)) return []
68+
const stored = parsed as StoredCustomSensor[]
6869
for (const s of stored) {
6970
if (s.mp && s.mp > 0) {
7071
COMMON_MP[s.id] = [{ mp: s.mp, models: s.name }]

src/components/shared/ScenePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useTranslations } from 'next-intl'
55
import { trackToolInteraction } from '@/lib/analytics'
66
import styles from './ScenePicker.module.css'
77

8-
export interface ScenePickerScene {
8+
interface ScenePickerScene {
99
id: string
1010
name: string
1111
src: string

0 commit comments

Comments
 (0)