Khunndev Cursor commited on
Commit
40fe69e
·
1 Parent(s): bb2225c

Overhaul mobile PWA UX: sticky header/bar, filled circles, pinch-to-zoom

Browse files

- Mobile-first layout: sticky header with model-ready indicator, bottom action bar with safe-area insets
- Filled semi-transparent circles fit inside each detected pipe with centered number labels
- Pinch-to-zoom and one-finger pan on result canvas; double-tap resets; zoom badge with one-tap reset
- Settings collapsed behind gear icon; toggle switches instead of checkboxes
- Export bottom sheet slide-up; processing fullscreen overlay
- GroupPanel scrolls horizontally on mobile; icon ToolBar with 44px+ tap targets
- Empty state onboarding screen with large camera/gallery buttons
- viewport-fit=cover + safe-area CSS for notched phones

Co-authored-by: Cursor <cursoragent@cursor.com>

frontend/index.html CHANGED
@@ -2,9 +2,12 @@
2
  <html lang="th">
3
  <head>
4
  <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <meta name="theme-color" content="#0f172a" />
7
  <meta name="apple-mobile-web-app-capable" content="yes" />
 
 
 
8
  <title>NPI Pipe Count</title>
9
  </head>
10
  <body>
 
2
  <html lang="th">
3
  <head>
4
  <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
+ <meta name="theme-color" content="#020617" />
7
  <meta name="apple-mobile-web-app-capable" content="yes" />
8
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
9
+ <meta name="mobile-web-app-capable" content="yes" />
10
+ <link rel="apple-touch-icon" href="/icon.svg" />
11
  <title>NPI Pipe Count</title>
12
  </head>
13
  <body>
frontend/src/App.tsx CHANGED
@@ -1,12 +1,19 @@
1
  import { useEffect, useRef, useState } from 'react'
2
- import { Camera, ImagePlus, Loader2 } from 'lucide-react'
3
  import { assignDiameterGroups, countByGroup } from './lib/clustering'
4
  import { exportCanvasPng, exportCsv, exportJson } from './lib/export'
5
  import { getActiveBackend, loadModel, runDetection } from './lib/inference'
6
  import { t } from './lib/i18n'
7
  import type { Detection, DiameterGroup, Lang, ToolMode } from './lib/types'
8
  import { DetectionCanvas } from './components/DetectionCanvas'
 
 
9
  import { GroupPanel } from './components/GroupPanel'
 
 
 
 
 
 
10
 
11
  export default function App() {
12
  const [lang, setLang] = useState<Lang>('th')
@@ -22,17 +29,23 @@ export default function App() {
22
  const [useTiling, setUseTiling] = useState(false)
23
  const [enhanceImage, setEnhanceImage] = useState(true)
24
  const [filterOutliers, setFilterOutliers] = useState(false)
 
 
25
  const [exportCanvas, setExportCanvas] = useState<HTMLCanvasElement | null>(null)
26
  const fileRef = useRef<HTMLInputElement>(null)
27
  const cameraRef = useRef<HTMLInputElement>(null)
28
 
29
  useEffect(() => {
30
  loadModel(setStatus)
31
- .then(() => setModelReady(true))
 
 
 
32
  .catch((err: unknown) => setStatus(String(err)))
33
  }, [])
34
 
35
  const counts = countByGroup(detections, groups)
 
36
 
37
  const loadFile = (file: File) => {
38
  const url = URL.createObjectURL(file)
@@ -41,16 +54,26 @@ export default function App() {
41
  setImage(img)
42
  setDetections([])
43
  setGroups([])
 
 
44
  URL.revokeObjectURL(url)
45
  }
46
  img.src = url
47
  }
48
 
 
 
 
 
 
 
 
49
  const runCount = async () => {
50
  if (!image) {
51
  return
52
  }
53
  setBusy(true)
 
54
  setStatus(t(lang, 'processing'))
55
  try {
56
  const dets = await runDetection(image, {
@@ -63,7 +86,7 @@ export default function App() {
63
  const clustered = assignDiameterGroups(dets, groupCount, lang)
64
  setDetections(clustered.detections)
65
  setGroups(clustered.groups)
66
- setSelectedGroupId(0)
67
  setStatus(`Done (${getActiveBackend()})`)
68
  } catch (err) {
69
  setStatus(String(err))
@@ -82,58 +105,99 @@ export default function App() {
82
  setGroups((prev) => prev.map((g) => (g.id === groupId ? { ...g, expected: value } : g)))
83
  }
84
 
85
- const tools: { id: ToolMode; label: string }[] = [
86
- { id: 'view', label: t(lang, 'toolView') },
87
- { id: 'delete', label: t(lang, 'toolDelete') },
88
- { id: 'add', label: t(lang, 'toolAdd') },
89
- { id: 'reassign', label: t(lang, 'toolReassign') },
90
- { id: 'area', label: t(lang, 'toolArea') },
91
- ]
92
-
93
  return (
94
- <div className="mx-auto flex min-h-dvh max-w-6xl flex-col gap-4 p-4 pb-8">
95
- <header className="flex flex-wrap items-center justify-between gap-3">
96
- <div>
97
- <h1 className="text-2xl font-bold text-white">{t(lang, 'title')}</h1>
98
- <p className="text-sm text-slate-400">{t(lang, 'subtitle')}</p>
99
- <p className="text-xs text-slate-500">{t(lang, 'company')}</p>
100
- </div>
101
- <div className="flex gap-2">
102
- <button
103
- type="button"
104
- className="rounded-lg bg-slate-800 px-3 py-1 text-sm"
105
- onClick={() => setLang(lang === 'th' ? 'en' : 'th')}
106
- >
107
- {lang === 'th' ? 'EN' : 'TH'}
108
- </button>
109
- </div>
110
- </header>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
- <div className="flex flex-wrap gap-2">
113
- <button
114
- type="button"
115
- className="flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 font-medium"
116
- onClick={() => cameraRef.current?.click()}
117
- >
118
- <Camera size={18} /> {t(lang, 'takePhoto')}
119
- </button>
120
- <button
121
- type="button"
122
- className="flex items-center gap-2 rounded-lg bg-slate-700 px-4 py-2"
123
- onClick={() => fileRef.current?.click()}
124
- >
125
- <ImagePlus size={18} /> {t(lang, 'chooseFile')}
126
- </button>
127
- <button
128
- type="button"
129
- disabled={!image || busy || !modelReady}
130
- className="flex items-center gap-2 rounded-lg bg-emerald-600 px-4 py-2 font-semibold disabled:opacity-50"
131
- onClick={runCount}
132
- >
133
- {busy ? <Loader2 className="animate-spin" size={18} /> : null}
134
- {t(lang, 'count')}
135
- </button>
136
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  <input
139
  ref={fileRef}
@@ -150,126 +214,6 @@ export default function App() {
150
  className="hidden"
151
  onChange={(e) => e.target.files?.[0] && loadFile(e.target.files[0])}
152
  />
153
-
154
- <div className="grid gap-4 lg:grid-cols-[1fr_280px]">
155
- <div className="space-y-3">
156
- {!image ? (
157
- <div className="flex h-64 items-center justify-center rounded-xl border border-dashed border-slate-600 text-slate-400">
158
- {t(lang, 'noImage')}
159
- </div>
160
- ) : (
161
- <DetectionCanvas
162
- image={image}
163
- detections={detections}
164
- groups={groups}
165
- tool={tool}
166
- selectedGroupId={selectedGroupId}
167
- onUpdate={setDetections}
168
- onCanvasReady={setExportCanvas}
169
- />
170
- )}
171
- {status && <p className="text-sm text-slate-400">{status}</p>}
172
- </div>
173
-
174
- <aside className="space-y-4">
175
- <div className="rounded-xl border border-slate-700 bg-slate-900/50 p-4">
176
- <div className="text-3xl font-bold">{detections.length}</div>
177
- <div className="text-sm text-slate-400">{t(lang, 'total')}</div>
178
- </div>
179
-
180
- <div className="space-y-2 rounded-xl border border-slate-700 bg-slate-900/50 p-4">
181
- <label className="text-sm text-slate-300">{t(lang, 'groupCount')}</label>
182
- <div className="flex flex-wrap gap-2">
183
- <button
184
- type="button"
185
- className={`rounded px-3 py-1 text-sm ${groupCount === 'auto' ? 'bg-blue-600' : 'bg-slate-800'}`}
186
- onClick={() => setGroupCount('auto')}
187
- >
188
- {t(lang, 'auto')}
189
- </button>
190
- {[1, 2, 3, 4, 5, 6].map((n) => (
191
- <button
192
- key={n}
193
- type="button"
194
- className={`rounded px-3 py-1 text-sm ${groupCount === n ? 'bg-blue-600' : 'bg-slate-800'}`}
195
- onClick={() => setGroupCount(n)}
196
- >
197
- {n}
198
- </button>
199
- ))}
200
- <button type="button" className="rounded bg-slate-700 px-3 py-1 text-sm" onClick={recluster}>
201
- Apply
202
- </button>
203
- </div>
204
- <label className="flex items-center gap-2 text-sm text-slate-300">
205
- <input type="checkbox" checked={enhanceImage} onChange={(e) => setEnhanceImage(e.target.checked)} />
206
- {t(lang, 'enhanceImage')}
207
- </label>
208
- <label className="flex items-center gap-2 text-sm text-slate-300">
209
- <input type="checkbox" checked={useTiling} onChange={(e) => setUseTiling(e.target.checked)} />
210
- {t(lang, 'highAccuracy')}
211
- </label>
212
- <label className="flex items-center gap-2 text-sm text-slate-300">
213
- <input type="checkbox" checked={filterOutliers} onChange={(e) => setFilterOutliers(e.target.checked)} />
214
- {t(lang, 'filterOutliers')}
215
- </label>
216
- </div>
217
-
218
- {groups.length > 0 && (
219
- <GroupPanel
220
- lang={lang}
221
- groups={groups}
222
- counts={counts}
223
- selectedGroupId={selectedGroupId}
224
- onSelectGroup={setSelectedGroupId}
225
- onExpectedChange={handleExpectedChange}
226
- />
227
- )}
228
-
229
- <div className="space-y-2">
230
- <p className="text-xs text-slate-400">{t(lang, 'selectGroup')}</p>
231
- <div className="flex flex-wrap gap-1">
232
- {tools.map((toolItem) => (
233
- <button
234
- key={toolItem.id}
235
- type="button"
236
- className={`rounded px-2 py-1 text-xs ${tool === toolItem.id ? 'bg-white text-slate-900' : 'bg-slate-800'}`}
237
- onClick={() => setTool(toolItem.id)}
238
- >
239
- {toolItem.label}
240
- </button>
241
- ))}
242
- </div>
243
- </div>
244
-
245
- <div className="flex flex-wrap gap-2">
246
- <button
247
- type="button"
248
- className="rounded bg-slate-700 px-3 py-2 text-sm"
249
- disabled={!exportCanvas}
250
- onClick={() => exportCanvas && exportCanvasPng(exportCanvas)}
251
- >
252
- {t(lang, 'exportPng')}
253
- </button>
254
- <button
255
- type="button"
256
- className="rounded bg-slate-700 px-3 py-2 text-sm"
257
- disabled={detections.length === 0}
258
- onClick={() => exportJson(detections, groups, counts)}
259
- >
260
- {t(lang, 'exportJson')}
261
- </button>
262
- <button
263
- type="button"
264
- className="rounded bg-slate-700 px-3 py-2 text-sm"
265
- disabled={detections.length === 0}
266
- onClick={() => exportCsv(detections, groups)}
267
- >
268
- {t(lang, 'exportCsv')}
269
- </button>
270
- </div>
271
- </aside>
272
- </div>
273
  </div>
274
  )
275
  }
 
1
  import { useEffect, useRef, useState } from 'react'
 
2
  import { assignDiameterGroups, countByGroup } from './lib/clustering'
3
  import { exportCanvasPng, exportCsv, exportJson } from './lib/export'
4
  import { getActiveBackend, loadModel, runDetection } from './lib/inference'
5
  import { t } from './lib/i18n'
6
  import type { Detection, DiameterGroup, Lang, ToolMode } from './lib/types'
7
  import { DetectionCanvas } from './components/DetectionCanvas'
8
+ import { EmptyState } from './components/EmptyState'
9
+ import { ExportSheet } from './components/ExportSheet'
10
  import { GroupPanel } from './components/GroupPanel'
11
+ import { MobileHeader } from './components/MobileHeader'
12
+ import { ProcessingOverlay } from './components/ProcessingOverlay'
13
+ import { ResultsSummary } from './components/ResultsSummary'
14
+ import { SettingsPanel } from './components/SettingsPanel'
15
+ import { StickyActionBar } from './components/StickyActionBar'
16
+ import { ToolBar } from './components/ToolBar'
17
 
18
  export default function App() {
19
  const [lang, setLang] = useState<Lang>('th')
 
29
  const [useTiling, setUseTiling] = useState(false)
30
  const [enhanceImage, setEnhanceImage] = useState(true)
31
  const [filterOutliers, setFilterOutliers] = useState(false)
32
+ const [settingsOpen, setSettingsOpen] = useState(false)
33
+ const [exportOpen, setExportOpen] = useState(false)
34
  const [exportCanvas, setExportCanvas] = useState<HTMLCanvasElement | null>(null)
35
  const fileRef = useRef<HTMLInputElement>(null)
36
  const cameraRef = useRef<HTMLInputElement>(null)
37
 
38
  useEffect(() => {
39
  loadModel(setStatus)
40
+ .then(() => {
41
+ setModelReady(true)
42
+ setStatus('')
43
+ })
44
  .catch((err: unknown) => setStatus(String(err)))
45
  }, [])
46
 
47
  const counts = countByGroup(detections, groups)
48
+ const hasResults = detections.length > 0
49
 
50
  const loadFile = (file: File) => {
51
  const url = URL.createObjectURL(file)
 
54
  setImage(img)
55
  setDetections([])
56
  setGroups([])
57
+ setTool('view')
58
+ setExportOpen(false)
59
  URL.revokeObjectURL(url)
60
  }
61
  img.src = url
62
  }
63
 
64
+ const clearImage = () => {
65
+ setImage(null)
66
+ setDetections([])
67
+ setGroups([])
68
+ setTool('view')
69
+ }
70
+
71
  const runCount = async () => {
72
  if (!image) {
73
  return
74
  }
75
  setBusy(true)
76
+ setSettingsOpen(false)
77
  setStatus(t(lang, 'processing'))
78
  try {
79
  const dets = await runDetection(image, {
 
86
  const clustered = assignDiameterGroups(dets, groupCount, lang)
87
  setDetections(clustered.detections)
88
  setGroups(clustered.groups)
89
+ setSelectedGroupId(clustered.groups[0]?.id ?? 0)
90
  setStatus(`Done (${getActiveBackend()})`)
91
  } catch (err) {
92
  setStatus(String(err))
 
105
  setGroups((prev) => prev.map((g) => (g.id === groupId ? { ...g, expected: value } : g)))
106
  }
107
 
 
 
 
 
 
 
 
 
108
  return (
109
+ <div className="flex min-h-dvh flex-col bg-slate-950">
110
+ <MobileHeader
111
+ lang={lang}
112
+ modelReady={modelReady}
113
+ settingsOpen={settingsOpen}
114
+ onToggleLang={() => setLang(lang === 'th' ? 'en' : 'th')}
115
+ onToggleSettings={() => setSettingsOpen((v) => !v)}
116
+ />
117
+
118
+ <main className="flex-1 overflow-y-auto px-4 pb-[calc(5.5rem+env(safe-area-inset-bottom))] pt-4">
119
+ {!image ? (
120
+ <EmptyState
121
+ lang={lang}
122
+ onCamera={() => cameraRef.current?.click()}
123
+ onGallery={() => fileRef.current?.click()}
124
+ />
125
+ ) : (
126
+ <div className="mx-auto flex w-full max-w-2xl flex-col gap-4">
127
+ <SettingsPanel
128
+ lang={lang}
129
+ open={settingsOpen}
130
+ groupCount={groupCount}
131
+ enhanceImage={enhanceImage}
132
+ useTiling={useTiling}
133
+ filterOutliers={filterOutliers}
134
+ onGroupCount={setGroupCount}
135
+ onEnhanceImage={setEnhanceImage}
136
+ onUseTiling={setUseTiling}
137
+ onFilterOutliers={setFilterOutliers}
138
+ onRecluster={recluster}
139
+ />
140
+
141
+ {hasResults && (
142
+ <ResultsSummary lang={lang} total={detections.length} groups={groups} counts={counts} />
143
+ )}
144
 
145
+ <DetectionCanvas
146
+ image={image}
147
+ detections={detections}
148
+ groups={groups}
149
+ tool={tool}
150
+ selectedGroupId={selectedGroupId}
151
+ onUpdate={setDetections}
152
+ onCanvasReady={setExportCanvas}
153
+ />
154
+
155
+ {!busy && status && !hasResults && (
156
+ <p className="text-center text-xs text-slate-500">{status}</p>
157
+ )}
158
+
159
+ {hasResults && (
160
+ <>
161
+ <GroupPanel
162
+ lang={lang}
163
+ groups={groups}
164
+ counts={counts}
165
+ selectedGroupId={selectedGroupId}
166
+ onSelectGroup={setSelectedGroupId}
167
+ onExpectedChange={handleExpectedChange}
168
+ />
169
+ <ToolBar lang={lang} tool={tool} onToolChange={setTool} />
170
+ </>
171
+ )}
172
+ </div>
173
+ )}
174
+ </main>
175
+
176
+ <StickyActionBar
177
+ lang={lang}
178
+ hasImage={!!image}
179
+ hasResults={hasResults}
180
+ busy={busy}
181
+ modelReady={modelReady}
182
+ onCamera={() => cameraRef.current?.click()}
183
+ onGallery={() => fileRef.current?.click()}
184
+ onCount={runCount}
185
+ onExport={() => setExportOpen(true)}
186
+ onNewPhoto={clearImage}
187
+ />
188
+
189
+ {busy && <ProcessingOverlay lang={lang} status={status} />}
190
+
191
+ <ExportSheet
192
+ lang={lang}
193
+ open={exportOpen}
194
+ onClose={() => setExportOpen(false)}
195
+ onExportPng={() => exportCanvas && exportCanvasPng(exportCanvas)}
196
+ onExportJson={() => exportJson(detections, groups, counts)}
197
+ onExportCsv={() => exportCsv(detections, groups)}
198
+ canExportPng={!!exportCanvas}
199
+ canExportData={detections.length > 0}
200
+ />
201
 
202
  <input
203
  ref={fileRef}
 
214
  className="hidden"
215
  onChange={(e) => e.target.files?.[0] && loadFile(e.target.files[0])}
216
  />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  </div>
218
  )
219
  }
frontend/src/components/DetectionCanvas.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef } from 'react'
2
  import type { Detection, DiameterGroup, ToolMode } from '../lib/types'
3
 
4
  interface Props {
@@ -11,6 +11,67 @@ interface Props {
11
  onCanvasReady?: (canvas: HTMLCanvasElement | null) => void
12
  }
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  export function DetectionCanvas({
15
  image,
16
  detections,
@@ -20,14 +81,31 @@ export function DetectionCanvas({
20
  onUpdate,
21
  onCanvasReady,
22
  }: Props) {
 
23
  const canvasRef = useRef<HTMLCanvasElement>(null)
24
- const dragRef = useRef<{ x: number; y: number } | null>(null)
 
25
  const areaRef = useRef<{ x1: number; y1: number; x2: number; y2: number } | null>(null)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  useEffect(() => {
28
  onCanvasReady?.(canvasRef.current)
29
  }, [onCanvasReady, image, detections])
30
 
 
31
  useEffect(() => {
32
  const canvas = canvasRef.current
33
  if (!canvas || !image) {
@@ -42,55 +120,70 @@ export function DetectionCanvas({
42
  const scale = Math.min(1, maxW / image.naturalWidth)
43
  canvas.width = Math.round(image.naturalWidth * scale)
44
  canvas.height = Math.round(image.naturalHeight * scale)
 
45
  ctx.clearRect(0, 0, canvas.width, canvas.height)
46
  ctx.drawImage(image, 0, 0, canvas.width, canvas.height)
47
 
48
- detections.forEach((d, idx) => {
49
- const group = groups.find((g) => g.id === d.groupId) ?? groups[0]
50
- const color = group?.color ?? '#ef4444'
51
- const x = d.xmin * scale
52
- const y = d.ymin * scale
53
- const w = (d.xmax - d.xmin) * scale
54
- const h = (d.ymax - d.ymin) * scale
55
- const cx = x + w / 2
56
- const cy = y + h / 2
57
- const r = Math.max(10, Math.min(w, h) / 2)
58
-
59
- ctx.beginPath()
60
- ctx.arc(cx, cy, r, 0, Math.PI * 2)
61
- ctx.strokeStyle = color
62
- ctx.lineWidth = 3
63
- ctx.stroke()
64
-
65
- ctx.fillStyle = color
66
- ctx.font = 'bold 12px sans-serif'
67
- ctx.textAlign = 'center'
68
- ctx.textBaseline = 'middle'
69
- ctx.fillText(String(idx + 1), cx, cy)
70
- })
71
 
72
  const area = areaRef.current
73
  if (area) {
74
- ctx.strokeStyle = '#fff'
 
 
 
75
  ctx.setLineDash([6, 4])
76
- ctx.strokeRect(
77
- area.x1 * scale,
78
- area.y1 * scale,
79
- (area.x2 - area.x1) * scale,
80
- (area.y2 - area.y1) * scale,
81
- )
82
- ctx.setLineDash([])
83
  }
84
  }, [image, detections, groups])
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  const toImageCoords = (clientX: number, clientY: number) => {
87
  const canvas = canvasRef.current!
88
  const rect = canvas.getBoundingClientRect()
89
- const scale = image!.naturalWidth / canvas.width
90
  return {
91
- x: (clientX - rect.left) * scale,
92
- y: (clientY - rect.top) * scale,
93
- displayScale: canvas.width / image!.naturalWidth,
94
  }
95
  }
96
 
@@ -104,25 +197,65 @@ export function DetectionCanvas({
104
  return -1
105
  }
106
 
 
 
107
  const handlePointerDown = (e: React.PointerEvent) => {
108
  if (!image) {
109
  return
110
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  const { x, y } = toImageCoords(e.clientX, e.clientY)
 
112
  if (tool === 'area') {
113
- dragRef.current = { x, y }
114
  areaRef.current = { x1: x, y1: y, x2: x, y2: y }
115
  return
116
  }
 
117
  const hit = findHit(x, y)
118
  if (tool === 'delete' && hit >= 0) {
119
  onUpdate(detections.filter((_, i) => i !== hit))
120
  return
121
  }
122
  if (tool === 'reassign' && hit >= 0) {
123
- onUpdate(
124
- detections.map((d, i) => (i === hit ? { ...d, groupId: selectedGroupId, manual: true } : d)),
125
- )
126
  return
127
  }
128
  if (tool === 'add') {
@@ -144,36 +277,104 @@ export function DetectionCanvas({
144
  }
145
 
146
  const handlePointerMove = (e: React.PointerEvent) => {
147
- if (!dragRef.current || tool !== 'area') {
148
  return
149
  }
150
- const { x, y } = toImageCoords(e.clientX, e.clientY)
151
- areaRef.current = {
152
- x1: Math.min(dragRef.current.x, x),
153
- y1: Math.min(dragRef.current.y, y),
154
- x2: Math.max(dragRef.current.x, x),
155
- y2: Math.max(dragRef.current.y, y),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
- onUpdate([...detections])
158
  }
159
 
160
- const handlePointerUp = () => {
161
- if (tool === 'area' && areaRef.current) {
 
 
 
 
 
162
  const a = areaRef.current
163
- onUpdate(
164
- detections.map((d) => {
165
- const cx = (d.xmin + d.xmax) / 2
166
- const cy = (d.ymin + d.ymax) / 2
167
- if (cx >= a.x1 && cx <= a.x2 && cy >= a.y1 && cy <= a.y2) {
168
- return { ...d, groupId: selectedGroupId, manual: true }
169
- }
170
- return d
171
- }),
172
- )
173
- }
174
- dragRef.current = null
175
- areaRef.current = null
176
- onUpdate([...detections])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  }
178
 
179
  if (!image) {
@@ -181,13 +382,36 @@ export function DetectionCanvas({
181
  }
182
 
183
  return (
184
- <canvas
185
- ref={canvasRef}
186
- className="w-full rounded-xl border border-slate-700 bg-black touch-none"
187
- onPointerDown={handlePointerDown}
188
- onPointerMove={handlePointerMove}
189
- onPointerUp={handlePointerUp}
190
- onPointerLeave={handlePointerUp}
191
- />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  )
193
  }
 
1
+ import { useEffect, useRef, useState } from 'react'
2
  import type { Detection, DiameterGroup, ToolMode } from '../lib/types'
3
 
4
  interface Props {
 
11
  onCanvasReady?: (canvas: HTMLCanvasElement | null) => void
12
  }
13
 
14
+ // --- drawing helpers ---
15
+
16
+ function hexToRgb(hex: string): [number, number, number] {
17
+ const v = parseInt(hex.replace('#', ''), 16)
18
+ return [(v >> 16) & 255, (v >> 8) & 255, v & 255]
19
+ }
20
+
21
+ function drawDetections(
22
+ ctx: CanvasRenderingContext2D,
23
+ detections: Detection[],
24
+ groups: DiameterGroup[],
25
+ scale: number,
26
+ ) {
27
+ const dense = detections.length > 300
28
+ const showNumbers = detections.length <= 500
29
+
30
+ detections.forEach((d, idx) => {
31
+ const group = groups.find((g) => g.id === d.groupId) ?? groups[0]
32
+ const color = group?.color ?? '#ef4444'
33
+ const [r, g, b] = hexToRgb(color)
34
+
35
+ const px = d.xmin * scale
36
+ const py = d.ymin * scale
37
+ const pw = (d.xmax - d.xmin) * scale
38
+ const ph = (d.ymax - d.ymin) * scale
39
+ const cx = px + pw / 2
40
+ const cy = py + ph / 2
41
+ const radius = Math.max(dense ? 4 : 6, Math.min(pw, ph) / 2)
42
+
43
+ ctx.save()
44
+
45
+ // filled circle – semi-transparent group color
46
+ ctx.beginPath()
47
+ ctx.arc(cx, cy, radius, 0, Math.PI * 2)
48
+ ctx.fillStyle = `rgba(${r},${g},${b},0.30)`
49
+ ctx.fill()
50
+
51
+ // ring border
52
+ ctx.strokeStyle = `rgba(${r},${g},${b},0.90)`
53
+ ctx.lineWidth = Math.max(1.5, radius * 0.14)
54
+ ctx.stroke()
55
+
56
+ // number label centered inside circle
57
+ if (!dense && showNumbers && radius >= 7) {
58
+ const fs = Math.max(9, Math.min(radius * 0.85, 15))
59
+ ctx.font = `bold ${fs}px sans-serif`
60
+ ctx.textAlign = 'center'
61
+ ctx.textBaseline = 'middle'
62
+ // dark shadow for readability
63
+ ctx.fillStyle = 'rgba(0,0,0,0.55)'
64
+ ctx.fillText(String(idx + 1), cx + 0.6, cy + 0.6)
65
+ ctx.fillStyle = '#ffffff'
66
+ ctx.fillText(String(idx + 1), cx, cy)
67
+ }
68
+
69
+ ctx.restore()
70
+ })
71
+ }
72
+
73
+ // --- component ---
74
+
75
  export function DetectionCanvas({
76
  image,
77
  detections,
 
81
  onUpdate,
82
  onCanvasReady,
83
  }: Props) {
84
+ const containerRef = useRef<HTMLDivElement>(null)
85
  const canvasRef = useRef<HTMLCanvasElement>(null)
86
+
87
+ // Area selection (image coords)
88
  const areaRef = useRef<{ x1: number; y1: number; x2: number; y2: number } | null>(null)
89
+ const areaStartRef = useRef<{ x: number; y: number } | null>(null)
90
+
91
+ // Zoom / pan (client coords)
92
+ const transformRef = useRef({ scale: 1, tx: 0, ty: 0 })
93
+
94
+ // Multi-touch tracking
95
+ const activeRef = useRef(new Map<number, { x: number; y: number }>())
96
+ const pinchRef = useRef<{ dist: number; mx: number; my: number } | null>(null)
97
+ // Pan (one finger in view mode, or while zoomed)
98
+ const panStartRef = useRef<{ x: number; y: number; tx: number; ty: number } | null>(null)
99
+ // Double tap
100
+ const lastTapRef = useRef(0)
101
+ // Display zoom scale for UI
102
+ const [displayScale, setDisplayScale] = useState(1)
103
 
104
  useEffect(() => {
105
  onCanvasReady?.(canvasRef.current)
106
  }, [onCanvasReady, image, detections])
107
 
108
+ // Render canvas content
109
  useEffect(() => {
110
  const canvas = canvasRef.current
111
  if (!canvas || !image) {
 
120
  const scale = Math.min(1, maxW / image.naturalWidth)
121
  canvas.width = Math.round(image.naturalWidth * scale)
122
  canvas.height = Math.round(image.naturalHeight * scale)
123
+
124
  ctx.clearRect(0, 0, canvas.width, canvas.height)
125
  ctx.drawImage(image, 0, 0, canvas.width, canvas.height)
126
 
127
+ drawDetections(ctx, detections, groups, scale)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  const area = areaRef.current
130
  if (area) {
131
+ ctx.save()
132
+ ctx.strokeStyle = 'rgba(255,255,255,0.9)'
133
+ ctx.fillStyle = 'rgba(255,255,255,0.08)'
134
+ ctx.lineWidth = 2
135
  ctx.setLineDash([6, 4])
136
+ const ax = area.x1 * scale
137
+ const ay = area.y1 * scale
138
+ const aw = (area.x2 - area.x1) * scale
139
+ const ah = (area.y2 - area.y1) * scale
140
+ ctx.fillRect(ax, ay, aw, ah)
141
+ ctx.strokeRect(ax, ay, aw, ah)
142
+ ctx.restore()
143
  }
144
  }, [image, detections, groups])
145
 
146
+ // --- transform helpers ---
147
+
148
+ const applyTransform = () => {
149
+ const canvas = canvasRef.current
150
+ if (!canvas) {
151
+ return
152
+ }
153
+ const { scale, tx, ty } = transformRef.current
154
+ canvas.style.transform = `translate(${tx}px, ${ty}px) scale(${scale})`
155
+ setDisplayScale(scale)
156
+ }
157
+
158
+ const clampTransform = () => {
159
+ const canvas = canvasRef.current
160
+ const container = containerRef.current
161
+ if (!canvas || !container) {
162
+ return
163
+ }
164
+ const t = transformRef.current
165
+ if (t.scale <= 1) {
166
+ transformRef.current = { scale: 1, tx: 0, ty: 0 }
167
+ } else {
168
+ const cw = container.clientWidth
169
+ const ch = container.clientHeight
170
+ // canvas layout size (unscaled)
171
+ const lw = canvas.offsetWidth
172
+ const lh = canvas.offsetHeight
173
+ t.tx = Math.min(0, Math.max(cw - lw * t.scale, t.tx))
174
+ t.ty = Math.min(0, Math.max(ch - lh * t.scale, t.ty))
175
+ }
176
+ setDisplayScale(transformRef.current.scale)
177
+ applyTransform()
178
+ }
179
+
180
+ // Convert client pointer position → image-space coordinates
181
  const toImageCoords = (clientX: number, clientY: number) => {
182
  const canvas = canvasRef.current!
183
  const rect = canvas.getBoundingClientRect()
 
184
  return {
185
+ x: ((clientX - rect.left) / rect.width) * image!.naturalWidth,
186
+ y: ((clientY - rect.top) / rect.height) * image!.naturalHeight,
 
187
  }
188
  }
189
 
 
197
  return -1
198
  }
199
 
200
+ // --- pointer event handlers ---
201
+
202
  const handlePointerDown = (e: React.PointerEvent) => {
203
  if (!image) {
204
  return
205
  }
206
+ e.currentTarget.setPointerCapture(e.pointerId)
207
+ activeRef.current.set(e.pointerId, { x: e.clientX, y: e.clientY })
208
+
209
+ // Two-finger pinch start
210
+ if (activeRef.current.size === 2) {
211
+ panStartRef.current = null
212
+ areaStartRef.current = null
213
+ const pts = [...activeRef.current.values()]
214
+ const dist = Math.hypot(pts[1].x - pts[0].x, pts[1].y - pts[0].y)
215
+ const mx = (pts[0].x + pts[1].x) / 2
216
+ const my = (pts[0].y + pts[1].y) / 2
217
+ pinchRef.current = { dist, mx, my }
218
+ return
219
+ }
220
+
221
+ if (activeRef.current.size > 2) {
222
+ return
223
+ }
224
+
225
+ // Double-tap to reset zoom
226
+ const now = Date.now()
227
+ if (now - lastTapRef.current < 280) {
228
+ transformRef.current = { scale: 1, tx: 0, ty: 0 }
229
+ applyTransform()
230
+ lastTapRef.current = 0
231
+ pinchRef.current = null
232
+ panStartRef.current = null
233
+ return
234
+ }
235
+ lastTapRef.current = now
236
+
237
+ // While zoomed or in view mode: pan
238
+ if (transformRef.current.scale > 1 || tool === 'view') {
239
+ panStartRef.current = { x: e.clientX, y: e.clientY, tx: transformRef.current.tx, ty: transformRef.current.ty }
240
+ return
241
+ }
242
+
243
+ // Edit tools
244
  const { x, y } = toImageCoords(e.clientX, e.clientY)
245
+
246
  if (tool === 'area') {
247
+ areaStartRef.current = { x, y }
248
  areaRef.current = { x1: x, y1: y, x2: x, y2: y }
249
  return
250
  }
251
+
252
  const hit = findHit(x, y)
253
  if (tool === 'delete' && hit >= 0) {
254
  onUpdate(detections.filter((_, i) => i !== hit))
255
  return
256
  }
257
  if (tool === 'reassign' && hit >= 0) {
258
+ onUpdate(detections.map((d, i) => (i === hit ? { ...d, groupId: selectedGroupId, manual: true } : d)))
 
 
259
  return
260
  }
261
  if (tool === 'add') {
 
277
  }
278
 
279
  const handlePointerMove = (e: React.PointerEvent) => {
280
+ if (!activeRef.current.has(e.pointerId)) {
281
  return
282
  }
283
+ activeRef.current.set(e.pointerId, { x: e.clientX, y: e.clientY })
284
+
285
+ // Pinch zoom + pan
286
+ if (activeRef.current.size === 2 && pinchRef.current) {
287
+ const pts = [...activeRef.current.values()]
288
+ const dist = Math.hypot(pts[1].x - pts[0].x, pts[1].y - pts[0].y)
289
+ const mx = (pts[0].x + pts[1].x) / 2
290
+ const my = (pts[0].y + pts[1].y) / 2
291
+
292
+ const t = transformRef.current
293
+ const scaleDelta = dist / pinchRef.current.dist
294
+ const newScale = Math.max(1, Math.min(6, t.scale * scaleDelta))
295
+
296
+ // zoom centered at pinch midpoint (in canvas layout coords)
297
+ const container = containerRef.current
298
+ if (container) {
299
+ const cr = container.getBoundingClientRect()
300
+ const localMx = mx - cr.left
301
+ const localMy = my - cr.top
302
+ // point in canvas layout before scale
303
+ const originX = (localMx - t.tx) / t.scale
304
+ const originY = (localMy - t.ty) / t.scale
305
+ t.tx = localMx - originX * newScale
306
+ t.ty = localMy - originY * newScale
307
+ }
308
+ t.scale = newScale
309
+
310
+ // additionally pan by midpoint movement
311
+ t.tx += mx - pinchRef.current.mx
312
+ t.ty += my - pinchRef.current.my
313
+
314
+ clampTransform()
315
+ pinchRef.current = { dist, mx, my }
316
+ return
317
+ }
318
+
319
+ // Single-finger pan
320
+ if (panStartRef.current && activeRef.current.size === 1) {
321
+ transformRef.current.tx = panStartRef.current.tx + (e.clientX - panStartRef.current.x)
322
+ transformRef.current.ty = panStartRef.current.ty + (e.clientY - panStartRef.current.y)
323
+ clampTransform()
324
+ return
325
+ }
326
+
327
+ // Area selection drag
328
+ if (areaStartRef.current && tool === 'area' && image) {
329
+ const { x, y } = toImageCoords(e.clientX, e.clientY)
330
+ areaRef.current = {
331
+ x1: Math.min(areaStartRef.current.x, x),
332
+ y1: Math.min(areaStartRef.current.y, y),
333
+ x2: Math.max(areaStartRef.current.x, x),
334
+ y2: Math.max(areaStartRef.current.y, y),
335
+ }
336
+ onUpdate([...detections])
337
  }
 
338
  }
339
 
340
+ const handlePointerUp = (e: React.PointerEvent) => {
341
+ if (e.currentTarget.hasPointerCapture(e.pointerId)) {
342
+ e.currentTarget.releasePointerCapture(e.pointerId)
343
+ }
344
+
345
+ // Finish area select
346
+ if (tool === 'area' && areaRef.current && areaStartRef.current) {
347
  const a = areaRef.current
348
+ if (a.x2 > a.x1 && a.y2 > a.y1) {
349
+ onUpdate(
350
+ detections.map((d) => {
351
+ const cx = (d.xmin + d.xmax) / 2
352
+ const cy = (d.ymin + d.ymax) / 2
353
+ return cx >= a.x1 && cx <= a.x2 && cy >= a.y1 && cy <= a.y2
354
+ ? { ...d, groupId: selectedGroupId, manual: true }
355
+ : d
356
+ }),
357
+ )
358
+ }
359
+ }
360
+
361
+ activeRef.current.delete(e.pointerId)
362
+
363
+ if (activeRef.current.size < 2) {
364
+ pinchRef.current = null
365
+ }
366
+ if (activeRef.current.size === 0) {
367
+ panStartRef.current = null
368
+ areaStartRef.current = null
369
+ areaRef.current = null
370
+ onUpdate([...detections])
371
+ }
372
+ }
373
+
374
+ const resetZoom = () => {
375
+ transformRef.current = { scale: 1, tx: 0, ty: 0 }
376
+ setDisplayScale(1)
377
+ applyTransform()
378
  }
379
 
380
  if (!image) {
 
382
  }
383
 
384
  return (
385
+ <div
386
+ ref={containerRef}
387
+ className="relative overflow-hidden rounded-2xl border border-slate-700/80 bg-black shadow-lg"
388
+ >
389
+ <canvas
390
+ ref={canvasRef}
391
+ style={{ transformOrigin: '0 0', display: 'block', width: '100%' }}
392
+ className="select-none touch-none"
393
+ onPointerDown={handlePointerDown}
394
+ onPointerMove={handlePointerMove}
395
+ onPointerUp={handlePointerUp}
396
+ onPointerCancel={handlePointerUp}
397
+ />
398
+ {/* Zoom badge + reset */}
399
+ {displayScale > 1 && (
400
+ <button
401
+ type="button"
402
+ onClick={resetZoom}
403
+ className="absolute top-2 right-2 rounded-full bg-black/70 px-2.5 py-1 text-xs font-medium text-white/90 backdrop-blur-sm active:scale-95"
404
+ aria-label="Reset zoom"
405
+ >
406
+ {displayScale.toFixed(1)}× ✕
407
+ </button>
408
+ )}
409
+ {/* Zoom hint (show once when results load) */}
410
+ {displayScale === 1 && detections.length > 0 && (
411
+ <div className="pointer-events-none absolute bottom-2 left-1/2 -translate-x-1/2 rounded-full bg-black/60 px-3 py-1 text-xs text-white/60 backdrop-blur-sm">
412
+ Pinch to zoom · double-tap to reset
413
+ </div>
414
+ )}
415
+ </div>
416
  )
417
  }
frontend/src/components/EmptyState.tsx ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Camera, ImagePlus } from 'lucide-react'
2
+ import { t } from '../lib/i18n'
3
+ import type { Lang } from '../lib/types'
4
+
5
+ interface Props {
6
+ lang: Lang
7
+ onCamera: () => void
8
+ onGallery: () => void
9
+ }
10
+
11
+ export function EmptyState({ lang, onCamera, onGallery }: Props) {
12
+ return (
13
+ <div className="flex flex-1 flex-col items-center justify-center px-4 py-10">
14
+ <div className="w-full max-w-sm rounded-2xl border border-dashed border-slate-600/80 bg-slate-900/40 p-8 text-center">
15
+ <div className="mx-auto mb-5 flex h-20 w-20 items-center justify-center rounded-full bg-slate-800/80 ring-1 ring-slate-700">
16
+ <Camera className="text-blue-400" size={36} strokeWidth={1.5} />
17
+ </div>
18
+ <h2 className="text-lg font-semibold text-white">{t(lang, 'getStarted')}</h2>
19
+ <p className="mt-2 text-sm leading-relaxed text-slate-400">{t(lang, 'noImage')}</p>
20
+ <div className="mt-6 flex flex-col gap-3">
21
+ <button
22
+ type="button"
23
+ className="flex h-12 items-center justify-center gap-2 rounded-xl bg-blue-600 text-base font-semibold text-white active:scale-[0.98]"
24
+ onClick={onCamera}
25
+ >
26
+ <Camera size={20} />
27
+ {t(lang, 'takePhoto')}
28
+ </button>
29
+ <button
30
+ type="button"
31
+ className="flex h-12 items-center justify-center gap-2 rounded-xl bg-slate-800 text-base font-medium text-slate-200 active:scale-[0.98]"
32
+ onClick={onGallery}
33
+ >
34
+ <ImagePlus size={20} />
35
+ {t(lang, 'chooseFile')}
36
+ </button>
37
+ </div>
38
+ </div>
39
+ <p className="mt-6 text-center text-xs text-slate-500">{t(lang, 'company')}</p>
40
+ </div>
41
+ )
42
+ }
frontend/src/components/ExportSheet.tsx ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { FileJson, FileSpreadsheet, Image } from 'lucide-react'
2
+ import { t } from '../lib/i18n'
3
+ import type { Lang } from '../lib/types'
4
+
5
+ interface Props {
6
+ lang: Lang
7
+ open: boolean
8
+ onClose: () => void
9
+ onExportPng: () => void
10
+ onExportJson: () => void
11
+ onExportCsv: () => void
12
+ canExportPng: boolean
13
+ canExportData: boolean
14
+ }
15
+
16
+ export function ExportSheet({
17
+ lang,
18
+ open,
19
+ onClose,
20
+ onExportPng,
21
+ onExportJson,
22
+ onExportCsv,
23
+ canExportPng,
24
+ canExportData,
25
+ }: Props) {
26
+ if (!open) {
27
+ return null
28
+ }
29
+
30
+ return (
31
+ <>
32
+ <button
33
+ type="button"
34
+ className="fixed inset-0 z-50 bg-slate-950/60 backdrop-blur-sm"
35
+ aria-label="Close"
36
+ onClick={onClose}
37
+ />
38
+ <div className="fixed inset-x-0 bottom-0 z-50 rounded-t-2xl border-t border-slate-700 bg-slate-900 px-4 pt-4 pb-[max(1rem,env(safe-area-inset-bottom))] shadow-2xl">
39
+ <div className="mx-auto mb-4 h-1 w-10 rounded-full bg-slate-600" />
40
+ <h2 className="mb-4 text-center text-base font-semibold text-white">{t(lang, 'export')}</h2>
41
+ <div className="mx-auto flex max-w-lg flex-col gap-2">
42
+ <button
43
+ type="button"
44
+ disabled={!canExportPng}
45
+ className="flex min-h-12 items-center gap-3 rounded-xl bg-slate-800 px-4 text-left text-sm font-medium disabled:opacity-50 active:bg-slate-700"
46
+ onClick={() => {
47
+ onExportPng()
48
+ onClose()
49
+ }}
50
+ >
51
+ <Image size={20} className="text-blue-400" />
52
+ {t(lang, 'exportPng')}
53
+ </button>
54
+ <button
55
+ type="button"
56
+ disabled={!canExportData}
57
+ className="flex min-h-12 items-center gap-3 rounded-xl bg-slate-800 px-4 text-left text-sm font-medium disabled:opacity-50 active:bg-slate-700"
58
+ onClick={() => {
59
+ onExportJson()
60
+ onClose()
61
+ }}
62
+ >
63
+ <FileJson size={20} className="text-amber-400" />
64
+ {t(lang, 'exportJson')}
65
+ </button>
66
+ <button
67
+ type="button"
68
+ disabled={!canExportData}
69
+ className="flex min-h-12 items-center gap-3 rounded-xl bg-slate-800 px-4 text-left text-sm font-medium disabled:opacity-50 active:bg-slate-700"
70
+ onClick={() => {
71
+ onExportCsv()
72
+ onClose()
73
+ }}
74
+ >
75
+ <FileSpreadsheet size={20} className="text-emerald-400" />
76
+ {t(lang, 'exportCsv')}
77
+ </button>
78
+ </div>
79
+ </div>
80
+ </>
81
+ )
82
+ }
frontend/src/components/GroupPanel.tsx CHANGED
@@ -1,3 +1,4 @@
 
1
  import type { DiameterGroup } from '../lib/types'
2
  import { t } from '../lib/i18n'
3
  import type { Lang } from '../lib/types'
@@ -20,48 +21,52 @@ export function GroupPanel({
20
  onExpectedChange,
21
  }: Props) {
22
  return (
23
- <div className="space-y-2">
24
- <h3 className="text-sm font-semibold text-slate-300">{t(lang, 'groups')}</h3>
25
- {groups.map((g) => {
26
- const count = counts[g.id] ?? 0
27
- const mismatch = g.expected !== undefined && g.expected !== count
28
- return (
29
- <button
30
- key={g.id}
31
- type="button"
32
- onClick={() => onSelectGroup(g.id)}
33
- className={`w-full rounded-lg border p-3 text-left transition ${
34
- selectedGroupId === g.id
35
- ? 'border-white bg-slate-800'
36
- : 'border-slate-700 bg-slate-900/60 hover:border-slate-500'
37
- }`}
38
- >
39
- <div className="flex items-center gap-2">
40
- <span className="h-3 w-3 rounded-full" style={{ background: g.color }} />
41
- <span className="font-medium">{g.label}</span>
42
- <span className="ml-auto text-lg font-bold">{count}</span>
43
- </div>
44
- <div className="mt-2 flex items-center gap-2 text-xs text-slate-400">
45
- <label htmlFor={`exp-${g.id}`}>{t(lang, 'expected')}:</label>
46
- <input
47
- id={`exp-${g.id}`}
48
- type="number"
49
- min={0}
50
- className="w-16 rounded bg-slate-800 px-2 py-1 text-white"
51
- value={g.expected ?? ''}
52
- onChange={(e) => {
53
- const v = e.target.value
54
- onExpectedChange(g.id, v === '' ? undefined : Number(v))
55
- }}
56
- onClick={(e) => e.stopPropagation()}
57
- />
58
- {mismatch && (
59
- <span className="text-amber-400">{t(lang, 'mismatch')}</span>
60
  )}
61
- </div>
62
- </button>
63
- )
64
- })}
65
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  )
67
  }
 
1
+ import { cn } from '../lib/utils'
2
  import type { DiameterGroup } from '../lib/types'
3
  import { t } from '../lib/i18n'
4
  import type { Lang } from '../lib/types'
 
21
  onExpectedChange,
22
  }: Props) {
23
  return (
24
+ <section>
25
+ <h3 className="mb-2 text-xs font-medium uppercase tracking-wide text-slate-500">{t(lang, 'groups')}</h3>
26
+ <div className="flex gap-3 overflow-x-auto pb-1 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden lg:flex-col lg:overflow-visible">
27
+ {groups.map((g) => {
28
+ const count = counts[g.id] ?? 0
29
+ const mismatch = g.expected !== undefined && g.expected !== count
30
+ const selected = selectedGroupId === g.id
31
+ return (
32
+ <button
33
+ key={g.id}
34
+ type="button"
35
+ onClick={() => onSelectGroup(g.id)}
36
+ className={cn(
37
+ 'w-[min(85vw,280px)] shrink-0 rounded-2xl border p-4 text-left transition active:scale-[0.99] lg:w-full',
38
+ selected
39
+ ? 'border-white/40 bg-slate-800 ring-1 ring-white/20'
40
+ : 'border-slate-700/80 bg-slate-900/60',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  )}
42
+ >
43
+ <div className="flex items-center gap-2">
44
+ <span className="h-3.5 w-3.5 rounded-full ring-2 ring-slate-700" style={{ background: g.color }} />
45
+ <span className="font-medium text-slate-100">{g.label}</span>
46
+ <span className="ml-auto text-2xl font-bold tabular-nums text-white">{count}</span>
47
+ </div>
48
+ <div className="mt-3 flex items-center gap-2 text-xs text-slate-400">
49
+ <label htmlFor={`exp-${g.id}`}>{t(lang, 'expected')}:</label>
50
+ <input
51
+ id={`exp-${g.id}`}
52
+ type="number"
53
+ inputMode="numeric"
54
+ min={0}
55
+ className="h-9 w-20 rounded-lg border border-slate-600 bg-slate-950 px-2 text-sm text-white"
56
+ value={g.expected ?? ''}
57
+ onChange={(e) => {
58
+ const v = e.target.value
59
+ onExpectedChange(g.id, v === '' ? undefined : Number(v))
60
+ }}
61
+ onClick={(e) => e.stopPropagation()}
62
+ />
63
+ {mismatch && <span className="font-medium text-amber-400">{t(lang, 'mismatch')}</span>}
64
+ </div>
65
+ </button>
66
+ )
67
+ })}
68
+ </div>
69
+ <p className="mt-2 text-xs text-slate-500">{t(lang, 'selectGroup')}</p>
70
+ </section>
71
  )
72
  }
frontend/src/components/MobileHeader.tsx ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Settings } from 'lucide-react'
2
+ import { cn } from '../lib/utils'
3
+ import { t } from '../lib/i18n'
4
+ import type { Lang } from '../lib/types'
5
+
6
+ interface Props {
7
+ lang: Lang
8
+ modelReady: boolean
9
+ settingsOpen: boolean
10
+ onToggleLang: () => void
11
+ onToggleSettings: () => void
12
+ }
13
+
14
+ export function MobileHeader({ lang, modelReady, settingsOpen, onToggleLang, onToggleSettings }: Props) {
15
+ return (
16
+ <header className="sticky top-0 z-40 border-b border-slate-800/80 bg-slate-950/90 px-4 pb-3 pt-[max(0.75rem,env(safe-area-inset-top))] backdrop-blur-md">
17
+ <div className="flex items-center gap-3">
18
+ <img src="/icon.svg" alt="" className="h-10 w-10 shrink-0 rounded-xl" />
19
+ <div className="min-w-0 flex-1">
20
+ <h1 className="truncate text-base font-bold leading-tight text-white">{t(lang, 'title')}</h1>
21
+ <p className="truncate text-xs text-slate-400">{t(lang, 'subtitle')}</p>
22
+ </div>
23
+ <div className="flex shrink-0 items-center gap-1.5">
24
+ <span
25
+ className={cn(
26
+ 'h-2 w-2 rounded-full',
27
+ modelReady ? 'bg-emerald-400 shadow-[0_0_8px_rgba(52,211,153,0.6)]' : 'animate-pulse bg-amber-400',
28
+ )}
29
+ title={modelReady ? t(lang, 'modelReady') : t(lang, 'loadingModel')}
30
+ />
31
+ <button
32
+ type="button"
33
+ className="flex h-10 w-10 items-center justify-center rounded-xl bg-slate-800 text-sm font-medium text-slate-200 active:scale-95"
34
+ onClick={onToggleLang}
35
+ aria-label="Switch language"
36
+ >
37
+ {lang === 'th' ? 'EN' : 'TH'}
38
+ </button>
39
+ <button
40
+ type="button"
41
+ className={cn(
42
+ 'flex h-10 w-10 items-center justify-center rounded-xl active:scale-95',
43
+ settingsOpen ? 'bg-blue-600 text-white' : 'bg-slate-800 text-slate-200',
44
+ )}
45
+ onClick={onToggleSettings}
46
+ aria-label={t(lang, 'settings')}
47
+ aria-expanded={settingsOpen}
48
+ >
49
+ <Settings size={18} />
50
+ </button>
51
+ </div>
52
+ </div>
53
+ </header>
54
+ )
55
+ }
frontend/src/components/ProcessingOverlay.tsx ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Loader2 } from 'lucide-react'
2
+ import { t } from '../lib/i18n'
3
+ import type { Lang } from '../lib/types'
4
+
5
+ interface Props {
6
+ lang: Lang
7
+ status: string
8
+ }
9
+
10
+ export function ProcessingOverlay({ lang, status }: Props) {
11
+ return (
12
+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/80 px-6 backdrop-blur-sm">
13
+ <div className="w-full max-w-xs rounded-2xl border border-slate-700 bg-slate-900 p-6 text-center shadow-2xl">
14
+ <Loader2 className="mx-auto mb-4 animate-spin text-emerald-400" size={40} />
15
+ <p className="text-base font-semibold text-white">{t(lang, 'processing')}</p>
16
+ <p className="mt-2 line-clamp-3 text-sm text-slate-400">{status || t(lang, 'pleaseWait')}</p>
17
+ </div>
18
+ </div>
19
+ )
20
+ }
frontend/src/components/ResultsSummary.tsx ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { t } from '../lib/i18n'
2
+ import type { DiameterGroup, Lang } from '../lib/types'
3
+
4
+ interface Props {
5
+ lang: Lang
6
+ total: number
7
+ groups: DiameterGroup[]
8
+ counts: Record<number, number>
9
+ }
10
+
11
+ export function ResultsSummary({ lang, total, groups, counts }: Props) {
12
+ return (
13
+ <section className="rounded-2xl border border-emerald-500/30 bg-gradient-to-br from-emerald-950/50 to-slate-900/80 p-4">
14
+ <div className="flex items-end justify-between gap-4">
15
+ <div>
16
+ <p className="text-xs font-medium uppercase tracking-wide text-emerald-400/80">{t(lang, 'total')}</p>
17
+ <p className="text-4xl font-bold tabular-nums leading-none text-white">{total.toLocaleString()}</p>
18
+ </div>
19
+ {groups.length > 0 && (
20
+ <div className="flex flex-wrap justify-end gap-1.5">
21
+ {groups.map((g) => (
22
+ <span
23
+ key={g.id}
24
+ className="inline-flex items-center gap-1.5 rounded-full bg-slate-950/50 px-2.5 py-1 text-xs font-medium text-slate-200 ring-1 ring-slate-700/80"
25
+ >
26
+ <span className="h-2 w-2 rounded-full" style={{ background: g.color }} />
27
+ {counts[g.id] ?? 0}
28
+ </span>
29
+ ))}
30
+ </div>
31
+ )}
32
+ </div>
33
+ </section>
34
+ )
35
+ }
frontend/src/components/SettingsPanel.tsx ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { t } from '../lib/i18n'
2
+ import type { Lang } from '../lib/types'
3
+
4
+ interface Props {
5
+ lang: Lang
6
+ open: boolean
7
+ groupCount: number | 'auto'
8
+ enhanceImage: boolean
9
+ useTiling: boolean
10
+ filterOutliers: boolean
11
+ onGroupCount: (value: number | 'auto') => void
12
+ onEnhanceImage: (value: boolean) => void
13
+ onUseTiling: (value: boolean) => void
14
+ onFilterOutliers: (value: boolean) => void
15
+ onRecluster: () => void
16
+ }
17
+
18
+ function Toggle({
19
+ checked,
20
+ onChange,
21
+ label,
22
+ }: {
23
+ checked: boolean
24
+ onChange: (v: boolean) => void
25
+ label: string
26
+ }) {
27
+ return (
28
+ <div className="flex min-h-11 items-center justify-between gap-3 rounded-xl bg-slate-800/60 px-3 py-2.5">
29
+ <span className="text-sm text-slate-200">{label}</span>
30
+ <button
31
+ type="button"
32
+ role="switch"
33
+ aria-checked={checked}
34
+ aria-label={label}
35
+ className={`relative h-7 w-12 shrink-0 rounded-full transition-colors ${checked ? 'bg-emerald-600' : 'bg-slate-600'}`}
36
+ onClick={() => onChange(!checked)}
37
+ >
38
+ <span
39
+ className={`absolute top-0.5 left-0.5 h-6 w-6 rounded-full bg-white shadow transition-transform ${checked ? 'translate-x-5' : ''}`}
40
+ />
41
+ </button>
42
+ </div>
43
+ )
44
+ }
45
+
46
+ export function SettingsPanel({
47
+ lang,
48
+ open,
49
+ groupCount,
50
+ enhanceImage,
51
+ useTiling,
52
+ filterOutliers,
53
+ onGroupCount,
54
+ onEnhanceImage,
55
+ onUseTiling,
56
+ onFilterOutliers,
57
+ onRecluster,
58
+ }: Props) {
59
+ if (!open) {
60
+ return null
61
+ }
62
+
63
+ return (
64
+ <section className="rounded-2xl border border-slate-700/80 bg-slate-900/60 p-4">
65
+ <h2 className="mb-3 text-sm font-semibold text-slate-300">{t(lang, 'settings')}</h2>
66
+
67
+ <div className="mb-4">
68
+ <p className="mb-2 text-xs text-slate-500">{t(lang, 'groupCount')}</p>
69
+ <div className="flex flex-wrap gap-2">
70
+ <button
71
+ type="button"
72
+ className={`min-h-10 rounded-lg px-3 text-sm font-medium ${groupCount === 'auto' ? 'bg-blue-600 text-white' : 'bg-slate-800 text-slate-300'}`}
73
+ onClick={() => onGroupCount('auto')}
74
+ >
75
+ {t(lang, 'auto')}
76
+ </button>
77
+ {[1, 2, 3, 4, 5, 6].map((n) => (
78
+ <button
79
+ key={n}
80
+ type="button"
81
+ className={`min-h-10 min-w-10 rounded-lg text-sm font-medium ${groupCount === n ? 'bg-blue-600 text-white' : 'bg-slate-800 text-slate-300'}`}
82
+ onClick={() => onGroupCount(n)}
83
+ >
84
+ {n}
85
+ </button>
86
+ ))}
87
+ <button
88
+ type="button"
89
+ className="min-h-10 rounded-lg bg-slate-700 px-3 text-sm font-medium text-slate-200"
90
+ onClick={onRecluster}
91
+ >
92
+ {t(lang, 'apply')}
93
+ </button>
94
+ </div>
95
+ </div>
96
+
97
+ <div className="space-y-2">
98
+ <Toggle checked={enhanceImage} onChange={onEnhanceImage} label={t(lang, 'enhanceImage')} />
99
+ <Toggle checked={useTiling} onChange={onUseTiling} label={t(lang, 'highAccuracy')} />
100
+ <Toggle checked={filterOutliers} onChange={onFilterOutliers} label={t(lang, 'filterOutliers')} />
101
+ </div>
102
+ </section>
103
+ )
104
+ }
frontend/src/components/StickyActionBar.tsx ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Camera, Download, ImagePlus, Loader2, RotateCcw } from 'lucide-react'
2
+ import { cn } from '../lib/utils'
3
+ import { t } from '../lib/i18n'
4
+ import type { Lang } from '../lib/types'
5
+
6
+ interface Props {
7
+ lang: Lang
8
+ hasImage: boolean
9
+ hasResults: boolean
10
+ busy: boolean
11
+ modelReady: boolean
12
+ onCamera: () => void
13
+ onGallery: () => void
14
+ onCount: () => void
15
+ onExport: () => void
16
+ onNewPhoto: () => void
17
+ }
18
+
19
+ export function StickyActionBar({
20
+ lang,
21
+ hasImage,
22
+ hasResults,
23
+ busy,
24
+ modelReady,
25
+ onCamera,
26
+ onGallery,
27
+ onCount,
28
+ onExport,
29
+ onNewPhoto,
30
+ }: Props) {
31
+ return (
32
+ <div className="fixed inset-x-0 bottom-0 z-40 border-t border-slate-800/80 bg-slate-950/95 px-4 pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] backdrop-blur-md">
33
+ {hasResults ? (
34
+ <div className="mx-auto flex max-w-lg gap-2">
35
+ <button
36
+ type="button"
37
+ className="flex h-12 flex-1 items-center justify-center gap-2 rounded-xl bg-slate-800 text-sm font-medium active:scale-[0.98]"
38
+ onClick={onExport}
39
+ >
40
+ <Download size={18} />
41
+ {t(lang, 'export')}
42
+ </button>
43
+ <button
44
+ type="button"
45
+ disabled={busy || !modelReady}
46
+ className="flex h-12 flex-[2] items-center justify-center gap-2 rounded-xl bg-emerald-600 text-sm font-bold text-white active:scale-[0.98] disabled:opacity-50"
47
+ onClick={onCount}
48
+ >
49
+ {busy ? <Loader2 className="animate-spin" size={18} /> : <RotateCcw size={18} />}
50
+ {t(lang, 'recount')}
51
+ </button>
52
+ </div>
53
+ ) : (
54
+ <div className="mx-auto flex max-w-lg items-center gap-2">
55
+ <button
56
+ type="button"
57
+ className="flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-slate-800 active:scale-95"
58
+ onClick={onCamera}
59
+ aria-label={t(lang, 'takePhoto')}
60
+ >
61
+ <Camera size={22} />
62
+ </button>
63
+ <button
64
+ type="button"
65
+ className="flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-slate-800 active:scale-95"
66
+ onClick={onGallery}
67
+ aria-label={t(lang, 'chooseFile')}
68
+ >
69
+ <ImagePlus size={22} />
70
+ </button>
71
+ <button
72
+ type="button"
73
+ disabled={!hasImage || busy || !modelReady}
74
+ className={cn(
75
+ 'flex h-12 min-w-0 flex-1 items-center justify-center gap-2 rounded-xl text-base font-bold text-white active:scale-[0.98] disabled:opacity-50',
76
+ hasImage ? 'bg-emerald-600' : 'bg-slate-700',
77
+ )}
78
+ onClick={onCount}
79
+ >
80
+ {busy ? <Loader2 className="animate-spin" size={20} /> : null}
81
+ {t(lang, 'count')}
82
+ </button>
83
+ </div>
84
+ )}
85
+ {hasImage && !hasResults && (
86
+ <button
87
+ type="button"
88
+ className="mx-auto mt-2 block text-xs text-slate-500 underline-offset-2 hover:text-slate-300 hover:underline"
89
+ onClick={onNewPhoto}
90
+ >
91
+ {t(lang, 'newPhoto')}
92
+ </button>
93
+ )}
94
+ </div>
95
+ )
96
+ }
frontend/src/components/ToolBar.tsx ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Eye, Plus, SquareDashed, Tag, Trash2 } from 'lucide-react'
2
+ import { cn } from '../lib/utils'
3
+ import { t } from '../lib/i18n'
4
+ import type { Lang, ToolMode } from '../lib/types'
5
+
6
+ const TOOLS: { id: ToolMode; icon: typeof Eye; labelKey: 'toolView' | 'toolDelete' | 'toolAdd' | 'toolReassign' | 'toolArea' }[] = [
7
+ { id: 'view', icon: Eye, labelKey: 'toolView' },
8
+ { id: 'delete', icon: Trash2, labelKey: 'toolDelete' },
9
+ { id: 'add', icon: Plus, labelKey: 'toolAdd' },
10
+ { id: 'reassign', icon: Tag, labelKey: 'toolReassign' },
11
+ { id: 'area', icon: SquareDashed, labelKey: 'toolArea' },
12
+ ]
13
+
14
+ interface Props {
15
+ lang: Lang
16
+ tool: ToolMode
17
+ onToolChange: (tool: ToolMode) => void
18
+ }
19
+
20
+ export function ToolBar({ lang, tool, onToolChange }: Props) {
21
+ return (
22
+ <section>
23
+ <p className="mb-2 text-xs font-medium uppercase tracking-wide text-slate-500">{t(lang, 'tools')}</p>
24
+ <div className="flex gap-2 overflow-x-auto pb-1 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
25
+ {TOOLS.map(({ id, icon: Icon, labelKey }) => {
26
+ const active = tool === id
27
+ return (
28
+ <button
29
+ key={id}
30
+ type="button"
31
+ className={cn(
32
+ 'flex min-h-11 shrink-0 items-center gap-2 rounded-xl px-4 text-sm font-medium transition active:scale-95',
33
+ active ? 'bg-white text-slate-900 shadow-lg' : 'bg-slate-800 text-slate-300',
34
+ )}
35
+ onClick={() => onToolChange(id)}
36
+ >
37
+ <Icon size={16} />
38
+ {t(lang, labelKey)}
39
+ </button>
40
+ )
41
+ })}
42
+ </div>
43
+ </section>
44
+ )
45
+ }
frontend/src/index.css CHANGED
@@ -1,22 +1,42 @@
1
  @import 'tailwindcss';
2
 
3
  :root {
4
- font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
5
  color: #f8fafc;
6
- background: #0f172a;
 
 
 
 
 
 
7
  }
8
 
9
  body {
10
  margin: 0;
11
  min-height: 100dvh;
12
- background: radial-gradient(circle at top, #1e293b, #0f172a 55%);
13
  }
14
 
15
  #root {
16
  min-height: 100dvh;
17
  }
18
 
 
 
 
 
19
  button:disabled {
20
  opacity: 0.5;
21
  cursor: not-allowed;
22
  }
 
 
 
 
 
 
 
 
 
 
 
1
  @import 'tailwindcss';
2
 
3
  :root {
4
+ font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
5
  color: #f8fafc;
6
+ background: #020617;
7
+ -webkit-tap-highlight-color: transparent;
8
+ -webkit-text-size-adjust: 100%;
9
+ }
10
+
11
+ html {
12
+ overscroll-behavior: none;
13
  }
14
 
15
  body {
16
  margin: 0;
17
  min-height: 100dvh;
18
+ background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e3a5f 0%, #020617 55%);
19
  }
20
 
21
  #root {
22
  min-height: 100dvh;
23
  }
24
 
25
+ button {
26
+ touch-action: manipulation;
27
+ }
28
+
29
  button:disabled {
30
  opacity: 0.5;
31
  cursor: not-allowed;
32
  }
33
+
34
+ input[type='number'] {
35
+ -moz-appearance: textfield;
36
+ }
37
+
38
+ input[type='number']::-webkit-outer-spin-button,
39
+ input[type='number']::-webkit-inner-spin-button {
40
+ -webkit-appearance: none;
41
+ margin: 0;
42
+ }
frontend/src/lib/i18n.ts CHANGED
@@ -3,42 +3,55 @@ import type { Lang } from './types'
3
  const messages = {
4
  en: {
5
  title: 'NPI Pipe Count',
6
- subtitle: 'Offline AI pipe counting with diameter sorting',
7
  takePhoto: 'Take Photo',
8
  chooseFile: 'Choose Image',
9
  count: 'Count Pipes',
 
 
10
  loadingModel: 'Loading model...',
 
11
  processing: 'Processing...',
12
- total: 'Total',
13
- groups: 'Diameter Groups',
14
- groupCount: 'Groups',
 
15
  auto: 'Auto',
16
  expected: 'Expected',
17
  toolView: 'View',
18
  toolDelete: 'Delete',
19
  toolAdd: 'Add',
20
  toolReassign: 'Re-tag',
21
- toolArea: 'Area select',
22
- exportPng: 'Export PNG',
23
- exportJson: 'Export JSON',
24
- exportCsv: 'Export CSV',
 
 
25
  highAccuracy: 'High accuracy (multi-tile)',
26
- enhanceImage: 'Enhance image (contrast + sharpen)',
27
  filterOutliers: 'Filter outliers',
28
  mismatch: 'Mismatch',
29
- selectGroup: 'Select target group',
30
- noImage: 'Upload or capture a pipe bundle photo to begin.',
 
31
  company: 'Nawaplastic Industry Co., Ltd.',
 
 
32
  },
33
  th: {
34
  title: 'NPI นับท่อ',
35
- subtitle: 'นับท่อออฟไลน์ พร้อมจัดกลุ่มตามเส้นผ่านศูนย์กลาง',
36
  takePhoto: 'ถ่ายภาพ',
37
  chooseFile: 'เลือกรูป',
38
  count: 'นับท่อ',
 
 
39
  loadingModel: 'กำลังโหลดโมเดล...',
 
40
  processing: 'กำลังประมวลผล...',
41
- total: 'รวม',
 
42
  groups: 'กลุ่มเส้นผ่านศูนย์กลาง',
43
  groupCount: 'จำนวนกลุ่ม',
44
  auto: 'อัตโนมัติ',
@@ -48,16 +61,21 @@ const messages = {
48
  toolAdd: 'เพิ่ม',
49
  toolReassign: 'เปลี่ยนกลุ่ม',
50
  toolArea: 'เลือกพื้นที่',
51
- exportPng: 'ส่งออก PNG',
52
- exportJson: 'ส่งออก JSON',
53
- exportCsv: 'ส่งออก CSV',
 
 
54
  highAccuracy: 'ความแม่นยำสูง (หลายส่วน)',
55
- enhanceImage: 'ปรับภาพ (คอนทราสต์ + ความคม)',
56
  filterOutliers: 'กรองค่าผิดปกติ',
57
  mismatch: 'ไม่ตรง',
58
- selectGroup: 'เลือกกลุ่มเป้าหมาย',
59
- noImage: 'อัปโหลดหรือถ่ายภาพมัดท่อเพื่อเริ่มต้น',
 
60
  company: 'บริษัท นวพลาสติก อุตสาหกรรม จำกัด',
 
 
61
  },
62
  } as const
63
 
 
3
  const messages = {
4
  en: {
5
  title: 'NPI Pipe Count',
6
+ subtitle: 'Offline AI pipe counting',
7
  takePhoto: 'Take Photo',
8
  chooseFile: 'Choose Image',
9
  count: 'Count Pipes',
10
+ recount: 'Re-count',
11
+ newPhoto: 'Choose a different photo',
12
  loadingModel: 'Loading model...',
13
+ modelReady: 'Model ready',
14
  processing: 'Processing...',
15
+ pleaseWait: 'This may take a moment on large photos.',
16
+ total: 'Total pipes',
17
+ groups: 'Diameter groups',
18
+ groupCount: 'Number of groups',
19
  auto: 'Auto',
20
  expected: 'Expected',
21
  toolView: 'View',
22
  toolDelete: 'Delete',
23
  toolAdd: 'Add',
24
  toolReassign: 'Re-tag',
25
+ toolArea: 'Area',
26
+ tools: 'Correction tools',
27
+ exportPng: 'Annotated image (PNG)',
28
+ exportJson: 'Data (JSON)',
29
+ exportCsv: 'Spreadsheet (CSV)',
30
+ export: 'Export results',
31
  highAccuracy: 'High accuracy (multi-tile)',
32
+ enhanceImage: 'Enhance image',
33
  filterOutliers: 'Filter outliers',
34
  mismatch: 'Mismatch',
35
+ selectGroup: 'Tap a group, then use tools to correct detections.',
36
+ noImage: 'Capture or upload a photo of a pipe bundle. Works fully offline after first load.',
37
+ getStarted: 'Ready to count',
38
  company: 'Nawaplastic Industry Co., Ltd.',
39
+ settings: 'Settings',
40
+ apply: 'Apply',
41
  },
42
  th: {
43
  title: 'NPI นับท่อ',
44
+ subtitle: 'นับท่อออฟไลน์ด้วย AI',
45
  takePhoto: 'ถ่ายภาพ',
46
  chooseFile: 'เลือกรูป',
47
  count: 'นับท่อ',
48
+ recount: 'นับใหม่',
49
+ newPhoto: 'เลือกรูปอื่น',
50
  loadingModel: 'กำลังโหลดโมเดล...',
51
+ modelReady: 'โมเดลพร้อมใช้งาน',
52
  processing: 'กำลังประมวลผล...',
53
+ pleaseWait: 'รูปขนาดใหญ่อาจใช้เวลาสักครู่',
54
+ total: 'จำนวนท่อรวม',
55
  groups: 'กลุ่มเส้นผ่านศูนย์กลาง',
56
  groupCount: 'จำนวนกลุ่ม',
57
  auto: 'อัตโนมัติ',
 
61
  toolAdd: 'เพิ่ม',
62
  toolReassign: 'เปลี่ยนกลุ่ม',
63
  toolArea: 'เลือกพื้นที่',
64
+ tools: 'เครื่องมือแก้ไข',
65
+ exportPng: 'รูปพร้อมหมายเลข (PNG)',
66
+ exportJson: 'ข้อมูล (JSON)',
67
+ exportCsv: 'ตาราง (CSV)',
68
+ export: 'ส่งออกผลลัพธ์',
69
  highAccuracy: 'ความแม่นยำสูง (หลายส่วน)',
70
+ enhanceImage: 'ปรับภาพอัตโนมัติ',
71
  filterOutliers: 'กรองค่าผิดปกติ',
72
  mismatch: 'ไม่ตรง',
73
+ selectGroup: 'แตะเลือกกลุ่ม แล้วใช้เครื่องมือแก้ไขจุดตรวจจับ',
74
+ noImage: 'ถ่ายหรืออัปโหลดรูปมัดท่อ ใช้งานออฟไลน์ได้หลังโหลดครั้งแรก',
75
+ getStarted: 'พร้อมนับท่อ',
76
  company: 'บริษัท นวพลาสติก อุตสาหกรรม จำกัด',
77
+ settings: 'ตั้งค่า',
78
+ apply: 'ใช้',
79
  },
80
  } as const
81
 
frontend/src/lib/utils.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import { clsx, type ClassValue } from 'clsx'
2
+ import { twMerge } from 'tailwind-merge'
3
+
4
+ export function cn(...inputs: ClassValue[]): string {
5
+ return twMerge(clsx(inputs))
6
+ }
frontend/vite.config.ts CHANGED
@@ -14,8 +14,8 @@ export default defineConfig({
14
  name: 'NPI Pipe Count',
15
  short_name: 'Pipe Count',
16
  description: 'Offline pipe counting with diameter sorting',
17
- theme_color: '#0f172a',
18
- background_color: '#0f172a',
19
  display: 'standalone',
20
  orientation: 'portrait',
21
  start_url: '/',
 
14
  name: 'NPI Pipe Count',
15
  short_name: 'Pipe Count',
16
  description: 'Offline pipe counting with diameter sorting',
17
+ theme_color: '#020617',
18
+ background_color: '#020617',
19
  display: 'standalone',
20
  orientation: 'portrait',
21
  start_url: '/',