Skip to content

Commit b12cbde

Browse files
committed
chore: add prettier
1 parent fb38397 commit b12cbde

15 files changed

+176
-248
lines changed

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": false,
5+
"printWidth": 120,
6+
"tabWidth": 2,
7+
"useTabs": false,
8+
"arrowParens": "always",
9+
"endOfLine": "lf"
10+
}

index.html

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
/>
1818

1919
<meta property="og:type" content="website" />
20-
<meta
21-
property="og:title"
22-
content="CommonForms - AI-Powered PDF Form Field Detection in Browser"
23-
/>
20+
<meta property="og:title" content="CommonForms - AI-Powered PDF Form Field Detection in Browser" />
2421
<meta
2522
property="og:description"
2623
content="Automatically detect and add form fields to PDFs using CommonForms AI models. Free browser-based tool using ONNX Runtime - no server upload required."
@@ -31,10 +28,7 @@
3128
/>
3229

3330
<meta name="twitter:card" content="summary_large_image" />
34-
<meta
35-
name="twitter:title"
36-
content="CommonForms - AI-Powered PDF Form Field Detection in Browser"
37-
/>
31+
<meta name="twitter:title" content="CommonForms - AI-Powered PDF Form Field Detection in Browser" />
3832
<meta
3933
name="twitter:description"
4034
content="Automatically detect and add form fields to PDFs using CommonForms AI models. Free browser-based tool using ONNX Runtime - no server upload required."

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"dev": "vite",
77
"build": "tsc && vite build",
88
"preview": "vite preview",
9-
"test:types": "tsc --noEmit"
9+
"test:types": "tsc --noEmit",
10+
"format:check": "prettier --check .",
11+
"format:fix": "prettier --write ."
1012
},
1113
"dependencies": {
1214
"@simplepdf/react-embed-pdf": "^1.9.0",

postcss.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
22
plugins: {
3-
'@tailwindcss/postcss': {},
3+
"@tailwindcss/postcss": {},
44
autoprefixer: {},
55
},
6-
}
6+
};

src/FormFieldsDetection.tsx

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,19 @@ import * as pdfjsLib from "pdfjs-dist";
55
import { detectFormFields } from "./lib/formFieldDetection";
66
import { applyAcroFields } from "./lib/applyAcroFields";
77
import { ensureValidPDF } from "./lib/ensureValidPDF";
8-
import {
9-
ModelSelection,
10-
type ModelType,
11-
type ModelOption,
12-
} from "./components/ModelSelection";
13-
import {
14-
DetectionResults,
15-
type ProcessingResult,
16-
} from "./components/DetectionResults";
8+
import { ModelSelection, type ModelType, type ModelOption } from "./components/ModelSelection";
9+
import { DetectionResults, type ProcessingResult } from "./components/DetectionResults";
1710
import { ProcessingSteps } from "./components/ProcessingSteps";
1811
import { Header } from "./components/Header";
1912
import { StatusMessage, type Status } from "./components/StatusMessage";
2013

2114
pdfjsLib.GlobalWorkerOptions.workerSrc = `https://cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjsLib.version}/build/pdf.worker.min.mjs`;
2215

23-
ort.env.wasm.wasmPaths =
24-
"https://cdn.jsdelivr.net/npm/onnxruntime-web@1.23.0/dist/";
16+
ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.23.0/dist/";
2517

2618
const MODEL_URLS: Record<ModelType, string> = {
27-
"FFDNet-S":
28-
"https://us-beautiful-space.nyc3.digitaloceanspaces.com/commonforms/FFDNet-S.onnx",
29-
"FFDNet-L":
30-
"https://huggingface.co/jbarrow/FFDNet-L-cpu/resolve/main/FFDNet-L.onnx",
19+
"FFDNet-S": "https://us-beautiful-space.nyc3.digitaloceanspaces.com/commonforms/FFDNet-S.onnx",
20+
"FFDNet-L": "https://huggingface.co/jbarrow/FFDNet-L-cpu/resolve/main/FFDNet-L.onnx",
3121
};
3222

3323
const AVAILABLE_MODELS: ModelOption[] = [
@@ -48,19 +38,16 @@ interface PdfFileState {
4838
export function FormFieldsDetection() {
4939
const { t } = useTranslation();
5040
const [pdfFile, setPdfFile] = useState<PdfFileState | null>(null);
51-
const [modelConfiguration, setModelConfiguration] =
52-
useState<ModelConfiguration>({
53-
selectedModel: "FFDNet-S",
54-
confidenceThreshold: 0.4,
55-
});
41+
const [modelConfiguration, setModelConfiguration] = useState<ModelConfiguration>({
42+
selectedModel: "FFDNet-S",
43+
confidenceThreshold: 0.4,
44+
});
5645
const [result, setResult] = useState<ProcessingResult | null>(null);
5746
const [status, setStatus] = useState<Status>({ type: "idle" });
5847
const fileInputRef = useRef<HTMLInputElement>(null);
5948
const canvasRef = useRef<HTMLCanvasElement>(null);
6049

61-
const handleFileSelect = async (
62-
event: React.ChangeEvent<HTMLInputElement>
63-
) => {
50+
const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
6451
const file = event.target.files?.[0];
6552

6653
if (!file || file.type !== "application/pdf") {
@@ -161,7 +148,10 @@ export function FormFieldsDetection() {
161148
return;
162149
}
163150

164-
setStatus({ type: "loading", message: t("statusMessages.applyingAcroFields") });
151+
setStatus({
152+
type: "loading",
153+
message: t("statusMessages.applyingAcroFields"),
154+
});
165155

166156
const acroFieldsResult = await applyAcroFields({
167157
pdfFile: pdfFile.file,

src/components/DetectionResults.tsx

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ export function DetectionResults({ result }: DetectionResultsProps) {
3333
}
3434

3535
const currentPage = result.pages[currentPageIndex] || result.pages[0];
36-
const totalFields = result.pages.reduce(
37-
(sum, page) => sum + page.fields.length,
38-
0
39-
);
36+
const totalFields = result.pages.reduce((sum, page) => sum + page.fields.length, 0);
4037

4138
const handlePreviousPage = () => {
4239
setCurrentPageIndex((prev) => Math.max(0, prev - 1));
@@ -50,9 +47,7 @@ export function DetectionResults({ result }: DetectionResultsProps) {
5047
<div className="mt-6 md:mt-8 grid grid-cols-1 md:grid-cols-4 gap-4 md:gap-6">
5148
{/* Visualization */}
5249
<div className="col-span-1 md:col-span-3">
53-
<h2 className="text-xl md:text-2xl font-bold text-gray-900 mb-4">
54-
{t("detectionResults.detectedFormFields")}
55-
</h2>
50+
<h2 className="text-xl md:text-2xl font-bold text-gray-900 mb-4">{t("detectionResults.detectedFormFields")}</h2>
5651
<img
5752
src={currentPage.imageData}
5853
alt={`Detected Fields - Page ${currentPageIndex + 1}`}
@@ -65,24 +60,15 @@ export function DetectionResults({ result }: DetectionResultsProps) {
6560
<div className="mt-4 md:mt-6 flex flex-col md:flex-row items-start md:items-center justify-between gap-4">
6661
<div className="flex flex-wrap gap-3 md:gap-4 text-sm">
6762
<div className="flex items-center gap-2">
68-
<div
69-
className="w-4 h-4 rounded"
70-
style={{ backgroundColor: "#3B82F6" }}
71-
></div>
63+
<div className="w-4 h-4 rounded" style={{ backgroundColor: "#3B82F6" }}></div>
7264
<span>TextBox</span>
7365
</div>
7466
<div className="flex items-center gap-2">
75-
<div
76-
className="w-4 h-4 rounded"
77-
style={{ backgroundColor: "#10B981" }}
78-
></div>
67+
<div className="w-4 h-4 rounded" style={{ backgroundColor: "#10B981" }}></div>
7968
<span>ChoiceButton</span>
8069
</div>
8170
<div className="flex items-center gap-2">
82-
<div
83-
className="w-4 h-4 rounded"
84-
style={{ backgroundColor: "#F59E0B" }}
85-
></div>
71+
<div className="w-4 h-4 rounded" style={{ backgroundColor: "#F59E0B" }}></div>
8672
<span>Signature</span>
8773
</div>
8874
</div>
@@ -100,7 +86,10 @@ export function DetectionResults({ result }: DetectionResultsProps) {
10086
10187
</button>
10288
<span className="text-sm font-medium">
103-
{t("detectionResults.pageOfTotal", { current: currentPageIndex + 1, total: result.pages.length })}
89+
{t("detectionResults.pageOfTotal", {
90+
current: currentPageIndex + 1,
91+
total: result.pages.length,
92+
})}
10493
</span>
10594
<button
10695
onClick={handleNextPage}
@@ -140,9 +129,7 @@ export function DetectionResults({ result }: DetectionResultsProps) {
140129
</div>
141130
<div className="flex justify-between">
142131
<span className="text-gray-600">{t("detectionResults.processingTime")}</span>
143-
<span className="font-semibold text-emerald-600">
144-
{result.processingTime.toFixed(0)}ms
145-
</span>
132+
<span className="font-semibold text-emerald-600">{result.processingTime.toFixed(0)}ms</span>
146133
</div>
147134
</div>
148135
</div>

src/components/Header.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ export function Header() {
2020
></iframe>
2121
</div>
2222
</h1>
23-
<p className="text-gray-600 text-base md:text-lg">
24-
{t("header.subtitle")}
25-
</p>
23+
<p className="text-gray-600 text-base md:text-lg">{t("header.subtitle")}</p>
2624
<div className="flex flex-wrap gap-2 mt-4">
2725
<a
2826
href="https://github.com/jbarrow/commonforms"
@@ -71,9 +69,7 @@ export function Header() {
7169

7270
<div className="grid md:grid-cols-2 gap-3 md:gap-4 mb-6 md:mb-8">
7371
<div className="p-3 bg-sky-50 rounded-lg border border-sky-200">
74-
<h3 className="text-lg font-semibold text-sky-900 mb-2">
75-
{t("header.aboutCommonForms")}
76-
</h3>
72+
<h3 className="text-lg font-semibold text-sky-900 mb-2">{t("header.aboutCommonForms")}</h3>
7773
<p className="text-sky-800 text-sm">
7874
<Trans
7975
i18nKey="header.aboutCommonFormsDescription"
@@ -108,9 +104,7 @@ export function Header() {
108104
</div>
109105

110106
<div className="p-3 bg-emerald-50 rounded-lg border border-emerald-200">
111-
<h3 className="text-lg font-semibold text-emerald-900 mb-2">
112-
{t("header.howItWorks")}
113-
</h3>
107+
<h3 className="text-lg font-semibold text-emerald-900 mb-2">{t("header.howItWorks")}</h3>
114108
<ul className="text-emerald-800 text-sm space-y-1">
115109
<li>
116110
{" "}

src/components/ModelSelection.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export function ModelSelection({
2828
<div className="mb-6">
2929
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-6 max-w-2xl">
3030
<div>
31-
<label className="block text-sm font-medium text-gray-700 mb-2">
32-
{t("modelSelection.selectModel")}
33-
</label>
31+
<label className="block text-sm font-medium text-gray-700 mb-2">{t("modelSelection.selectModel")}</label>
3432
<select
3533
value={selectedModel}
3634
onChange={(e) => onSelectModel(e.target.value as ModelType)}

src/components/ProcessingSteps.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const ProcessingSteps = ({
3232
const currentLanguage = i18n.language;
3333
const supportedLocales = ["en", "de", "es", "fr", "it", "pt"] as const;
3434

35-
if (supportedLocales.includes(currentLanguage as typeof supportedLocales[number])) {
35+
if (supportedLocales.includes(currentLanguage as (typeof supportedLocales)[number])) {
3636
return currentLanguage as "en" | "de" | "es" | "fr" | "it" | "pt";
3737
}
3838

@@ -106,19 +106,17 @@ export const ProcessingSteps = ({
106106
</span>
107107
</div>
108108
<div className="border border-gray-300 rounded-lg p-4 md:p-6 text-center hover:border-sky-500 transition-colors flex flex-col justify-start h-32">
109-
<input
110-
ref={fileInputRef}
111-
type="file"
112-
accept="application/pdf"
113-
onChange={onFileSelect}
114-
className="hidden"
115-
/>
109+
<input ref={fileInputRef} type="file" accept="application/pdf" onChange={onFileSelect} className="hidden" />
116110
<div className="flex flex-col gap-2">
117111
<button
118112
onClick={handleFileInputClick}
119113
className="px-4 py-2 bg-sky-500 text-white rounded-lg hover:bg-sky-600 transition-colors font-medium text-sm cursor-pointer overflow-hidden text-ellipsis whitespace-nowrap"
120114
>
121-
{pdfFile ? t("processingSteps.selectedFile", { fileName: pdfFile.name }) : t("processingSteps.choosePdfForm")}
115+
{pdfFile
116+
? t("processingSteps.selectedFile", {
117+
fileName: pdfFile.name,
118+
})
119+
: t("processingSteps.choosePdfForm")}
122120
</button>
123121
<button
124122
onClick={handleLoadExample}
@@ -188,4 +186,4 @@ export const ProcessingSteps = ({
188186
</div>
189187
</>
190188
);
191-
}
189+
};

src/i18n/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ const STORAGE_KEY = "commonforms-language";
2121

2222
const getBrowserLanguage = (): SupportedLanguage => {
2323
const browserLang = navigator.language.split("-")[0];
24-
return Object.keys(SUPPORTED_LANGUAGES).includes(browserLang)
25-
? (browserLang as SupportedLanguage)
26-
: "en";
24+
return Object.keys(SUPPORTED_LANGUAGES).includes(browserLang) ? (browserLang as SupportedLanguage) : "en";
2725
};
2826

2927
const getStoredLanguage = (): SupportedLanguage | null => {

0 commit comments

Comments
 (0)