matching library

Shipflow — Pure matching library.

Public, side-effect-free entry point for color distance (ΔE CIE2000), set similarity, fuzzy string scoring, and numeric quantization. Importable from any Dart context — including AOT-restricted ones — without dragging dart:io, AST parsers, or filesystem access.

Purity is enforced by the matching_purity rule of shipflow/.ship.yaml::architecture.package_boundaries[], which is verified in CI by tool/check_shipflow_boundaries.dart. Adding an export from outside lib/src/matching/ will fail that check.

Classes

Lab
A point in CIE Lab* color space (D65 illuminant).
SnapResult
Result of snapToSteps — the closest declared step and how far the input was from it (in the same unit as the input).

Functions

deltaE2000(Lab c1, Lab c2) double
ΔE CIE2000 between two Lab colors. Returns 0 for identical inputs and values up to ~100 for extreme contrasts.
deltaE2000FromRgb(int r1, int g1, int b1, int r2, int g2, int b2) double
Convenience: ΔE CIE2000 between two sRGB triples (0..255 per channel).
foldDiacritics(String input) String
Fold diacritics across an entire string, preserving non-alpha characters. Used by fuzzyScore for substring containment checks.
fuzzyScore(String query, String candidate) double
Compound fuzzy score in 0..1, higher = better match.
isCleanAgainst(double value, List<double> steps, {double tolerance = 0.5}) bool
Return true when value is within tolerance of any entry in steps.
jaccardAsymmetric<T>(Set<T> query, Set<T> candidate, {double weight = 0.3}) double
Asymmetric Jaccard: |Q ∩ C| / (|Q| + weight * |C|).
jaccardSimilarity<T>(Set<T> a, Set<T> b) double
Symmetric Jaccard similarity: |A ∩ B| / |A ∪ B|.
snapToMultiple(double value, double step, {double base = 0}) double
Snap value to the nearest multiple of step, offset by base. Useful when a design system uses an even grid (e.g. multiples of 4 px starting at 0). step must be strictly positive.
snapToSteps(double value, List<double> steps) SnapResult
Snap value to the closest entry of steps. steps must not be empty. Ties are broken in favour of the smaller value.
srgbToLab(int r, int g, int b) Lab
Convert sRGB (0..255 per channel) to CIE Lab under D65.
tokenize(String input) List<String>
Tokenize a string for fuzzy matching.