2.7 KiB
2.7 KiB
Architecture
Diff Tools is a static React application with a relocatable ./ build. Its comparison pipeline is deliberately separated from the view:
- The workbench captures strings or decodes a selected file as strict UTF-8 after a byte-size check.
- A fresh module worker receives a typed shared worker-job request. Changing input cancels and terminates the preceding worker; job IDs exclude stale messages, and a 15-second hard deadline bounds the whole worker. The last successful result remains on screen until a replacement succeeds.
- A mode-specific pure comparator produces display rows and diagnostics. Normalized rows are first-class output, not discarded state.
- The orchestrator adds exact input metadata, a bounded unified patch and a schema-labelled portable report.
- React renders values as text. The app never consumes or inserts HTML produced by a diff or parser library.
When Worker is unavailable, such as in unit tests, the same pure comparator runs asynchronously on the calling thread.
Comparators
- Text tokenizes lines without losing delimiters, or uses
Intl.Segmenterfor words and graphemes with bounded fallbacks.diffaligns token arrays. - JSON uses
lossless-json, rejects duplicate and prototype-affecting keys, and compares numbers without converting to IEEE-754. Object member order is semantically ignored but reported. - XML rejects active declaration/include syntax and preflights structure before
@xmldom/xmldombuilds an inert DOM. Elements and attributes compare by expanded name when selected. - CSV/TSV uses Papa Parse in string mode. Unique composite keys align rows; no spreadsheet type inference is performed.
- Directory manifests strip the one common browser-selected root, validate every relative path and conservative case/Unicode collision key, then hash file bytes with SHA-256 under count, per-file, aggregate and concurrency ceilings. The sorted, versioned JSON artifact can be compared later without the files.
- Three-way merge independently derives bounded token edits from base to ours and base to theirs. Non-overlapping regions compose; overlapping regions are compared against each other and the base before conflict markers are emitted. It does not claim semantic structured-data merging.
All report and patch formats are generated locally. de.add-ideas.diff-tools.report.v1, de.add-ideas.diff-tools.directory-manifest.v1 and de.add-ideas.diff-tools.merge-report.v1 identify the portable artifacts.
Diff algorithms, semantic models and reports remain bounded domain functions in
src/core. Generic byte-size display, safe Blob downloads and cancellable
worker lifecycle come from @add-ideas/toolbox-helpers 0.2.0.