let red = @core.Color::from_rgb_bytes(255, 0, 0)
// 转换为各色彩空间
let hsl = @spaces.color_to_hsl(red) // HSL
let lab = @spaces.color_to_lab(red) // CIE L*a*b*
let oklch = @spaces.color_to_oklch(red) // OkLCH
// 从字符串解析
let c = @spaces.parse_color_string("#3b82f6")
let c2 = @spaces.parse_color_string("hsl(210, 100%, 60%)")
let c3 = @spaces.parse_color_string("rgb(59, 130, 246)")
调和配色 (src/harmony)
let seed = @lib.create_color("#6366f1")
// 7 种调和方式
let mono = @lib.create_harmony_palette(seed, Monochromatic)
let ana = @lib.create_harmony_palette(seed, Analogous)
let comp = @lib.create_harmony_palette(seed, Complementary)
let split = @lib.create_harmony_palette(seed, SplitComplementary)
let triad = @lib.create_harmony_palette(seed, Triadic)
let tetrad = @lib.create_harmony_palette(seed, Tetradic)
let square = @lib.create_harmony_palette(seed, Square)
// OkLCH 渐变
let stops = @harmony.generate_gradient(seed, target, steps=10)
无障碍合规 (src/accessibility)
let fg = @lib.create_color("#4f46e5")
let bg = @lib.create_color("#ffffff")
// WCAG 2.1 评估
let result = @lib.check_wcag(fg, bg)
// result.ratio, result.aa_normal, result.aaa_normal, result.compliance
// 自动修正至 AA 级别
let fixed = @lib.fix_contrast(fg, bg, target=4.5)
// 获取完整对比度网格
let grid = @accessibility.generate_contrast_grid(palette)
设计令牌生成 (src/tokens)
let brand = @lib.create_color("#6366f1")
// Material Design 3 Tonal Palette (13 tones)
let m3 = @lib.create_material_tokens(brand)
// Tailwind CSS 11-step scale
let tw = @lib.create_tailwind_tokens(brand)
// Ant Design 10-step scale
let ant = @tokens.generate_ant_design_scale(brand)
// Radix UI 12-step semantic scale
let radix = @tokens.generate_radix_scale(brand)
多格式导出 (src/export)
// CSS Custom Properties
let css = @lib.export_palette(palette, CSS)
// :root { --color-1: #6366f1; ... }
// W3C 设计令牌 JSON
let json = @lib.export_palette(palette, JSON)
// Tailwind config.js
let tw = @lib.export_palette(palette, TailwindConfig)
// SVG 色板可视化
let svg = @lib.export_palette(palette, SVG)
// Android colors.xml
let xml = @export.export_android_xml(palette)
// SwiftUI / Dart Flutter
let swift = @export.export_swift_enum(palette)
let flutter = @export.export_flutter_dart(palette)
// GIMP GPL 色板
let gpl = @export.export_gimp_gpl(palette)
moonbit-palette-forge
面向设计系统的高精度配色与色彩调和工具库
A high-precision color palette generation and harmony engine for design systems — written entirely in MoonBit.
简介
moonbit-palette-forge是一个使用 MoonBit 编写的现代化色彩科学工具库,专为设计系统(Design System)的色彩工程场景而构建。项目实现了从色彩空间转换、调和算法、无障碍合规检测,到设计令牌生成与多格式导出的完整工作流。核心特性
src/coresrc/spacessrc/harmonysrc/accessibilitysrc/visionsrc/distancesrc/tokenssrc/exportsrc/libsrc/cli快速开始
环境要求
克隆与构建
运行测试
运行命令行演示
示例输出:
模块文档
色彩空间转换 (
src/spaces)调和配色 (
src/harmony)无障碍合规 (
src/accessibility)设计令牌生成 (
src/tokens)多格式导出 (
src/export)项目结构
代码规模
corespacesharmonyaccessibilityvisiondistancetokensexportlibcliCI 持续集成
本项目配置了 GitHub Actions 多平台 CI,在每次 push 和 PR 时自动完成:
moon fmt --check)moon build --deny-warn)moon test --deny-warn)moon info)参赛信息
本项目参加 开源之夏 2026 (OSC 2026) MoonBit 赛道。
许可证
Copyright 2026 lkdrt
Licensed under the Apache License, Version 2.0. See LICENSE for details.