diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3366dc4..6070bca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,9 @@ jobs: - name: Lint run: npm run lint + - name: Knip + run: npm run knip + - name: Typecheck run: npm run typecheck diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f55915..f53f8da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,33 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and ## [Unreleased] -No unreleased changes at this time. Future work tracked in `docs/ROADMAP.md` under "Beyond Phase 3". +No unreleased changes at this time. Future work tracked in `docs/ROADMAP.md` under "Beyond". + +## [1.5.0] — 2026-05-21 + +### Added + +- **Scroll-to-top button on the About page.** A floating up-arrow button (`src/components/common/ScrollToTop.tsx`) fades in at the bottom-right once the About page is scrolled past ~320px, and smoothly returns to the top on click. The About page hides its scrollbar (`.scrollbar-hide`), so there was previously no quick way back up. Respects `prefers-reduced-motion` (jumps instead of animating) and stays out of the keyboard tab order / accessibility tree while hidden. New i18n key `common.scroll_to_top` across all four locales (en/vi/ja/zh-CN). The button is About-only by design — the converter workspace uses a fixed `h-dvh` layout that never page-scrolls. + +### Changed + +- **Internal refactor — three oversized components decomposed (behavior-preserving).** `BatchPanel.tsx` (515 lines), `ConverterWorkspace.tsx` (314), and `InputPanel.tsx` (278) were split into focused, reusable units: pure utilities (`lib/format-bytes.ts`, `lib/editor-language.ts`, `lib/read-file.ts`), leaf components (`common/ToolbarButton.tsx` — de-duplicated from InputPanel + OutputPanel — plus `converter/BatchItemRow.tsx` and `converter/BatchSummaryChips.tsx`), and hooks (`useFileAccept`, `useBatchActions`, `useConversionResult`, `useOutputBadge`, `useBatchFileRouter`). No converter or UI behavior changed; all 193 unit tests still pass. + +### Tooling + +- **`knip` integrated for dead-code analysis.** New `knip.json` config, an `npm run knip` script, and a `Knip` step in CI (`.github/workflows/ci.yml`) — unused files and dependencies are now caught on every push. The initial sweep deleted the orphaned `src/hooks/useLocalStorage.ts` (superseded by `lib/options-storage.ts`), dropped the unused `i18n` default export and the unused `BatchPanel` prop `onAddExternalFiles`, and un-exported the internally-used `nativeReadText`. knip's export-level `types` check is disabled — the converter-contract types in `converters/types.ts` are intentional public vocabulary, not dead code. + +### Fixed + +- **`globals` was a phantom (undeclared) devDependency.** `eslint.config.js` imports `globals`, but it was never listed in `package.json` — linting only worked because ESLint pulls `globals` in transitively. Now declared explicitly so a stricter or deduped install can't break `npm run lint`. Surfaced by the new `knip` check. + +### Dependencies + +- Added `knip` `^6.14.1` (ISC, dead-code analyzer, devDep) and `globals` `^14.0.0` (MIT, explicit devDep — previously resolved transitively). `THIRD-PARTY.md` updated. + +### Tests + +- No new tests this round — the refactor is behavior-preserving and the scroll button is editor/CSS/i18n surface best verified manually. The **193** existing unit tests still pass; typecheck, lint, `knip`, and `prettier --check` are all green. ## [1.4.3] — 2026-05-14 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a820f08..e5d11f8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,11 +20,12 @@ Open . ```bash npm run format npm run lint + npm run knip npm run typecheck npm run build ``` - CI runs all four. If any fails, your PR can't be merged. + CI runs all of these. If any fails, your PR can't be merged. 2. **Match the project style.** Read [`CLAUDE.md`](CLAUDE.md) for non-negotiable conventions (converter shape, error handling, i18n requirements). diff --git a/THIRD-PARTY.md b/THIRD-PARTY.md index 81c6433..d077fd2 100644 --- a/THIRD-PARTY.md +++ b/THIRD-PARTY.md @@ -122,6 +122,8 @@ installed as a runtime dependency. | `@testing-library/jest-dom` | ^6.6.0 | MIT | [testing-library.com](https://testing-library.com/) | | `@testing-library/user-event` | ^14.5.0 | MIT | [testing-library.com](https://testing-library.com/) | | `jsdom` | ^29.0.0 | MIT | [github.com/jsdom/jsdom](https://github.com/jsdom/jsdom) | +| `knip` | ^6.14.1 | ISC | [knip.dev](https://knip.dev/) | +| `globals` | ^14.0.0 | MIT | [github.com/sindresorhus/globals](https://github.com/sindresorhus/globals) | ## Fonts diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 523567c..d2be8f2 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -219,7 +219,33 @@ Goal: ship the .NET RESX converter and integrate with existing AutoClickForge / --- -## Beyond Phase 3 — Ideas (no commitment) +## Phase 4 — Binary formats & reverse conversion ✅ + +**Status**: complete (shipped in v1.1.0) + +Post-1.0 expansion: three binary target formats and bidirectional conversion. + +- [x] **BSON / CBOR / MessagePack** converters — output rendered as base64 (default) or hex; downloads decode back to raw bytes. New `ConverterMeta.binary` flag. +- [x] **Reverse conversion** — optional `Converter.reverse()` interface method; JSONL, CSV/TSV, YAML, TOML, RESX → JSON. New `DirectionToggle` component, direction persisted to localStorage. +- [x] Reverse batch processing — drop non-JSON files, get a `.zip` of `.json` outputs back. + +**12/12 formats production-ready.** + +--- + +## Phase 5 — Maintenance & refactor ✅ + +**Status**: complete (shipped in v1.5.0) + +Codebase hygiene plus a small UX addition — no converter behavior changed. + +- [x] Decomposed three oversized components (`BatchPanel`, `ConverterWorkspace`, `InputPanel`) into focused pure utilities, leaf components, and hooks — behavior-preserving, all 193 tests still green. +- [x] Integrated `knip` for dead-code analysis: `knip.json` config, `npm run knip` script, and a CI step. Initial sweep removed orphaned code and a phantom dependency. +- [x] Scroll-to-top button on the long, scrollbar-hidden About page (respects `prefers-reduced-motion`). + +--- + +## Beyond — Ideas (no commitment) - **JSON → Excel (.xlsx)** via SheetJS — possible if Markdown/CSV doesn't cover the use case - **Reverse direction** (other format → JSON): different mental model; might warrant a sibling app @@ -228,7 +254,7 @@ Goal: ship the .NET RESX converter and integrate with existing AutoClickForge / - **VS Code extension**: surface the converters in the editor command palette - **Sharing**: hash-based shareable URLs (`#data=...`) for sample inputs (privacy: opt-in only) -These are deliberately deferred — Phase 1–3 first. +These are deliberately deferred — Phase 1–5 first. --- diff --git a/knip.json b/knip.json new file mode 100644 index 0000000..0defc80 --- /dev/null +++ b/knip.json @@ -0,0 +1,15 @@ +{ + "project": ["src/**/*.{ts,tsx}"], + "ignore": ["src/components/ui/**"], + "ignoreDependencies": [ + "@radix-ui/react-slot", + "tailwindcss", + "tw-animate-css", + "@tauri-apps/plugin-os", + "@tauri-apps/plugin-shell", + "@testing-library/user-event" + ], + "rules": { + "types": "off" + } +} diff --git a/package-lock.json b/package-lock.json index fe29bc1..6ca7521 100644 --- a/package-lock.json +++ b/package-lock.json @@ -69,7 +69,9 @@ "eslint": "^9.15.0", "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.0", + "globals": "^14.0.0", "jsdom": "^29.0.0", + "knip": "^6.14.1", "prettier": "^3.4.0", "prettier-plugin-tailwindcss": "^0.6.0", "tailwindcss": "^4.0.0", @@ -1130,6 +1132,372 @@ ], "license": "MIT" }, + "node_modules/@oxc-parser/binding-android-arm-eabi": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-android-arm-eabi/-/binding-android-arm-eabi-0.130.0.tgz", + "integrity": "sha512-h/xYU8/7ADWzVSf5I+YalLpj33LOy9CI/zgbJNIZ5eunRBG+Czqa3lZsvuPHHf3rOt6z1c5+UzoxjbAzAvhwVw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-android-arm64": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-android-arm64/-/binding-android-arm64-0.130.0.tgz", + "integrity": "sha512-oFWFJrsGv9siFM4HjMqKNB7IuIZD/SMmZdCXl8xyx7lDplGvPKyewpOo272rSWgMXe2Wx7bWI0Yj+gkHv4qbeg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-darwin-arm64": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-darwin-arm64/-/binding-darwin-arm64-0.130.0.tgz", + "integrity": "sha512-sGUzupdTplK9jQg7eJZ878HfEgQjJNBc6dAYVWJ9W5aU+J8rLfRJhTVsKThiu1pNwm6Y1qKCcbC6WhNWSXR3Ig==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-darwin-x64": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-darwin-x64/-/binding-darwin-x64-0.130.0.tgz", + "integrity": "sha512-PsB4cdCISbC00Uy8eiD8bc2AkGWjZqrSrJnkBFuG2ptrrf6mZ2F5gLFSjOAVMMgZPg8B1D7OydJwLWSfyI2Plg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-freebsd-x64": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-freebsd-x64/-/binding-freebsd-x64-0.130.0.tgz", + "integrity": "sha512-DgABp3l38hS77JbXCV4qk1+n6DPym5u8zzwuweokezm2tX194nDSJDENbDRECxVsiNbprKATLbk+Z5wlHT0OHw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-arm-gnueabihf": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-0.130.0.tgz", + "integrity": "sha512-4Kn3CTEmwFrzhTSC/JuUW16qovmaMdX7jeSKbL8w0pLtLww7To1a2XJi9Z5uD8QWUkfUHhqfV+VD6dVzBnWzoA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-arm-musleabihf": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-arm-musleabihf/-/binding-linux-arm-musleabihf-0.130.0.tgz", + "integrity": "sha512-D35KZM3F4rRu1uAFKyBlg3Gaf/ybCjyaPR1hfgvk5ex8NtcTmRgc0JgSighEyNg96TPrFhemFba68SZuxaha8w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-arm64-gnu": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-0.130.0.tgz", + "integrity": "sha512-Q9o7oVlo955KHwS8l1u0bCzIx+JsZUA3XToLXC+MsMhye/9LeBQbt84nh120cl2XLy+TEzvugYDiHShg5yaX6Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-arm64-musl": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-arm64-musl/-/binding-linux-arm64-musl-0.130.0.tgz", + "integrity": "sha512-EiJ/gC0ljbcwVpycC8YWw6ggMbtsPX8XMOt0mPx0aqWeMsNR+L9m05Flbvd5T+GlivG+GkSWQL7tM9SRFpM/dw==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-ppc64-gnu": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-0.130.0.tgz", + "integrity": "sha512-b+h/lsLLurp756dMGizNs5uPaJfyEdWrTcV5t8M609jWm1DEHB1StpRXCkyvwtkJx3m+qL5BNQ0dEKan/4yGFA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-riscv64-gnu": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-0.130.0.tgz", + "integrity": "sha512-O19Cil83XAyjEFfo8WhkMwY58ALqZ7ckjGL+25mjMIuF84urWBeANH0FC8B8BsSSygWU3/1aY3ADdDbp+wlBnw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-riscv64-musl": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-0.130.0.tgz", + "integrity": "sha512-BgXRVC0+83n3YzCscLQjj6nbyeBIVeZYPTI4fFMAE4WNm2+4RXhWp03IVizL7esIz36kgmT48aebk1iM+cs8sw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-s390x-gnu": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-0.130.0.tgz", + "integrity": "sha512-6tJz0xvnGhsokE7N1WlUSBXibpYmT9xSJFS1Ce41Km/+8gQvdlW8MLhRv8PD0L7ix8vRG0FDDepp3jdOFzdVdw==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-x64-gnu": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-x64-gnu/-/binding-linux-x64-gnu-0.130.0.tgz", + "integrity": "sha512-9aCWj83dp3heTQGmGnZGdIWgxjZrr/7VQ0TGFHH5PKByxJKF2Hcr4qvaSUHhhGEa3MSsDjTL1YDP8RAgdL5/Cg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-linux-x64-musl": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-linux-x64-musl/-/binding-linux-x64-musl-0.130.0.tgz", + "integrity": "sha512-afXt87aZBqrUVli8TB/I8H1G50RDWcwirjWtXGXYqJ2ZqWEiErH7V72j3LUSDZaivmtu2OLX0KQ/mbhP81mr7A==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-openharmony-arm64": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-openharmony-arm64/-/binding-openharmony-arm64-0.130.0.tgz", + "integrity": "sha512-I0NCrZV/YZuCGWgqwNN/GO/iXlLF2z+Wgc7u+Aa9N4P51oYeIa0XT+zVBUne4csO9GqxskXgI4g8JzzWGRpfOw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-wasm32-wasi": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-wasm32-wasi/-/binding-wasm32-wasi-0.130.0.tgz", + "integrity": "sha512-sJgQkGaBX0WJvPUDfwciex6IcTk5O5NLQ1bhEb6f3nBruh1GshKMRSMt2bxZlYrgBzjyBbJzsnO+InPG0bg+fA==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/core": "1.10.0", + "@emnapi/runtime": "1.10.0", + "@napi-rs/wasm-runtime": "^1.1.4" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-win32-arm64-msvc": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-0.130.0.tgz", + "integrity": "sha512-bjcma99sQrNh6RY4mPO9yTkfxql6TDFoN3HWdK31RCKXwNhcDgJXW/l8PUtzKNiQ+9vpKJfJtQq+LklBuxSOBA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-win32-ia32-msvc": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-0.130.0.tgz", + "integrity": "sha512-hRYbv6HhpSTzT4xTiIkadLI7upLQxuOdLPR/9nL1fTjwhgutBTPXrwaAPb/jTFVx6/8C7Jb5HcUKhmNwloTbFA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@oxc-parser/binding-win32-x64-msvc": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-parser/binding-win32-x64-msvc/-/binding-win32-x64-msvc-0.130.0.tgz", + "integrity": "sha512-RBpA9TsRucJq6HNVNCFF1iKg+QeTkLdZf7hi4xaOGCPvMZWvDHjQgSOEZMUpuW4JNciHbxNhLEYmz5CVygjVGQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, "node_modules/@oxc-project/types": { "version": "0.129.0", "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.129.0.tgz", @@ -1140,6 +1508,313 @@ "url": "https://github.com/sponsors/Boshen" } }, + "node_modules/@oxc-resolver/binding-android-arm-eabi": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-android-arm-eabi/-/binding-android-arm-eabi-11.19.1.tgz", + "integrity": "sha512-aUs47y+xyXHUKlbhqHUjBABjvycq6YSD7bpxSW7vplUmdzAlJ93yXY6ZR0c1o1x5A/QKbENCvs3+NlY8IpIVzg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@oxc-resolver/binding-android-arm64": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-android-arm64/-/binding-android-arm64-11.19.1.tgz", + "integrity": "sha512-oolbkRX+m7Pq2LNjr/kKgYeC7bRDMVTWPgxBGMjSpZi/+UskVo4jsMU3MLheZV55jL6c3rNelPl4oD60ggYmqA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@oxc-resolver/binding-darwin-arm64": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-darwin-arm64/-/binding-darwin-arm64-11.19.1.tgz", + "integrity": "sha512-nUC6d2i3R5B12sUW4O646qD5cnMXf2oBGPLIIeaRfU9doJRORAbE2SGv4eW6rMqhD+G7nf2Y8TTJTLiiO3Q/dQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@oxc-resolver/binding-darwin-x64": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-darwin-x64/-/binding-darwin-x64-11.19.1.tgz", + "integrity": "sha512-cV50vE5+uAgNcFa3QY1JOeKDSkM/9ReIcc/9wn4TavhW/itkDGrXhw9jaKnkQnGbjJ198Yh5nbX/Gr2mr4Z5jQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@oxc-resolver/binding-freebsd-x64": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-freebsd-x64/-/binding-freebsd-x64-11.19.1.tgz", + "integrity": "sha512-xZOQiYGFxtk48PBKff+Zwoym7ScPAIVp4c14lfLxizO2LTTTJe5sx9vQNGrBymrf/vatSPNMD4FgsaaRigPkqw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@oxc-resolver/binding-linux-arm-gnueabihf": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-11.19.1.tgz", + "integrity": "sha512-lXZYWAC6kaGe/ky2su94e9jN9t6M0/6c+GrSlCqL//XO1cxi5lpAhnJYdyrKfm0ZEr/c7RNyAx3P7FSBcBd5+A==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-arm-musleabihf": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-arm-musleabihf/-/binding-linux-arm-musleabihf-11.19.1.tgz", + "integrity": "sha512-veG1kKsuK5+t2IsO9q0DErYVSw2azvCVvWHnfTOS73WE0STdLLB7Q1bB9WR+yHPQM76ASkFyRbogWo1GR1+WbQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-arm64-gnu": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-11.19.1.tgz", + "integrity": "sha512-heV2+jmXyYnUrpUXSPugqWDRpnsQcDm2AX4wzTuvgdlZfoNYO0O3W2AVpJYaDn9AG4JdM6Kxom8+foE7/BcSig==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-arm64-musl": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-arm64-musl/-/binding-linux-arm64-musl-11.19.1.tgz", + "integrity": "sha512-jvo2Pjs1c9KPxMuMPIeQsgu0mOJF9rEb3y3TdpsrqwxRM+AN6/nDDwv45n5ZrUnQMsdBy5gIabioMKnQfWo9ew==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-ppc64-gnu": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-11.19.1.tgz", + "integrity": "sha512-vLmdNxWCdN7Uo5suays6A/+ywBby2PWBBPXctWPg5V0+eVuzsJxgAn6MMB4mPlshskYbppjpN2Zg83ArHze9gQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-riscv64-gnu": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-11.19.1.tgz", + "integrity": "sha512-/b+WgR+VTSBxzgOhDO7TlMXC1ufPIMR6Vj1zN+/x+MnyXGW7prTLzU9eW85Aj7Th7CCEG9ArCbTeqxCzFWdg2w==", + "cpu": [ + "riscv64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-riscv64-musl": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-11.19.1.tgz", + "integrity": "sha512-YlRdeWb9j42p29ROh+h4eg/OQ3dTJlpHSa+84pUM9+p6i3djtPz1q55yLJhgW9XfDch7FN1pQ/Vd6YP+xfRIuw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-s390x-gnu": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-11.19.1.tgz", + "integrity": "sha512-EDpafVOQWF8/MJynsjOGFThcqhRHy417sRyLfQmeiamJ8qVhSKAn2Dn2VVKUGCjVB9C46VGjhNo7nOPUi1x6uA==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-x64-gnu": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-x64-gnu/-/binding-linux-x64-gnu-11.19.1.tgz", + "integrity": "sha512-NxjZe+rqWhr+RT8/Ik+5ptA3oz7tUw361Wa5RWQXKnfqwSSHdHyrw6IdcTfYuml9dM856AlKWZIUXDmA9kkiBQ==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-linux-x64-musl": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-linux-x64-musl/-/binding-linux-x64-musl-11.19.1.tgz", + "integrity": "sha512-cM/hQwsO3ReJg5kR+SpI69DMfvNCp+A/eVR4b4YClE5bVZwz8rh2Nh05InhwI5HR/9cArbEkzMjcKgTHS6UaNw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxc-resolver/binding-openharmony-arm64": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-openharmony-arm64/-/binding-openharmony-arm64-11.19.1.tgz", + "integrity": "sha512-QF080IowFB0+9Rh6RcD19bdgh49BpQHUW5TajG1qvWHvmrQznTZZjYlgE2ltLXyKY+qs4F/v5xuX1XS7Is+3qA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@oxc-resolver/binding-wasm32-wasi": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-wasm32-wasi/-/binding-wasm32-wasi-11.19.1.tgz", + "integrity": "sha512-w8UCKhX826cP/ZLokXDS6+milN8y4X7zidsAttEdWlVoamTNf6lhBJldaWr3ukTDiye7s4HRcuPEPOXNC432Vg==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@napi-rs/wasm-runtime": "^1.1.1" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@oxc-resolver/binding-win32-arm64-msvc": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-11.19.1.tgz", + "integrity": "sha512-nJ4AsUVZrVKwnU/QRdzPCCrO0TrabBqgJ8pJhXITdZGYOV28TIYystV1VFLbQ7DtAcaBHpocT5/ZJnF78YJPtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@oxc-resolver/binding-win32-ia32-msvc": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-11.19.1.tgz", + "integrity": "sha512-EW+ND5q2Tl+a3pH81l1QbfgbF3HmqgwLfDfVithRFheac8OTcnbXt/JxqD2GbDkb7xYEqy1zNaVFRr3oeG8npA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@oxc-resolver/binding-win32-x64-msvc": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/@oxc-resolver/binding-win32-x64-msvc/-/binding-win32-x64-msvc-11.19.1.tgz", + "integrity": "sha512-6hIU3RQu45B+VNTY4Ru8ppFwjVS/S5qwYyGhBotmjxfEKk41I2DlGtRfGJndZ5+6lneE2pwloqunlOyZuX/XAw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@radix-ui/primitive": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.3.tgz", @@ -3999,6 +4674,16 @@ "fxparser": "src/cli/cli.js" } }, + "node_modules/fd-package-json": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fd-package-json/-/fd-package-json-2.0.0.tgz", + "integrity": "sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "walk-up-path": "^4.0.0" + } + }, "node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", @@ -4086,6 +4771,22 @@ "dev": true, "license": "ISC" }, + "node_modules/formatly": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/formatly/-/formatly-0.3.0.tgz", + "integrity": "sha512-9XNj/o4wrRFyhSMJOvsuyMwy8aUfBaZ1VrqHVfohyXf0Sw0e+yfKG+xZaY3arGCOMdwFsqObtzVOc1gU9KiT9w==", + "dev": true, + "license": "MIT", + "dependencies": { + "fd-package-json": "^2.0.0" + }, + "bin": { + "formatly": "bin/index.mjs" + }, + "engines": { + "node": ">=18.3.0" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -4110,6 +4811,19 @@ "node": ">=6" } }, + "node_modules/get-tsconfig": { + "version": "4.14.0", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.14.0.tgz", + "integrity": "sha512-yTb+8DXzDREzgvYmh6s9vHsSVCHeC0G3PI5bEXNBHtmshPnO+S5O7qgLEOn0I5QvMy6kpZN8K1NKGyilLb93wA==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -4447,6 +5161,59 @@ "json-buffer": "3.0.1" } }, + "node_modules/knip": { + "version": "6.14.1", + "resolved": "https://registry.npmjs.org/knip/-/knip-6.14.1.tgz", + "integrity": "sha512-SN3Ly0ixzj5CQkY/rc4OPHpWrCC0XRIIjgdP76G9Cni5k72ur5jBYOyvJuF5oPTM14v8eHcMUgPbElHa+lnR0g==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/webpro" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/knip" + } + ], + "license": "ISC", + "dependencies": { + "fdir": "^6.5.0", + "formatly": "^0.3.0", + "get-tsconfig": "4.14.0", + "jiti": "^2.7.0", + "minimist": "^1.2.8", + "oxc-parser": "^0.130.0", + "oxc-resolver": "^11.19.1", + "picomatch": "^4.0.4", + "smol-toml": "^1.6.1", + "strip-json-comments": "5.0.3", + "tinyglobby": "^0.2.16", + "unbash": "^3.0.0", + "yaml": "^2.9.0", + "zod": "^4.1.11" + }, + "bin": { + "knip": "bin/knip.js", + "knip-bun": "bin/knip-bun.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/knip/node_modules/strip-json-comments": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-5.0.3.tgz", + "integrity": "sha512-1tB5mhVo7U+ETBKNf92xT4hrQa3pm0MZ0PQvuDnWgAAGHDsfp4lPSpiS6psrSiet87wyGPh9ft6wmhOMQ0hDiw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -4870,6 +5637,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -4956,6 +5733,86 @@ "node": ">= 0.8.0" } }, + "node_modules/oxc-parser": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/oxc-parser/-/oxc-parser-0.130.0.tgz", + "integrity": "sha512-X0PJ+NmOok8qP3vK9uaW431ngkdM9UPEK7KG466urtIL2+EYTEgbZK2yqe2MWKJKBjRlFweP/pJPx0x9muMEVw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "^0.130.0" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/sponsors/Boshen" + }, + "optionalDependencies": { + "@oxc-parser/binding-android-arm-eabi": "0.130.0", + "@oxc-parser/binding-android-arm64": "0.130.0", + "@oxc-parser/binding-darwin-arm64": "0.130.0", + "@oxc-parser/binding-darwin-x64": "0.130.0", + "@oxc-parser/binding-freebsd-x64": "0.130.0", + "@oxc-parser/binding-linux-arm-gnueabihf": "0.130.0", + "@oxc-parser/binding-linux-arm-musleabihf": "0.130.0", + "@oxc-parser/binding-linux-arm64-gnu": "0.130.0", + "@oxc-parser/binding-linux-arm64-musl": "0.130.0", + "@oxc-parser/binding-linux-ppc64-gnu": "0.130.0", + "@oxc-parser/binding-linux-riscv64-gnu": "0.130.0", + "@oxc-parser/binding-linux-riscv64-musl": "0.130.0", + "@oxc-parser/binding-linux-s390x-gnu": "0.130.0", + "@oxc-parser/binding-linux-x64-gnu": "0.130.0", + "@oxc-parser/binding-linux-x64-musl": "0.130.0", + "@oxc-parser/binding-openharmony-arm64": "0.130.0", + "@oxc-parser/binding-wasm32-wasi": "0.130.0", + "@oxc-parser/binding-win32-arm64-msvc": "0.130.0", + "@oxc-parser/binding-win32-ia32-msvc": "0.130.0", + "@oxc-parser/binding-win32-x64-msvc": "0.130.0" + } + }, + "node_modules/oxc-parser/node_modules/@oxc-project/types": { + "version": "0.130.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.130.0.tgz", + "integrity": "sha512-ibD2usx9JRu7f5pu2tMKMI4cpA4NgXJQoYRP4pQ7Pxmn1l6k/53qWtQWZayhYy3X4QZkt90Ot+mJEaeXouio6Q==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/Boshen" + } + }, + "node_modules/oxc-resolver": { + "version": "11.19.1", + "resolved": "https://registry.npmjs.org/oxc-resolver/-/oxc-resolver-11.19.1.tgz", + "integrity": "sha512-qE/CIg/spwrTBFt5aKmwe3ifeDdLfA2NESN30E42X/lII5ClF8V7Wt6WIJhcGZjp0/Q+nQ+9vgxGk//xZNX2hg==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/Boshen" + }, + "optionalDependencies": { + "@oxc-resolver/binding-android-arm-eabi": "11.19.1", + "@oxc-resolver/binding-android-arm64": "11.19.1", + "@oxc-resolver/binding-darwin-arm64": "11.19.1", + "@oxc-resolver/binding-darwin-x64": "11.19.1", + "@oxc-resolver/binding-freebsd-x64": "11.19.1", + "@oxc-resolver/binding-linux-arm-gnueabihf": "11.19.1", + "@oxc-resolver/binding-linux-arm-musleabihf": "11.19.1", + "@oxc-resolver/binding-linux-arm64-gnu": "11.19.1", + "@oxc-resolver/binding-linux-arm64-musl": "11.19.1", + "@oxc-resolver/binding-linux-ppc64-gnu": "11.19.1", + "@oxc-resolver/binding-linux-riscv64-gnu": "11.19.1", + "@oxc-resolver/binding-linux-riscv64-musl": "11.19.1", + "@oxc-resolver/binding-linux-s390x-gnu": "11.19.1", + "@oxc-resolver/binding-linux-x64-gnu": "11.19.1", + "@oxc-resolver/binding-linux-x64-musl": "11.19.1", + "@oxc-resolver/binding-openharmony-arm64": "11.19.1", + "@oxc-resolver/binding-wasm32-wasi": "11.19.1", + "@oxc-resolver/binding-win32-arm64-msvc": "11.19.1", + "@oxc-resolver/binding-win32-ia32-msvc": "11.19.1", + "@oxc-resolver/binding-win32-x64-msvc": "11.19.1" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -5494,6 +6351,16 @@ "node": ">=4" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/rolldown": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.0.0.tgz", @@ -5901,6 +6768,16 @@ "typescript": ">=4.8.4 <6.1.0" } }, + "node_modules/unbash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/unbash/-/unbash-3.0.0.tgz", + "integrity": "sha512-FeFPZ/WFT0mbRCuydiZzpPFlrYN8ZUpphQKoq4EeElVIYjYyGzPMxQR/simUwCOJIyVhpFk4RbtyO7RuMpMnHA==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=14" + } + }, "node_modules/undici": { "version": "7.25.0", "resolved": "https://registry.npmjs.org/undici/-/undici-7.25.0.tgz", @@ -6167,6 +7044,16 @@ "node": ">=18" } }, + "node_modules/walk-up-path": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/walk-up-path/-/walk-up-path-4.0.0.tgz", + "integrity": "sha512-3hu+tD8YzSLGuFYtPRb48vdhKMi0KQV5sn+uWr8+7dMEq/2G/dtLrdDinkLjqq5TIbIBjYJ4Ax/n3YiaW7QM8A==", + "dev": true, + "license": "ISC", + "engines": { + "node": "20 || >=22" + } + }, "node_modules/webidl-conversions": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-8.0.1.tgz", @@ -6277,6 +7164,22 @@ "dev": true, "license": "MIT" }, + "node_modules/yaml": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz", + "integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==", + "dev": true, + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -6290,6 +7193,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/zod": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", + "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, "node_modules/zustand": { "version": "5.0.13", "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.13.tgz", diff --git a/package.json b/package.json index f404c41..03f3e0d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jsonprism", "private": true, - "version": "1.4.3", + "version": "1.5.0", "type": "module", "description": "Disperse JSON into many formats — JSONL, CSV, YAML, XML, TOML, RESX, Markdown, SQL — fully client-side.", "author": "poli0981 ", @@ -20,6 +20,7 @@ "preview": "vite preview", "lint": "eslint .", "lint:fix": "eslint . --fix", + "knip": "knip", "format": "prettier --write \"src/**/*.{ts,tsx,css,md,json}\"", "format:check": "prettier --check \"src/**/*.{ts,tsx,css,md,json}\"", "typecheck": "tsc -b --noEmit", @@ -93,7 +94,9 @@ "eslint": "^9.15.0", "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.0", + "globals": "^14.0.0", "jsdom": "^29.0.0", + "knip": "^6.14.1", "prettier": "^3.4.0", "prettier-plugin-tailwindcss": "^0.6.0", "tailwindcss": "^4.0.0", diff --git a/src/components/common/ScrollToTop.tsx b/src/components/common/ScrollToTop.tsx new file mode 100644 index 0000000..4f77d4a --- /dev/null +++ b/src/components/common/ScrollToTop.tsx @@ -0,0 +1,51 @@ +import { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { ArrowUp } from 'lucide-react'; +import { cn } from '@/lib/utils'; + +interface ScrollToTopProps { + /** The scroll container to watch and scroll back to top. */ + scrollRef: React.RefObject; + /** Reveal the button once the container is scrolled past this many pixels. */ + threshold?: number; +} + +export function ScrollToTop({ scrollRef, threshold = 320 }: ScrollToTopProps) { + const { t } = useTranslation(); + const [visible, setVisible] = useState(false); + + useEffect(() => { + const el = scrollRef.current; + if (!el) return; + const onScroll = () => setVisible(el.scrollTop > threshold); + onScroll(); + el.addEventListener('scroll', onScroll, { passive: true }); + return () => el.removeEventListener('scroll', onScroll); + }, [scrollRef, threshold]); + + const handleClick = () => { + const el = scrollRef.current; + if (!el) return; + const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; + el.scrollTo({ top: 0, behavior: reduceMotion ? 'auto' : 'smooth' }); + }; + + return ( + + ); +} diff --git a/src/components/common/ToolbarButton.tsx b/src/components/common/ToolbarButton.tsx new file mode 100644 index 0000000..8f009c1 --- /dev/null +++ b/src/components/common/ToolbarButton.tsx @@ -0,0 +1,22 @@ +interface ToolbarButtonProps { + onClick: () => void; + label: string; + icon: React.ReactNode; + disabled?: boolean; +} + +export function ToolbarButton({ onClick, label, icon, disabled }: ToolbarButtonProps) { + return ( + + ); +} diff --git a/src/components/converter/BatchItemRow.tsx b/src/components/converter/BatchItemRow.tsx new file mode 100644 index 0000000..8111e11 --- /dev/null +++ b/src/components/converter/BatchItemRow.tsx @@ -0,0 +1,114 @@ +import { useTranslation } from 'react-i18next'; +import { Loader2, Trash2 } from 'lucide-react'; +import { cn } from '@/lib/utils'; +import { formatBytes } from '@/lib/format-bytes'; +import type { BatchItem } from '@/stores/batchStore'; + +interface BatchItemRowProps { + item: BatchItem; + outputExt: string; + onRemove: () => void; + disabled: boolean; +} + +export function BatchItemRow({ item, outputExt, onRemove, disabled }: BatchItemRowProps) { + const { t } = useTranslation(); + const Icon = statusIcon(item.status); + const tone = statusTone(item.status); + + return ( +
  • + +
    +
    + {item.filename} + → .{outputExt} +
    +
    + {formatBytes(item.size)} + {item.outputSize !== undefined && ( + <> + · + + {t('batch.row.out')}: {formatBytes(item.outputSize)} + + + )} +
    + {item.error && ( +

    {item.error}

    + )} +
    + +
  • + ); +} + +function statusIcon(status: BatchItem['status']) { + switch (status) { + case 'queued': + return CircleIcon; + case 'processing': + return ProcessingIcon; + case 'done': + return CheckIcon; + case 'error': + return ErrorIcon; + } +} + +function statusTone(status: BatchItem['status']): string { + switch (status) { + case 'done': + return 'text-primary'; + case 'error': + return 'text-destructive'; + case 'processing': + return 'text-foreground'; + case 'queued': + default: + return 'text-muted-foreground/60'; + } +} + +function CircleIcon({ className }: { className?: string }) { + return ( + + + + ); +} + +function ProcessingIcon({ className }: { className?: string }) { + return ; +} + +function CheckIcon({ className }: { className?: string }) { + return ( + + + + ); +} + +function ErrorIcon({ className }: { className?: string }) { + return ( + + + + ); +} diff --git a/src/components/converter/BatchPanel.tsx b/src/components/converter/BatchPanel.tsx index 5dc2b09..1d402f0 100644 --- a/src/components/converter/BatchPanel.tsx +++ b/src/components/converter/BatchPanel.tsx @@ -1,7 +1,7 @@ -import { useCallback, useEffect, useMemo, useRef } from 'react'; +import { useCallback, useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { useDropzone } from 'react-dropzone'; -import { Download, FileStack, FolderOpen, Loader2, Play, StopCircle, Trash2 } from 'lucide-react'; +import { Download, FileStack, FolderOpen, Play, StopCircle, Trash2 } from 'lucide-react'; import { Sheet, SheetContent, @@ -11,14 +11,16 @@ import { SheetTrigger, } from '@/components/ui/sheet'; import { toast } from '@/components/ui/sonner'; -import { useBatchStore, BATCH_MAX_FILES, type BatchItem } from '@/stores/batchStore'; -import { processBatch, zipOutputs, downloadBlob } from '@/lib/batch-processor'; -import { filterByExtension, getAllowedExtensions } from '@/lib/file-filter'; -import { isTauri, nativeOpenFiles, nativeSaveBlob, fileFromNativePath } from '@/lib/tauri'; -import { getConverter } from '@/converters/registry'; -import type { FormatId } from '@/converters/types'; +import { useBatchActions } from '@/hooks/useBatchActions'; +import { useFileAccept } from '@/hooks/useFileAccept'; +import { filterByExtension } from '@/lib/file-filter'; +import { isTauri, nativeOpenFiles, fileFromNativePath } from '@/lib/tauri'; import { cn } from '@/lib/utils'; +import { useBatchStore, BATCH_MAX_FILES } from '@/stores/batchStore'; +import type { FormatId } from '@/converters/types'; import type { Direction } from './DirectionToggle'; +import { BatchItemRow } from './BatchItemRow'; +import { BatchSummaryChips } from './BatchSummaryChips'; interface BatchPanelProps { format: FormatId; @@ -26,8 +28,6 @@ interface BatchPanelProps { options: Record; open: boolean; onOpenChange: (open: boolean) => void; - /** Filenames added via this trigger button are also routed into the queue. */ - onAddExternalFiles?: (files: File[]) => void; } export function BatchPanel({ format, direction, options, open, onOpenChange }: BatchPanelProps) { @@ -38,9 +38,6 @@ export function BatchPanel({ format, direction, options, open, onOpenChange }: B const addFiles = useBatchStore((s) => s.addFiles); const removeItem = useBatchStore((s) => s.removeItem); const clear = useBatchStore((s) => s.clear); - const setProcessing = useBatchStore((s) => s.setProcessing); - const setAbortController = useBatchStore((s) => s.setAbortController); - const updateItem = useBatchStore((s) => s.updateItem); const resetStatuses = useBatchStore((s) => s.resetStatuses); const fileInputRef = useRef(null); @@ -50,29 +47,11 @@ export function BatchPanel({ format, direction, options, open, onOpenChange }: B const errorCount = itemOrder.filter((id) => items[id]?.status === 'error').length; const queuedCount = itemOrder.filter((id) => items[id]?.status === 'queued').length; - const isReverse = direction === 'reverse'; - const converter = getConverter(format); - const accept = useMemo(() => { - if (isReverse) { - return { - [converter.meta.mimeType]: [`.${converter.meta.extension}`], - 'text/plain': ['.txt'], - }; - } - return { 'application/json': ['.json'], 'text/plain': ['.txt'] }; - }, [isReverse, converter.meta.mimeType, converter.meta.extension]); - - const fileInputAccept = isReverse - ? `.${converter.meta.extension},.txt,${converter.meta.mimeType}` - : '.json,.txt,application/json'; - - // Whitelist of file extensions that match the current direction × format. - // The browser's native `` is only a hint, so we re-validate - // in JS to reject files chosen via "Browse" with "All files" filter. - const allowedExtensions = useMemo( - () => getAllowedExtensions(isReverse ? 'reverse' : 'forward', converter.meta.extension), - [isReverse, converter.meta.extension], + const { converter, isReverse, accept, fileInputAccept, allowedExtensions } = useFileAccept( + format, + direction, ); + const { start, cancel, downloadZip } = useBatchActions(format, direction, options); const handleAddFiles = useCallback( (files: File[]) => { @@ -124,78 +103,6 @@ export function BatchPanel({ format, direction, options, open, onOpenChange }: B noKeyboard: true, }); - const handleStart = useCallback(async () => { - const queued = itemOrder - .map((id) => items[id]) - .filter((it): it is BatchItem => !!it && it.status !== 'done' && it.status !== 'processing'); - - if (queued.length === 0) { - toast.info(t('batch.toast.nothing_to_process')); - return; - } - - const controller = new AbortController(); - setAbortController(controller); - setProcessing(true); - toast.success(t('batch.toast.started', { count: queued.length })); - - try { - await processBatch( - queued, - format, - options, - { - onUpdate: (id, patch) => updateItem(id, patch), - }, - controller.signal, - direction, - ); - if (!controller.signal.aborted) { - toast.success(t('batch.toast.finished')); - } - } catch (err) { - toast.error(t('batch.toast.failed', { message: (err as Error).message })); - } finally { - setProcessing(false); - setAbortController(null); - } - }, [ - direction, - format, - items, - itemOrder, - options, - setAbortController, - setProcessing, - t, - updateItem, - ]); - - const handleCancel = useCallback(() => { - useBatchStore.getState().abortController?.abort(); - toast.info(t('batch.toast.cancelled')); - }, [t]); - - const handleDownloadZip = useCallback(async () => { - const done = itemOrder.map((id) => items[id]).filter((it): it is BatchItem => !!it); - try { - const { blob, fileCount } = await zipOutputs(done, format, direction); - const ts = new Date().toISOString().slice(0, 10); - const filename = `jsonprism-batch-${ts}.zip`; - if (isTauri()) { - const saved = await nativeSaveBlob(blob, filename); - if (saved) { - toast.success(t('batch.toast.zipped', { count: fileCount })); - } - } else { - downloadBlob(blob, filename); - toast.success(t('batch.toast.zipped', { count: fileCount })); - } - } catch (err) { - toast.error(t('batch.toast.zip_failed', { message: (err as Error).message })); - } - }, [direction, format, items, itemOrder, t]); - const handleOpenFiles = async () => { if (isTauri()) { const paths = await nativeOpenFiles({ multiple: true }); @@ -296,13 +203,11 @@ export function BatchPanel({ format, direction, options, open, onOpenChange }: B {/* Summary chips */} {totalCount > 0 && ( -
    - - - {errorCount > 0 && ( - - )} -
    + )} {/* Queue list */} @@ -346,7 +251,7 @@ export function BatchPanel({ format, direction, options, open, onOpenChange }: B {processing ? ( - - ); -} - -function statusIcon(status: BatchItem['status']) { - switch (status) { - case 'queued': - return CircleIcon; - case 'processing': - return ProcessingIcon; - case 'done': - return CheckIcon; - case 'error': - return ErrorIcon; - } -} - -function statusTone(status: BatchItem['status']): string { - switch (status) { - case 'done': - return 'text-primary'; - case 'error': - return 'text-destructive'; - case 'processing': - return 'text-foreground'; - case 'queued': - default: - return 'text-muted-foreground/60'; - } -} - -function CircleIcon({ className }: { className?: string }) { - return ( - - - - ); -} - -function ProcessingIcon({ className }: { className?: string }) { - return ; -} - -function CheckIcon({ className }: { className?: string }) { - return ( - - - - ); -} - -function ErrorIcon({ className }: { className?: string }) { - return ( - - - - ); -} - -function formatBytes(bytes: number): string { - if (bytes < 1024) return `${bytes} B`; - if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; - return `${(bytes / 1024 / 1024).toFixed(2)} MB`; -} diff --git a/src/components/converter/BatchSummaryChips.tsx b/src/components/converter/BatchSummaryChips.tsx new file mode 100644 index 0000000..0689738 --- /dev/null +++ b/src/components/converter/BatchSummaryChips.tsx @@ -0,0 +1,35 @@ +import { useTranslation } from 'react-i18next'; +import { cn } from '@/lib/utils'; + +interface BatchSummaryChipsProps { + queuedCount: number; + doneCount: number; + errorCount: number; +} + +export function BatchSummaryChips({ queuedCount, doneCount, errorCount }: BatchSummaryChipsProps) { + const { t } = useTranslation(); + return ( +
    + + + {errorCount > 0 && } +
    + ); +} + +function Chip({ label, value, tone }: { label: string; value: number; tone?: 'ok' | 'err' }) { + return ( + + {label}: + {value} + + ); +} diff --git a/src/components/converter/ConverterWorkspace.tsx b/src/components/converter/ConverterWorkspace.tsx index 89eecb3..6cd485d 100644 --- a/src/components/converter/ConverterWorkspace.tsx +++ b/src/components/converter/ConverterWorkspace.tsx @@ -1,14 +1,13 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { useCallback, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { toast } from '@/components/ui/sonner'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; +import { useBatchFileRouter } from '@/hooks/useBatchFileRouter'; +import { useConversionResult } from '@/hooks/useConversionResult'; +import { useKeyboardShortcuts } from '@/hooks/useKeyboardShortcuts'; +import { useOutputBadge } from '@/hooks/useOutputBadge'; import { getConverter } from '@/converters/registry'; import type { FormatId } from '@/converters/types'; -import { parseJsonInput } from '@/lib/detect'; -import { filterByExtension, getAllowedExtensions } from '@/lib/file-filter'; -import { useKeyboardShortcuts } from '@/hooks/useKeyboardShortcuts'; -import { useTauriDragDrop } from '@/hooks/useTauriDragDrop'; -import { useBatchStore } from '@/stores/batchStore'; import { useWorkspaceStore } from '@/stores/workspaceStore'; import { DirectionToggle, type Direction } from './DirectionToggle'; import { FormatPicker } from './FormatPicker'; @@ -39,40 +38,9 @@ export function ConverterWorkspace() { const [settingsOpen, setSettingsOpen] = useState(false); // Mobile tab state — desktop ignores this and renders both panels side-by-side. const [activeTab, setActiveTab] = useState<'input' | 'output'>('input'); - // Badge dot on Output tab when output changes while user is on Input tab. - const [hasUnreadOutput, setHasUnreadOutput] = useState(false); - const prevOutputRef = useRef(''); - const addBatchFiles = useBatchStore((s) => s.addFiles); - const handleMultiFileDrop = useCallback( - (files: File[]) => { - const allowed = getAllowedExtensions( - direction === 'reverse' ? 'reverse' : 'forward', - getConverter(format).meta.extension, - ); - const { valid, wrongFormat } = filterByExtension(files, allowed); - if (wrongFormat > 0) { - toast.warning(t('batch.toast.wrong_format', { count: wrongFormat })); - } - if (valid.length === 0) return; - const result = addBatchFiles(valid); - if (result.added > 0) { - toast.success(t('batch.toast.added', { count: result.added })); - setBatchOpen(true); - } - if (result.skipped > 0) { - if (result.reason === 'duplicate') { - toast.warning(t('batch.toast.duplicate', { count: result.skipped })); - } else { - toast.warning(t('batch.toast.skipped', { count: result.skipped, max: 500 })); - } - } - }, - [addBatchFiles, direction, format, t], - ); - - // Native OS drag-drop bridge (no-op outside Tauri). - useTauriDragDrop(handleMultiFileDrop); + const openBatch = useCallback(() => setBatchOpen(true), []); + const handleMultiFileDrop = useBatchFileRouter(format, direction, openBatch); const switchFormat = useCallback( (next: FormatId) => { @@ -109,75 +77,12 @@ export function ConverterWorkspace() { toast.success(t('toast.options_reset')); }, [format, resetOptionsForFormat, t]); - const { output, inputError, outputError, shape, parseMs } = useMemo(() => { - const start = performance.now(); - if (!input.trim()) { - return { output: '', inputError: null, outputError: null, shape: null, parseMs: null }; - } - const converter = getConverter(format); - if (!converter.meta.ready) { - return { - output: '', - inputError: null, - outputError: t('errors.converter_not_ready_phase', { phase: converter.meta.phase }), - shape: null, - parseMs: performance.now() - start, - }; - } - - if (direction === 'reverse') { - if (typeof converter.reverse !== 'function') { - return { - output: '', - inputError: null, - outputError: t('format_status.no_reverse'), - shape: null, - parseMs: performance.now() - start, - }; - } - const result = converter.reverse( - { text: input }, - currentOptions as Parameters[1], - ); - const ms = performance.now() - start; - return result.ok - ? { output: result.output, inputError: null, outputError: null, shape: null, parseMs: ms } - : { output: '', inputError: result.error, outputError: null, shape: null, parseMs: ms }; - } - - const parsed = parseJsonInput(input); - if (!parsed.ok) { - const msg = parsed.error === 'empty' ? null : parsed.error; - return { - output: '', - inputError: msg, - outputError: null, - shape: null, - parseMs: performance.now() - start, - }; - } - const result = converter.convert( - { data: parsed.value, rawText: input }, - currentOptions as Parameters[1], - ); - const ms = performance.now() - start; - if (result.ok) { - return { - output: result.output, - inputError: null, - outputError: null, - shape: parsed.shape, - parseMs: ms, - }; - } - return { - output: '', - inputError: null, - outputError: result.error, - shape: parsed.shape, - parseMs: ms, - }; - }, [input, format, currentOptions, direction, t]); + const { output, inputError, outputError, shape, parseMs } = useConversionResult( + input, + format, + direction, + currentOptions, + ); useKeyboardShortcuts([ { key: 'k', mod: true, handler: () => setInput('') }, @@ -185,20 +90,7 @@ export function ConverterWorkspace() { { key: ',', mod: true, handler: () => setSettingsOpen((v) => !v) }, ]); - // Flip the badge dot on the Output tab whenever output changes while the - // user is on the Input tab. Clearing happens once the user navigates over. - useEffect(() => { - if (output !== prevOutputRef.current) { - prevOutputRef.current = output; - if (output && activeTab !== 'output') { - setHasUnreadOutput(true); - } - } - }, [output, activeTab]); - - useEffect(() => { - if (activeTab === 'output') setHasUnreadOutput(false); - }, [activeTab]); + const hasUnreadOutput = useOutputBadge(output, activeTab); const inputBytes = useMemo(() => new TextEncoder().encode(input).length, [input]); const outputBytes = useMemo(() => new TextEncoder().encode(output).length, [output]); diff --git a/src/components/converter/InputPanel.tsx b/src/components/converter/InputPanel.tsx index f28a02f..7d6702b 100644 --- a/src/components/converter/InputPanel.tsx +++ b/src/components/converter/InputPanel.tsx @@ -1,14 +1,17 @@ -import { useCallback, useMemo, useRef, useState } from 'react'; +import { useCallback, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useDropzone } from 'react-dropzone'; import { Eraser, FileText, FolderOpen } from 'lucide-react'; +import { ToolbarButton } from '@/components/common/ToolbarButton'; import { toast } from '@/components/ui/sonner'; -import { extOf, getAllowedExtensions } from '@/lib/file-filter'; +import { useFileAccept } from '@/hooks/useFileAccept'; +import { editorLanguageFor } from '@/lib/editor-language'; +import { extOf } from '@/lib/file-filter'; +import { readFileText } from '@/lib/read-file'; import { SAMPLE_JSON } from '@/lib/sample'; import { isTauri, nativeOpenFiles, fileFromNativePath } from '@/lib/tauri'; -import { getConverter } from '@/converters/registry'; import type { FormatId } from '@/converters/types'; -import { CodeEditor, type EditorLanguage } from './CodeEditor'; +import { CodeEditor } from './CodeEditor'; import type { Direction } from './DirectionToggle'; interface InputPanelProps { @@ -35,49 +38,16 @@ export function InputPanel({ const fileInputRef = useRef(null); const [dragActive, setDragActive] = useState(false); - const isReverse = direction === 'reverse'; - const converter = getConverter(format); - // In reverse mode the dropzone + file picker accept the format's native - // extension; in forward mode JSON is the only useful input. - const accept = useMemo(() => { - if (isReverse) { - const ext = converter.meta.extension; - return { - [converter.meta.mimeType]: [`.${ext}`], - 'text/plain': ['.txt'], - }; - } - return { 'application/json': ['.json'], 'text/plain': ['.txt'] }; - }, [isReverse, converter.meta.mimeType, converter.meta.extension]); - - const fileInputAccept = isReverse - ? `.${converter.meta.extension},.txt,${converter.meta.mimeType}` - : '.json,.txt,application/json'; + const { converter, isReverse, accept, fileInputAccept, allowedExtensions } = useFileAccept( + format, + direction, + ); const inputLabel = isReverse ? t('home.input_label_format', { format: t(converter.meta.labelKey) }) : t('home.input_label'); - // CodeMirror language pack to use for the input. In forward mode the input - // is always JSON. In reverse, pick the closest available pack — formats - // without an official CodeMirror grammar fall back to plain text. - const editorLanguage: EditorLanguage = useMemo(() => { - if (!isReverse) return 'json'; - if (format === 'yaml') return 'yaml'; - if (format === 'xml' || format === 'resx') return 'xml'; - if (format === 'jsonl') return 'json'; - if (format === 'markdown') return 'markdown'; - if (format === 'sql') return 'sql'; - if (format === 'toml') return 'toml'; - return 'plain'; - }, [isReverse, format]); - - // Allowed extensions for the single-file "Open" / drag-drop path. - // `` is only a hint to the OS picker — re-validate in JS. - const allowedExtensions = useMemo( - () => getAllowedExtensions(isReverse ? 'reverse' : 'forward', converter.meta.extension), - [isReverse, converter.meta.extension], - ); + const editorLanguage = editorLanguageFor(format, direction); const hasAllowedExt = useCallback( (name: string) => allowedExtensions.includes(extOf(name)), @@ -97,7 +67,7 @@ export function InputPanel({ toast.warning(t('batch.toast.wrong_format', { count: 1 })); return; } - void readFile(file).then( + void readFileText(file).then( (text) => { onChange(text); toast.success(t('toast.file_loaded', { name: file.name })); @@ -159,7 +129,7 @@ export function InputPanel({ e.target.value = ''; return; } - void readFile(file).then( + void readFileText(file).then( (text) => { onChange(text); toast.success(t('toast.file_loaded', { name: file.name })); @@ -244,35 +214,3 @@ export function InputPanel({ ); } - -async function readFile(file: File): Promise { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onload = () => resolve(String(reader.result ?? '')); - reader.onerror = () => reject(new Error(`Cannot read file: ${file.name}`)); - reader.readAsText(file); - }); -} - -interface ToolbarButtonProps { - onClick: () => void; - label: string; - icon: React.ReactNode; - disabled?: boolean; -} - -function ToolbarButton({ onClick, label, icon, disabled }: ToolbarButtonProps) { - return ( - - ); -} diff --git a/src/components/converter/OutputPanel.tsx b/src/components/converter/OutputPanel.tsx index 6ea3d96..6c6045d 100644 --- a/src/components/converter/OutputPanel.tsx +++ b/src/components/converter/OutputPanel.tsx @@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Check, Copy, Download } from 'lucide-react'; import { toast } from '@/components/ui/sonner'; +import { ToolbarButton } from '@/components/common/ToolbarButton'; import type { FormatId } from '@/converters/types'; import { getConverter } from '@/converters/registry'; import { decodeBytes } from '@/converters/bson'; @@ -120,26 +121,3 @@ export function OutputPanel({ ); } - -interface ToolbarButtonProps { - onClick: () => void; - label: string; - icon: React.ReactNode; - disabled?: boolean; -} - -function ToolbarButton({ onClick, label, icon, disabled }: ToolbarButtonProps) { - return ( - - ); -} diff --git a/src/hooks/useBatchActions.ts b/src/hooks/useBatchActions.ts new file mode 100644 index 0000000..89a047d --- /dev/null +++ b/src/hooks/useBatchActions.ts @@ -0,0 +1,95 @@ +import { useCallback } from 'react'; +import { useTranslation } from 'react-i18next'; +import { toast } from '@/components/ui/sonner'; +import type { Direction } from '@/components/converter/DirectionToggle'; +import type { FormatId } from '@/converters/types'; +import { downloadBlob, processBatch, zipOutputs } from '@/lib/batch-processor'; +import { isTauri, nativeSaveBlob } from '@/lib/tauri'; +import { useBatchStore, type BatchItem } from '@/stores/batchStore'; + +export function useBatchActions( + format: FormatId, + direction: Direction, + options: Record, +) { + const { t } = useTranslation(); + const items = useBatchStore((s) => s.items); + const itemOrder = useBatchStore((s) => s.itemOrder); + const setProcessing = useBatchStore((s) => s.setProcessing); + const setAbortController = useBatchStore((s) => s.setAbortController); + const updateItem = useBatchStore((s) => s.updateItem); + + const start = useCallback(async () => { + const queued = itemOrder + .map((id) => items[id]) + .filter((it): it is BatchItem => !!it && it.status !== 'done' && it.status !== 'processing'); + + if (queued.length === 0) { + toast.info(t('batch.toast.nothing_to_process')); + return; + } + + const controller = new AbortController(); + setAbortController(controller); + setProcessing(true); + toast.success(t('batch.toast.started', { count: queued.length })); + + try { + await processBatch( + queued, + format, + options, + { + onUpdate: (id, patch) => updateItem(id, patch), + }, + controller.signal, + direction, + ); + if (!controller.signal.aborted) { + toast.success(t('batch.toast.finished')); + } + } catch (err) { + toast.error(t('batch.toast.failed', { message: (err as Error).message })); + } finally { + setProcessing(false); + setAbortController(null); + } + }, [ + direction, + format, + items, + itemOrder, + options, + setAbortController, + setProcessing, + t, + updateItem, + ]); + + const cancel = useCallback(() => { + useBatchStore.getState().abortController?.abort(); + toast.info(t('batch.toast.cancelled')); + }, [t]); + + const downloadZip = useCallback(async () => { + const done = itemOrder.map((id) => items[id]).filter((it): it is BatchItem => !!it); + try { + const { blob, fileCount } = await zipOutputs(done, format, direction); + const ts = new Date().toISOString().slice(0, 10); + const filename = `jsonprism-batch-${ts}.zip`; + if (isTauri()) { + const saved = await nativeSaveBlob(blob, filename); + if (saved) { + toast.success(t('batch.toast.zipped', { count: fileCount })); + } + } else { + downloadBlob(blob, filename); + toast.success(t('batch.toast.zipped', { count: fileCount })); + } + } catch (err) { + toast.error(t('batch.toast.zip_failed', { message: (err as Error).message })); + } + }, [direction, format, items, itemOrder, t]); + + return { start, cancel, downloadZip }; +} diff --git a/src/hooks/useBatchFileRouter.ts b/src/hooks/useBatchFileRouter.ts new file mode 100644 index 0000000..dc62499 --- /dev/null +++ b/src/hooks/useBatchFileRouter.ts @@ -0,0 +1,52 @@ +import { useCallback } from 'react'; +import { useTranslation } from 'react-i18next'; +import { toast } from '@/components/ui/sonner'; +import type { Direction } from '@/components/converter/DirectionToggle'; +import { getConverter } from '@/converters/registry'; +import type { FormatId } from '@/converters/types'; +import { filterByExtension, getAllowedExtensions } from '@/lib/file-filter'; +import { useTauriDragDrop } from '@/hooks/useTauriDragDrop'; +import { useBatchStore } from '@/stores/batchStore'; + +// Routes a multi-file drop into the batch queue (with format filtering and +// toasts) and wires the native Tauri drag-drop bridge to the same handler. +export function useBatchFileRouter( + format: FormatId, + direction: Direction, + onFilesAdded?: () => void, +): (files: File[]) => void { + const { t } = useTranslation(); + const addBatchFiles = useBatchStore((s) => s.addFiles); + + const handleMultiFileDrop = useCallback( + (files: File[]) => { + const allowed = getAllowedExtensions( + direction === 'reverse' ? 'reverse' : 'forward', + getConverter(format).meta.extension, + ); + const { valid, wrongFormat } = filterByExtension(files, allowed); + if (wrongFormat > 0) { + toast.warning(t('batch.toast.wrong_format', { count: wrongFormat })); + } + if (valid.length === 0) return; + const result = addBatchFiles(valid); + if (result.added > 0) { + toast.success(t('batch.toast.added', { count: result.added })); + onFilesAdded?.(); + } + if (result.skipped > 0) { + if (result.reason === 'duplicate') { + toast.warning(t('batch.toast.duplicate', { count: result.skipped })); + } else { + toast.warning(t('batch.toast.skipped', { count: result.skipped, max: 500 })); + } + } + }, + [addBatchFiles, direction, format, t, onFilesAdded], + ); + + // Native OS drag-drop bridge (no-op outside Tauri). + useTauriDragDrop(handleMultiFileDrop); + + return handleMultiFileDrop; +} diff --git a/src/hooks/useConversionResult.ts b/src/hooks/useConversionResult.ts new file mode 100644 index 0000000..1702f6d --- /dev/null +++ b/src/hooks/useConversionResult.ts @@ -0,0 +1,85 @@ +import { useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; +import type { Direction } from '@/components/converter/DirectionToggle'; +import { getConverter } from '@/converters/registry'; +import type { FormatId } from '@/converters/types'; +import { parseJsonInput } from '@/lib/detect'; + +export function useConversionResult( + input: string, + format: FormatId, + direction: Direction, + options: Record, +) { + const { t } = useTranslation(); + + return useMemo(() => { + const start = performance.now(); + if (!input.trim()) { + return { output: '', inputError: null, outputError: null, shape: null, parseMs: null }; + } + const converter = getConverter(format); + if (!converter.meta.ready) { + return { + output: '', + inputError: null, + outputError: t('errors.converter_not_ready_phase', { phase: converter.meta.phase }), + shape: null, + parseMs: performance.now() - start, + }; + } + + if (direction === 'reverse') { + if (typeof converter.reverse !== 'function') { + return { + output: '', + inputError: null, + outputError: t('format_status.no_reverse'), + shape: null, + parseMs: performance.now() - start, + }; + } + const result = converter.reverse( + { text: input }, + options as Parameters[1], + ); + const ms = performance.now() - start; + return result.ok + ? { output: result.output, inputError: null, outputError: null, shape: null, parseMs: ms } + : { output: '', inputError: result.error, outputError: null, shape: null, parseMs: ms }; + } + + const parsed = parseJsonInput(input); + if (!parsed.ok) { + const msg = parsed.error === 'empty' ? null : parsed.error; + return { + output: '', + inputError: msg, + outputError: null, + shape: null, + parseMs: performance.now() - start, + }; + } + const result = converter.convert( + { data: parsed.value, rawText: input }, + options as Parameters[1], + ); + const ms = performance.now() - start; + if (result.ok) { + return { + output: result.output, + inputError: null, + outputError: null, + shape: parsed.shape, + parseMs: ms, + }; + } + return { + output: '', + inputError: null, + outputError: result.error, + shape: parsed.shape, + parseMs: ms, + }; + }, [input, format, options, direction, t]); +} diff --git a/src/hooks/useFileAccept.ts b/src/hooks/useFileAccept.ts new file mode 100644 index 0000000..bba0652 --- /dev/null +++ b/src/hooks/useFileAccept.ts @@ -0,0 +1,42 @@ +import { useMemo } from 'react'; +import type { Direction } from '@/components/converter/DirectionToggle'; +import { getConverter } from '@/converters/registry'; +import type { FormatId } from '@/converters/types'; +import { getAllowedExtensions } from '@/lib/file-filter'; + +export interface FileAccept { + converter: ReturnType; + isReverse: boolean; + /** react-dropzone `accept` map: MIME type → extensions. */ + accept: Record; + /** Native `` hint string. */ + fileInputAccept: string; + /** Whitelist for JS-side re-validation — `` is only a hint. */ + allowedExtensions: string[]; +} + +export function useFileAccept(format: FormatId, direction: Direction): FileAccept { + const isReverse = direction === 'reverse'; + const converter = getConverter(format); + + const accept = useMemo>(() => { + if (isReverse) { + return { + [converter.meta.mimeType]: [`.${converter.meta.extension}`], + 'text/plain': ['.txt'], + }; + } + return { 'application/json': ['.json'], 'text/plain': ['.txt'] }; + }, [isReverse, converter.meta.mimeType, converter.meta.extension]); + + const fileInputAccept = isReverse + ? `.${converter.meta.extension},.txt,${converter.meta.mimeType}` + : '.json,.txt,application/json'; + + const allowedExtensions = useMemo( + () => getAllowedExtensions(isReverse ? 'reverse' : 'forward', converter.meta.extension), + [isReverse, converter.meta.extension], + ); + + return { converter, isReverse, accept, fileInputAccept, allowedExtensions }; +} diff --git a/src/hooks/useLocalStorage.ts b/src/hooks/useLocalStorage.ts deleted file mode 100644 index c9b14c0..0000000 --- a/src/hooks/useLocalStorage.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { useCallback, useEffect, useState } from 'react'; - -/** - * React hook for persistent state in localStorage. - * Survives reload; synced across tabs via `storage` event. - */ -export function useLocalStorage( - key: string, - initialValue: T, -): [T, (value: T | ((prev: T) => T)) => void] { - const read = useCallback((): T => { - if (typeof window === 'undefined') return initialValue; - try { - const raw = window.localStorage.getItem(key); - if (raw === null) return initialValue; - return JSON.parse(raw) as T; - } catch { - return initialValue; - } - }, [key, initialValue]); - - const [stored, setStored] = useState(read); - - const setValue = useCallback( - (value: T | ((prev: T) => T)) => { - setStored((prev) => { - const next = typeof value === 'function' ? (value as (p: T) => T)(prev) : value; - try { - window.localStorage.setItem(key, JSON.stringify(next)); - } catch { - /* quota errors are non-fatal */ - } - return next; - }); - }, - [key], - ); - - // Cross-tab sync - useEffect(() => { - const handler = (e: StorageEvent) => { - if (e.key !== key) return; - if (e.newValue === null) { - setStored(initialValue); - return; - } - try { - setStored(JSON.parse(e.newValue) as T); - } catch { - /* ignore malformed */ - } - }; - window.addEventListener('storage', handler); - return () => window.removeEventListener('storage', handler); - }, [key, initialValue]); - - return [stored, setValue]; -} diff --git a/src/hooks/useOutputBadge.ts b/src/hooks/useOutputBadge.ts new file mode 100644 index 0000000..9ee5267 --- /dev/null +++ b/src/hooks/useOutputBadge.ts @@ -0,0 +1,23 @@ +import { useEffect, useRef, useState } from 'react'; + +// Tracks an "unread output" badge for the mobile Output tab: set when output +// changes while the user is on a different tab, cleared once they navigate over. +export function useOutputBadge(output: string, activeTab: 'input' | 'output'): boolean { + const [hasUnreadOutput, setHasUnreadOutput] = useState(false); + const prevOutputRef = useRef(''); + + useEffect(() => { + if (output !== prevOutputRef.current) { + prevOutputRef.current = output; + if (output && activeTab !== 'output') { + setHasUnreadOutput(true); + } + } + }, [output, activeTab]); + + useEffect(() => { + if (activeTab === 'output') setHasUnreadOutput(false); + }, [activeTab]); + + return hasUnreadOutput; +} diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 809e7eb..f6038aa 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -26,5 +26,3 @@ void i18n lookupLocalStorage: 'jsonprism.lang', }, }); - -export default i18n; diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 18caa8c..6d6c798 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -291,7 +291,8 @@ "common": { "loading": "Loading…", "error": "Error", - "retry": "Retry" + "retry": "Retry", + "scroll_to_top": "Back to top" }, "disclaimer": { "translation": "Non-English translations are AI-generated. Accuracy is not guaranteed." diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index 46cfe6e..9804761 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -291,7 +291,8 @@ "common": { "loading": "読み込み中…", "error": "エラー", - "retry": "再試行" + "retry": "再試行", + "scroll_to_top": "トップへ戻る" }, "disclaimer": { "translation": "このページの翻訳は AI 生成です。100% の正確性は保証されません。" diff --git a/src/i18n/locales/vi.json b/src/i18n/locales/vi.json index 99ed8ec..616bbcc 100644 --- a/src/i18n/locales/vi.json +++ b/src/i18n/locales/vi.json @@ -291,7 +291,8 @@ "common": { "loading": "Đang tải…", "error": "Lỗi", - "retry": "Thử lại" + "retry": "Thử lại", + "scroll_to_top": "Về đầu trang" }, "disclaimer": { "translation": "Các bản dịch không phải tiếng Anh do AI tạo, không đảm bảo chính xác 100%." diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index cad2b2b..f7c0d98 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -291,7 +291,8 @@ "common": { "loading": "加载中…", "error": "错误", - "retry": "重试" + "retry": "重试", + "scroll_to_top": "回到顶部" }, "disclaimer": { "translation": "本页面译文由 AI 生成,不保证 100% 准确。" diff --git a/src/lib/editor-language.ts b/src/lib/editor-language.ts new file mode 100644 index 0000000..7afc42c --- /dev/null +++ b/src/lib/editor-language.ts @@ -0,0 +1,17 @@ +import type { EditorLanguage } from '@/components/converter/CodeEditor'; +import type { Direction } from '@/components/converter/DirectionToggle'; +import type { FormatId } from '@/converters/types'; + +// CodeMirror language pack for the input editor. Forward mode is always JSON. +// In reverse mode, pick the closest available pack — formats without an +// official CodeMirror grammar fall back to plain text. +export function editorLanguageFor(format: FormatId, direction: Direction): EditorLanguage { + if (direction !== 'reverse') return 'json'; + if (format === 'yaml') return 'yaml'; + if (format === 'xml' || format === 'resx') return 'xml'; + if (format === 'jsonl') return 'json'; + if (format === 'markdown') return 'markdown'; + if (format === 'sql') return 'sql'; + if (format === 'toml') return 'toml'; + return 'plain'; +} diff --git a/src/lib/format-bytes.ts b/src/lib/format-bytes.ts new file mode 100644 index 0000000..a5a2d36 --- /dev/null +++ b/src/lib/format-bytes.ts @@ -0,0 +1,5 @@ +export function formatBytes(bytes: number): string { + if (bytes < 1024) return `${bytes} B`; + if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; + return `${(bytes / 1024 / 1024).toFixed(2)} MB`; +} diff --git a/src/lib/read-file.ts b/src/lib/read-file.ts new file mode 100644 index 0000000..97d31c1 --- /dev/null +++ b/src/lib/read-file.ts @@ -0,0 +1,8 @@ +export function readFileText(file: File): Promise { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(String(reader.result ?? '')); + reader.onerror = () => reject(new Error(`Cannot read file: ${file.name}`)); + reader.readAsText(file); + }); +} diff --git a/src/lib/tauri.ts b/src/lib/tauri.ts index 5035a54..2f6c550 100644 --- a/src/lib/tauri.ts +++ b/src/lib/tauri.ts @@ -62,7 +62,7 @@ export async function nativeSaveBlob(blob: Blob, suggestedName: string): Promise /** * Read a file at the given native path as a UTF-8 string. */ -export async function nativeReadText(path: string): Promise { +async function nativeReadText(path: string): Promise { if (!isTauri()) { throw new Error('nativeReadText is only available inside Tauri.'); } @@ -131,6 +131,7 @@ export async function fileFromNativePath(path: string): Promise { /** * Diagnostic info from the Rust side (OS, arch, app version). * Not currently shown in the UI but useful for bug reports. + * @public */ export async function tauriHostInfo(): Promise<{ os: string; diff --git a/src/pages/About.tsx b/src/pages/About.tsx index f155eb9..2780888 100644 --- a/src/pages/About.tsx +++ b/src/pages/About.tsx @@ -1,5 +1,7 @@ +import { useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { ExternalLink, Heart, Users } from 'lucide-react'; +import { ScrollToTop } from '@/components/common/ScrollToTop'; import { BlueskyIcon, DiscordIcon, @@ -135,170 +137,175 @@ const DEPS: DepCategory[] = [ export function About() { const { t } = useTranslation(); + const scrollRef = useRef(null); return ( // Layout's
    is `flex flex-1 min-h-0 flex-col` (height-bounded). The // About page has many sections, so it needs its own scroll container — - // otherwise content overflows past the Footer at the bottom. -
    -
    -

    - {t('about.title')} -

    -

    {t('about.lead')}

    -
    -

    {t('about.p1')}

    -

    {t('about.p2')}

    -
    - - {/* Donate */} -
    -

    - - {t('about.donate.title')} -

    -

    {t('about.donate.lead')}

    - -
    - - {/* Community */} -
    -

    - - {t('about.community.title')} -

    -

    {t('about.community.lead')}

    - -
    - - {/* Third-party */} -
    -

    - {t('about.third_party.title')} -

    -

    {t('about.third_party.lead')}

    -
    - {DEPS.map((cat) => ( -
    -

    - {t(`about.third_party.${cat.key}`)} -

    - -
    - ))} + // otherwise content overflows past the Footer. The relative wrapper anchors + // the floating scroll-to-top button above the Footer. +
    +
    +
    +

    + {t('about.title')} +

    +

    {t('about.lead')}

    +
    +

    {t('about.p1')}

    +

    {t('about.p2')}

    -

    - - {t('about.third_party.see_full_list')} - -

    -
    - {/* Build info */} -
    -

    {t('about.build.title')}

    -
    -
    {t('about.build.version')}
    -
    {__APP_VERSION__}
    -
    {t('about.build.commit')}
    -
    + {/* Donate */} +
    +

    + + {t('about.donate.title')} +

    +

    {t('about.donate.lead')}

    + +
    + + {/* Community */} +
    +

    + + {t('about.community.title')} +

    +

    {t('about.community.lead')}

    + +
    + + {/* Third-party */} +
    +

    + {t('about.third_party.title')} +

    +

    {t('about.third_party.lead')}

    +
    + {DEPS.map((cat) => ( +
    +

    + {t(`about.third_party.${cat.key}`)} +

    + +
    + ))} +
    +

    - {__APP_COMMIT__} + {t('about.third_party.see_full_list')} -

    -
    {t('about.build.date')}
    -
    {__APP_BUILD_DATE__}
    -
    -
    +

    + - {/* Links */} -
    -

    {t('about.links.title')}

    -
      - - - - - -
    -
    + {/* Build info */} +
    +

    {t('about.build.title')}

    +
    +
    {t('about.build.version')}
    +
    {__APP_VERSION__}
    +
    {t('about.build.commit')}
    +
    + + {__APP_COMMIT__} + +
    +
    {t('about.build.date')}
    +
    {__APP_BUILD_DATE__}
    +
    +
    - {/* Disclaimer */} -
    -

    - {t('about.disclaimer.title')} -

    -

    - {t('about.disclaimer.body')} -

    -
    + {/* Links */} +
    +

    {t('about.links.title')}

    +
      + + + + + +
    +
    -
    - {t('about.version', { version: __APP_VERSION__ })} + {/* Disclaimer */} +
    +

    + {t('about.disclaimer.title')} +

    +

    + {t('about.disclaimer.body')} +

    +
    + +
    + {t('about.version', { version: __APP_VERSION__ })} +
    +
    ); }