開放 API
五個免費端點,無需註冊和金鑰,任意來源直接調用。數據口徑與全站一致:16,777,216 色空間、32,258 個命名色、17,756 檔標準色卡、659 個中國傳統色。
介面一覽
全部端點已開啟 CORS,瀏覽器與 Node.js 都能直接 fetch。
GET/api/search?q=crimson&limit=8
搜尋顏色:顏色名、標準色號、傳統色名與 HEX 模糊匹配
請求參數
| q | 搜索關鍵詞:支持 HEX 色值(ff0000)、顏色名稱(crimson)、標準色號(RAL 3020) |
| limit | 返回條數上限,預設 12,最大 50 |
調用示例
curl "https://www.yanseku.com/api/search?q=crimson&limit=8"
瀏覽器直接 fetch 即可,已開啟 CORS。
響應示例
{
"query": "crimson",
"results": [
{ "name": "BM 1299 Crimson", "hex": "b1625b", "source": "standard", "system": "benjamin_moore", "code": "BM 1299" },
{ "name": "crimson", "hex": "dc143c", "source": "standard", "system": "css_named", "code": "crimson" }
]
}GET/api/color/e63946
顏色檔案:10 種格式轉換 + 最近命名色 + 8 體系標準對位 + 傳統色對位 + 六種調和 + 對比度
請求參數
| hex | 顏色值:3 或 6 位 HEX(e63946 或 e63) |
調用示例
curl "https://www.yanseku.com/api/color/e63946"
響應示例
{
"hex": "e63946",
"formats": {
"rgb": { "r": 230, "g": 57, "b": 70 },
"hsl": { "h": 355.5, "s": 77.6, "l": 56.3 },
"hsv": { "h": 355.5, "s": 75.2, "v": 90.2 },
"cmyk": { "c": 0, "m": 75.2, "y": 69.6, "k": 9.8 },
"xyz": { "x": 0.352, "y": 0.2019, "z": 0.0784 },
"lab": { "L": 52.06, "a": 65.72, "b": 34.14 },
"oklch": { "L": 0.612, "c": 0.208, "h": 22.2 },
"webSafe": "ff3333",
"css": { "rgb": "rgb(230, 57, 70)", "hsl": "hsl(355.5, 77.6%, 56.3%)" }
},
"named": {
"closest": { "name": "Paint the Town Red", "hex": "e63045", "deltaE": 1.34, "exact": false },
"nearest": [ { "name": "Red Radish", "hex": "ee3344", "deltaE": 1.36, "exact": false } ]
},
"standards": [
{ "system": "ncs", "systemName": "NCS (Natural Color System)", "code": "NCS S 0570-Y90R", "name": "NCS S 0570-Y90R", "hex": "e6373f", "deltaE": 1.69, "exact": false },
{ "system": "munsell", "systemName": "Munsell (Re-renotation)", "code": "7.5R 6/16", "name": "7.5R 6/16", "hex": "dd3743", "deltaE": 2.02, "exact": false }
],
"traditional": [
{ "name": "火红", "hex": "ff2d51", "cat": "红", "deltaE": 4.88, "exact": false },
{ "name": "银红", "hex": "f05654", "cat": "红", "deltaE": 5.89, "exact": false }
],
"harmony": [
{ "type": "complementary", "colors": ["e63946", "39e6d9"] },
{ "type": "split-complementary", "colors": ["e63946", "39e683", "399de6"] }
],
"contrast": {
"onWhite": { "ratio": 4.17, "levels": { "aaNormal": false, "aaLarge": true, "aaaNormal": false, "aaaLarge": false } },
"onBlack": { "ratio": 5.04, "levels": { "aaNormal": true, "aaLarge": true, "aaaNormal": false, "aaaLarge": true } },
"bestText": "#000000"
}
}GET/api/scheme?hex=e63946&mode=triadic
調和配色:六種規則圍繞主色生成方案
請求參數
| hex | 顏色值:3 或 6 位 HEX(e63946 或 e63) |
| mode | 調和規則,預設 complementary。可選:complementary / split-complementary / triadic / tetradic / analogous / monochromatic |
調用示例
curl "https://www.yanseku.com/api/scheme?hex=e63946&mode=triadic"
響應示例
{
"hex": "e63946",
"mode": "triadic",
"count": 3,
"colors": ["e63946", "46e639", "3946e6"]
}GET/api/contrast?fg=ffffff&bg=e63946
對比度檢查:WCAG 比值 + AA/AAA 判定 + 最佳文字色
請求參數
| fg | 前景色 HEX,例如 ffffff |
| bg | 背景色 HEX,例如 e63946 |
調用示例
curl "https://www.yanseku.com/api/contrast?fg=ffffff&bg=e63946"
響應示例
{
"fg": "ffffff",
"bg": "e63946",
"ratio": 4.17,
"label": "AA Large",
"levels": { "aaNormal": false, "aaLarge": true, "aaaNormal": false, "aaaLarge": false },
"bestText": "#000000"
}GET/api/random?count=5
隨機一色:從精選命名色池抽取,最多 10 個
請求參數
| count | 隨機個數,1–10,預設 1 |
調用示例
curl "https://www.yanseku.com/api/random?count=5"
響應示例
{
"count": 3,
"colors": [
{ "name": "Sea Foam Green", "hex": "c2e4d0" },
{ "name": "Deep Koamaru", "hex": "333366" },
{ "name": "Laser Lemon", "hex": "ffff66" }
]
}開放數據下載
不止接口——整庫數據直接拿走。CSV 格式(UTF-8,首行表頭),適用於數據分析、機器學習與設計系統研究。字段說明見表頭,數據持續隨構建更新。
命名色數據基於 meodai/color-names(MIT)與 xkcd Color Survey;品牌色基於 simple-icons 開放數據;中國傳統色基於 zerosoul/chinese-colors 與中國色站數據;標準色卡色值為計算機模擬轉換,生產環境請以實物色卡為準。使用請遵循對應上游許可。
開源代碼庫
整站引擎與數據已打包為開源庫,可離線運行、可嵌入生產環境。npm 三件套覆蓋色彩引擎、數據集與 MCP Server,另有 Python 移植與 HuggingFace 數據集。
色彩引擎:10 色彩空間互轉、CIEDE2000、APCA、OKLab 混色、6 調和規則、色覺模擬——純計算零依賴
npm install @yanseku/color
數據集:17 庫 85,000+ 條目(命名色/標準卡/傳統色/日本色/品牌色…),JSON 直讀,LAB 預計算
npm install @yanseku/data
MCP Server:把整個顏色庫接入 Claude / Cursor 等 AI 客戶端,7 個工具離線可用
npm install -g @yanseku/mcp
Python 版:pip 一裝即用,同款 D65 數學與 ΔE2000,內建 659 傳統色典故
pip install yanseku
MCP 配置·遠端(免安裝,直接連雲端數據庫)
{
"mcpServers": {
"yanseku": {
"url": "https://www.yanseku.com/api/mcp"
}
}
}MCP 配置·本機(npx 離線運行)
{
"mcpServers": {
"yanseku": {
"command": "npx",
"args": ["-y", "@yanseku/mcp"]
}
}
}與其他色彩庫的能力對比
常見色彩庫只做數學轉換;Yanseku 獨有的是「數據層」:命名色檢索、官方色卡對位與傳統色典故。
| 功能 | Yanseku | colorjs.io | culori | chroma-js |
|---|---|---|---|---|
| 色彩空間互轉(10 種格式) | ✔ | ✔ | ✔ | |
| CIEDE2000 色差 | ✔ | ✔ | ✔ | |
| APCA 感知對比度 | ✔ | ✘ | ✘ | |
| 色覺缺陷模擬(8 型) | ✔ | ✘ | ✘ | |
| 命名色檢索(32,258) | ✔ 32,258 | ✘ | ✘ | |
| 官方色卡對位(12 體系) | ✔ 17,756 | ✘ | ✘ | |
| 中國傳統色典故(659) | ✔ 659 | ✘ | ✘ | |
| 感知調和規則 | ✔ 6 rules | ✘ | ✔ palette | |
| MCP Server(離線) | ✔ remote + offline | ✘ | ✘ | |
| Python 移植版 | ✔ | ✘ | ✘ | |
| 整庫 CSV / HF Dataset | ✔ 17 sets | ✘ | ✘ |
發布渠道: npm (@yanseku/color · @yanseku/data · @yanseku/mcp) · PyPI (yanseku) · HuggingFace (yanseku/chinese-traditional-colors)
來源標記:standard = 官方標準色卡;community = 社區命名色;traditional = 中國傳統色
免費公開接口,請合理調用(建議 ≤ 60 次/分鐘)。