Skip to content

Functions

dtcg-formulas ships a growing catalog of formula definitions: built-in functions that cover common math and color operations, plus computation adapters that connect to external libraries for domain-specific work.

Built-in Functions

Built-ins are pre-registered in the registry. They wrap CSS/Sass intrinsics and require no external dependencies.

FunctionDomainDescription
clampMathConstrain a value between minimum and maximum bounds
mixColorBlend two colors by a weighted ratio
modular-scaleMathCompute a value at a step on a modular scale

Computation Adapters

Adapters are domain-specific functions backed by external libraries. Parse their .module.scssdef, then register them in your pipeline.

AdapterDomainLibraryDescription
radiusShape--Proportional radius from size and ratio
leonardoColorAdobe LeonardoContrast-aware palette color generation
color-nameColormeodai/color-namesHuman-readable color naming via nearest match
shade / tintColorculoriPerceptually uniform darkening and lightening via OKLCH
fluid-sizeResponsive--Viewport-responsive sizing via CSS clamp() generation
material-shadowElevationMaterial Design 3Elevation-to-shadow mapping

Adding Your Own

Any .module.scssdef file that follows the scssdef specification can be parsed and registered as an adapter. The workflow:

  1. Author a .module.scssdef with frontmatter + function declaration
  2. Parse it with @dtcg-formulas/parser
  3. Register the functions in a @dtcg-formulas/registry instance
  4. Wire up an evaluate callback that delegates to your library

See the Registry Contract for the full interface.

Released under the MIT License.