palette_forge

    面向设计系统的高级调色与调和工具 - Advanced Color Palette & Harmony Engine for Design Systems in MoonBit

    color
    palette
    design-system
    wcag
    oklch
    theme
    accessibility
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    28

    No dependencies

    #Palette Forge

    Palette Forge is a MoonBit color-engineering library for design systems. It combines color-space conversion, harmony generation, perceptual interpolation, accessibility auditing, semantic themes, palette analysis, and deterministic export formats in one module.

    CI MoonBit License

    #Highlights

    • Convert between RGB, HSL, HSV, HWB, CMYK, XYZ, Lab, LCH, OkLab, OkLCH, YUV, YCbCr, HSLuv, CIELUV, IPT, HSI, and Hunter Lab.
    • Generate monochromatic, analogous, complementary, triadic, tetradic, square, split-complementary, and parameterized OkLCH scales.
    • Interpolate and sample gradients in RGB, HSL, Lab, and OkLCH with explicit hue-path policy and sRGB gamut handling.
    • Build light/dark/state-aware semantic themes with aliases and cycle-safe resolution.
    • Audit WCAG contrast and APCA thresholds, produce remediation suggestions, and inspect full contrast matrices.
    • Analyze luminance distributions, duplicate colors, readability, quality gates, contrast metrics, and role frequencies.
    • Export palettes and themes as CSS, SCSS, W3C JSON, CSV, SVG, HTML, Android XML, Swift, Flutter, GIMP GPL, Markdown, YAML, and Tailwind configuration.

    #Requirements

    • MoonBit stable toolchain. The CI installs the current stable release from the official MoonBit installer.
    • Windows, macOS, or Linux for the library and portable targets. Native builds use the host C toolchain.

    #Quick start

    git clone https://github.com/lkdrt/moonbit-palette-forge.git cd moonbit-palette-forge moon update moon check --deny-warn moon test --deny-warn moon run src/cli

    The CLI is a small smoke-testable demonstration of parsing, scale generation, theme construction, accessibility auditing, analysis, and serialization.

    #Library examples

    #Strict parsing and color spaces

    let seed = @core.Color::from_hex("#3b82f6")
    let parsed = @spaces.parse_color("oklch(62% 0.19 258)")
    let hsl = @spaces.color_to_hsl(seed)
    let oklch = @spaces.color_to_oklch(seed)

    The strict parser returns a typed ColorParseError for malformed syntax, unsupported functions, invalid units, range errors, and trailing input. The legacy parse_color_string API remains available for compatibility.

    #Scales and gradients

    let spec : @harmony.ScaleSpec = {
    steps: 9,
    lightness_min: 0.18,
    lightness_max: 0.92,
    chroma_scale: 1.0,
    hue_offset: 0.0,
    }
    let scale = @harmony.generate_oklch_scale(seed, spec)
    let gradient = @harmony.generate_gradient(seed, @core.Color::from_hex("#f97316"), steps=7)

    #Semantic themes

    let theme = @tokens.Theme::new("Product")
    let theme = match theme.add_color("surface", seed, "surface") {
    Ok(next) => next
    Err(error) => abort("invalid theme")
    }
    let palette = theme.to_palette()
    let css = @export.export_theme_css(theme)
    let json = @export.export_theme_json(theme)

    #Auditing and analysis

    let policy : @accessibility.AuditPolicy = {
    min_text_ratio: 4.5,
    min_large_ratio: 3.0,
    min_ui_ratio: 3.0,
    min_apca: 60.0,
    }
    let audit = @accessibility.audit_palette(palette, policy)
    let report = @analysis.analyze_palette(palette)

    All new validation-oriented APIs use typed Result values. Existing compatibility APIs and preset generator names are preserved.

    #Package map

    PackageResponsibility
    src/coreColor, palette, validation, metadata, and palette queries
    src/spacesColor-space conversion and strict parsing
    src/harmonyHarmony presets, interpolation, gradients, gamut, and scales
    src/tokensSemantic themes, aliases, states, and token queries
    src/accessibilityWCAG/APCA measurements, audits, remediation, and reports
    src/analysisStatistics, distributions, duplicates, metrics, and quality gates
    src/visionColor-vision simulation and filter matrices
    src/distanceCIE and OkLCH color-distance algorithms
    src/exportPalette and theme serializers
    src/libSmall workflow-oriented facade API
    src/cliExecutable demonstration and smoke path
    src/benchmarkFixed-input release benchmarks

    #Development commands

    moon fmt --check moon info moon check --deny-warn moon test --deny-warn moon test --deny-warn --target wasm moon test --deny-warn --target wasm-gc moon test --deny-warn --target js moon build src/cli --target native --deny-warn

    The GitHub Actions workflow runs the portable target matrix on Ubuntu, macOS, and Windows, plus native and coverage smoke jobs on Ubuntu. Generated interfaces are refreshed with moon info and checked for drift.

    Native builds depend on the host C toolchain. On Windows, use a MinGW/runtime installation that provides the C runtime declarations required by MoonBit; portable wasm, wasm-gc, and js checks do not require that native toolchain.

    #Benchmarks

    The repository includes fixed-input workloads for parsing, color-space round-trips, theme generation, accessibility auditing, and theme export. Run the release benchmark from the repository root:

    moon bench src/benchmark --target native --release

    The command and the latest observed output are recorded in benchmarks/results-2026-08-19.txt. The report records native measurements together with the host and toolchain so that later runs can be compared responsibly.

    #Project layout

    . ├── moon.mod ├── LICENSE ├── NOTICE ├── README.md ├── benchmarks/ ├── scripts/ ├── .github/workflows/ci.yml └── src/ ├── core/ spaces/ harmony/ tokens/ ├── accessibility/ analysis/ vision/ distance/ ├── export/ lib/ cli/ benchmark/

    #License

    Palette Forge is distributed under the Apache License 2.0. See LICENSE for the complete terms.