@ufira/vibma 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/mcp.cjs +807 -1429
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.js +807 -1430
- package/dist/mcp.js.map +1 -1
- package/dist/tools/endpoint.cjs +119 -0
- package/dist/tools/endpoint.cjs.map +1 -0
- package/dist/tools/endpoint.d.cts +94 -0
- package/dist/tools/endpoint.d.ts +94 -0
- package/dist/tools/endpoint.js +92 -0
- package/dist/tools/endpoint.js.map +1 -0
- package/dist/tools/registry.cjs +73 -0
- package/dist/tools/registry.cjs.map +1 -0
- package/dist/tools/registry.d.cts +14 -0
- package/dist/tools/registry.d.ts +14 -0
- package/dist/tools/registry.js +47 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/schemas.cjs +101 -0
- package/dist/tools/schemas.cjs.map +1 -0
- package/dist/tools/schemas.d.cts +52 -0
- package/dist/tools/schemas.d.ts +52 -0
- package/dist/tools/schemas.js +70 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/types.cjs +52 -0
- package/dist/tools/types.cjs.map +1 -0
- package/dist/tools/types.d.cts +53 -0
- package/dist/tools/types.d.ts +53 -0
- package/dist/tools/types.js +27 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/utils/coercion.cjs +56 -0
- package/dist/utils/coercion.cjs.map +1 -0
- package/dist/utils/coercion.d.cts +10 -0
- package/dist/utils/coercion.d.ts +10 -0
- package/dist/utils/coercion.js +30 -0
- package/dist/utils/coercion.js.map +1 -0
- package/dist/utils/color.cjs +38 -0
- package/dist/utils/color.cjs.map +1 -0
- package/dist/utils/color.d.cts +4 -0
- package/dist/utils/color.d.ts +4 -0
- package/dist/utils/color.js +14 -0
- package/dist/utils/color.js.map +1 -0
- package/dist/utils/wcag.cjs +123 -0
- package/dist/utils/wcag.cjs.map +1 -0
- package/dist/utils/wcag.d.cts +80 -0
- package/dist/utils/wcag.d.ts +80 -0
- package/dist/utils/wcag.js +92 -0
- package/dist/utils/wcag.js.map +1 -0
- package/package.json +44 -15
- package/LICENSE +0 -22
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/color.ts
|
|
20
|
+
var color_exports = {};
|
|
21
|
+
__export(color_exports, {
|
|
22
|
+
rgbaToHex: () => rgbaToHex
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(color_exports);
|
|
25
|
+
function rgbaToHex(color) {
|
|
26
|
+
if (typeof color === "string" && color.startsWith("#")) return color;
|
|
27
|
+
const r = Math.round(color.r * 255);
|
|
28
|
+
const g = Math.round(color.g * 255);
|
|
29
|
+
const b = Math.round(color.b * 255);
|
|
30
|
+
const a = color.a !== void 0 ? Math.round(color.a * 255) : 255;
|
|
31
|
+
const hex = [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
32
|
+
return a === 255 ? `#${hex}` : `#${hex}${a.toString(16).padStart(2, "0")}`;
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
rgbaToHex
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=color.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/color.ts"],"sourcesContent":["/** Convert RGBA (0-1 float) to hex string. Handles both server and plugin contexts. */\nexport function rgbaToHex(color: any): string {\n if (typeof color === \"string\" && color.startsWith(\"#\")) return color;\n\n const r = Math.round(color.r * 255);\n const g = Math.round(color.g * 255);\n const b = Math.round(color.b * 255);\n const a = color.a !== undefined ? Math.round(color.a * 255) : 255;\n\n const hex = [r, g, b].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n return a === 255 ? `#${hex}` : `#${hex}${a.toString(16).padStart(2, \"0\")}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,SAAS,UAAU,OAAoB;AAC5C,MAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG,EAAG,QAAO;AAE/D,QAAM,IAAI,KAAK,MAAM,MAAM,IAAI,GAAG;AAClC,QAAM,IAAI,KAAK,MAAM,MAAM,IAAI,GAAG;AAClC,QAAM,IAAI,KAAK,MAAM,MAAM,IAAI,GAAG;AAClC,QAAM,IAAI,MAAM,MAAM,SAAY,KAAK,MAAM,MAAM,IAAI,GAAG,IAAI;AAE9D,QAAM,MAAM,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AACzE,SAAO,MAAM,MAAM,IAAI,GAAG,KAAK,IAAI,GAAG,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC;AAC1E;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/utils/color.ts
|
|
2
|
+
function rgbaToHex(color) {
|
|
3
|
+
if (typeof color === "string" && color.startsWith("#")) return color;
|
|
4
|
+
const r = Math.round(color.r * 255);
|
|
5
|
+
const g = Math.round(color.g * 255);
|
|
6
|
+
const b = Math.round(color.b * 255);
|
|
7
|
+
const a = color.a !== void 0 ? Math.round(color.a * 255) : 255;
|
|
8
|
+
const hex = [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
9
|
+
return a === 255 ? `#${hex}` : `#${hex}${a.toString(16).padStart(2, "0")}`;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
rgbaToHex
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/color.ts"],"sourcesContent":["/** Convert RGBA (0-1 float) to hex string. Handles both server and plugin contexts. */\nexport function rgbaToHex(color: any): string {\n if (typeof color === \"string\" && color.startsWith(\"#\")) return color;\n\n const r = Math.round(color.r * 255);\n const g = Math.round(color.g * 255);\n const b = Math.round(color.b * 255);\n const a = color.a !== undefined ? Math.round(color.a * 255) : 255;\n\n const hex = [r, g, b].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n return a === 255 ? `#${hex}` : `#${hex}${a.toString(16).padStart(2, \"0\")}`;\n}\n"],"mappings":";AACO,SAAS,UAAU,OAAoB;AAC5C,MAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG,EAAG,QAAO;AAE/D,QAAM,IAAI,KAAK,MAAM,MAAM,IAAI,GAAG;AAClC,QAAM,IAAI,KAAK,MAAM,MAAM,IAAI,GAAG;AAClC,QAAM,IAAI,KAAK,MAAM,MAAM,IAAI,GAAG;AAClC,QAAM,IAAI,MAAM,MAAM,SAAY,KAAK,MAAM,MAAM,IAAI,GAAG,IAAI;AAE9D,QAAM,MAAM,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AACzE,SAAO,MAAM,MAAM,IAAI,GAAG,KAAK,IAAI,GAAG,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC;AAC1E;","names":[]}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/wcag.ts
|
|
20
|
+
var wcag_exports = {};
|
|
21
|
+
__export(wcag_exports, {
|
|
22
|
+
alphaComposite: () => alphaComposite,
|
|
23
|
+
checkContrastPair: () => checkContrastPair,
|
|
24
|
+
contrastRatio: () => contrastRatio,
|
|
25
|
+
formatContrastFailures: () => formatContrastFailures,
|
|
26
|
+
inferFontWeight: () => inferFontWeight,
|
|
27
|
+
isLargeText: () => isLargeText,
|
|
28
|
+
looksInteractive: () => looksInteractive,
|
|
29
|
+
srgbRelativeLuminance: () => srgbRelativeLuminance
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(wcag_exports);
|
|
32
|
+
function srgbRelativeLuminance(r, g, b) {
|
|
33
|
+
const linearize = (c) => c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
34
|
+
return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
|
|
35
|
+
}
|
|
36
|
+
function contrastRatio(l1, l2) {
|
|
37
|
+
const lighter = Math.max(l1, l2);
|
|
38
|
+
const darker = Math.min(l1, l2);
|
|
39
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
40
|
+
}
|
|
41
|
+
function alphaComposite(fgR, fgG, fgB, fgA, bgR, bgG, bgB) {
|
|
42
|
+
return {
|
|
43
|
+
r: fgR * fgA + bgR * (1 - fgA),
|
|
44
|
+
g: fgG * fgA + bgG * (1 - fgA),
|
|
45
|
+
b: fgB * fgA + bgB * (1 - fgA)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function checkContrastPair(fg, bg, large = false) {
|
|
49
|
+
const fgLum = srgbRelativeLuminance(fg.r, fg.g, fg.b);
|
|
50
|
+
const bgLum = srgbRelativeLuminance(bg.r, bg.g, bg.b);
|
|
51
|
+
const ratio = contrastRatio(fgLum, bgLum);
|
|
52
|
+
const aaRequired = large ? 3 : 4.5;
|
|
53
|
+
const aaaRequired = large ? 4.5 : 7;
|
|
54
|
+
return {
|
|
55
|
+
ratio: Math.round(ratio * 100) / 100,
|
|
56
|
+
passesAA: ratio >= aaRequired,
|
|
57
|
+
passesAAA: ratio >= aaaRequired,
|
|
58
|
+
aaRequired,
|
|
59
|
+
aaaRequired
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function isLargeText(fontSize, fontWeight) {
|
|
63
|
+
if (fontSize >= 24) return true;
|
|
64
|
+
if (fontSize >= 18.66 && fontWeight >= 700) return true;
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
function inferFontWeight(fontStyle) {
|
|
68
|
+
const s = fontStyle.toLowerCase();
|
|
69
|
+
if (s.includes("thin") || s.includes("hairline")) return 100;
|
|
70
|
+
if (s.includes("extralight") || s.includes("extra light") || s.includes("ultralight")) return 200;
|
|
71
|
+
if (s.includes("light")) return 300;
|
|
72
|
+
if (s.includes("regular") || s.includes("normal") || s === "roman") return 400;
|
|
73
|
+
if (s.includes("medium")) return 500;
|
|
74
|
+
if (s.includes("semibold") || s.includes("semi bold") || s.includes("demibold")) return 600;
|
|
75
|
+
if (s.includes("extrabold") || s.includes("extra bold") || s.includes("ultrabold")) return 800;
|
|
76
|
+
if (s.includes("bold")) return 700;
|
|
77
|
+
if (s.includes("black") || s.includes("heavy")) return 900;
|
|
78
|
+
return 400;
|
|
79
|
+
}
|
|
80
|
+
var INTERACTIVE_NAME_PATTERN = /\b(button|btn|link|tab|toggle|switch|checkbox|radio|chip|badge|tag|cta|menu[-_]?item|nav[-_]?item|input|select|dropdown|close|action|icon[-_]?button)\b/i;
|
|
81
|
+
function looksInteractive(node) {
|
|
82
|
+
if (node.type === "COMPONENT" || node.type === "INSTANCE") return true;
|
|
83
|
+
if (node.type === "FRAME" && INTERACTIVE_NAME_PATTERN.test(node.name)) return true;
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
function formatContrastFailures(newColor, existingColors) {
|
|
87
|
+
let worstRatio = Infinity;
|
|
88
|
+
let worstName = "";
|
|
89
|
+
let failCount = 0;
|
|
90
|
+
for (const existing of existingColors) {
|
|
91
|
+
const result = checkContrastPair(newColor, existing.color);
|
|
92
|
+
if (!result.passesAA) {
|
|
93
|
+
failCount++;
|
|
94
|
+
if (result.ratio < worstRatio) {
|
|
95
|
+
worstRatio = result.ratio;
|
|
96
|
+
worstName = existing.name;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const parts = [];
|
|
101
|
+
if (failCount > 0) {
|
|
102
|
+
parts.push(`Fails AA against ${failCount} style${failCount > 1 ? "s" : ""} (worst: ${worstRatio}:1 vs '${worstName}')`);
|
|
103
|
+
}
|
|
104
|
+
const whiteResult = checkContrastPair(newColor, { r: 1, g: 1, b: 1 });
|
|
105
|
+
const blackResult = checkContrastPair(newColor, { r: 0, g: 0, b: 0 });
|
|
106
|
+
if (whiteResult.ratio < 3 && blackResult.ratio < 3) {
|
|
107
|
+
parts.push("<3:1 vs both white & black");
|
|
108
|
+
}
|
|
109
|
+
if (parts.length === 0) return null;
|
|
110
|
+
return "WCAG: " + parts.join(". ") + ".";
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
alphaComposite,
|
|
115
|
+
checkContrastPair,
|
|
116
|
+
contrastRatio,
|
|
117
|
+
formatContrastFailures,
|
|
118
|
+
inferFontWeight,
|
|
119
|
+
isLargeText,
|
|
120
|
+
looksInteractive,
|
|
121
|
+
srgbRelativeLuminance
|
|
122
|
+
});
|
|
123
|
+
//# sourceMappingURL=wcag.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/wcag.ts"],"sourcesContent":["// ─── WCAG 2.2 Accessibility Utilities ────────────────────────────\n// Shared functions for contrast checking, luminance calculation, and\n// accessibility heuristics. Used by lint rules and creation-time recommendations.\n\n\n\n// ─── Types ──────────────────────────────────────────────────────\n\nexport interface SolidColor {\n r: number; g: number; b: number; a: number;\n}\n\nexport interface ContrastResult {\n ratio: number;\n passesAA: boolean;\n passesAAA: boolean;\n aaRequired: number;\n aaaRequired: number;\n}\n\n// ─── Core WCAG Calculations ─────────────────────────────────────\n\n/**\n * WCAG 2.2 relative luminance from sRGB channels (0-1 float).\n * https://www.w3.org/TR/WCAG22/#dfn-relative-luminance\n */\nexport function srgbRelativeLuminance(r: number, g: number, b: number): number {\n const linearize = (c: number) =>\n c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);\n return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);\n}\n\n/**\n * WCAG contrast ratio between two relative luminances.\n * Always returns a value >= 1.0.\n */\nexport function contrastRatio(l1: number, l2: number): number {\n const lighter = Math.max(l1, l2);\n const darker = Math.min(l1, l2);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\n/**\n * Composite a foreground RGBA color over an opaque background RGB.\n * Returns the resulting opaque RGB (0-1 float).\n */\nexport function alphaComposite(\n fgR: number, fgG: number, fgB: number, fgA: number,\n bgR: number, bgG: number, bgB: number,\n): { r: number; g: number; b: number } {\n return {\n r: fgR * fgA + bgR * (1 - fgA),\n g: fgG * fgA + bgG * (1 - fgA),\n b: fgB * fgA + bgB * (1 - fgA),\n };\n}\n\n/**\n * Check contrast between two colors for both AA and AAA levels.\n * `large` = true for large text (relaxed requirements).\n */\nexport function checkContrastPair(\n fg: { r: number; g: number; b: number },\n bg: { r: number; g: number; b: number },\n large = false,\n): ContrastResult {\n const fgLum = srgbRelativeLuminance(fg.r, fg.g, fg.b);\n const bgLum = srgbRelativeLuminance(bg.r, bg.g, bg.b);\n const ratio = contrastRatio(fgLum, bgLum);\n const aaRequired = large ? 3.0 : 4.5;\n const aaaRequired = large ? 4.5 : 7.0;\n return {\n ratio: Math.round(ratio * 100) / 100,\n passesAA: ratio >= aaRequired,\n passesAAA: ratio >= aaaRequired,\n aaRequired,\n aaaRequired,\n };\n}\n\n// ─── Text Helpers ───────────────────────────────────────────────\n\n/**\n * WCAG \"large text\": >= 24px regular, or >= 18.66px bold (>= 700).\n */\nexport function isLargeText(fontSize: number, fontWeight: number): boolean {\n if (fontSize >= 24) return true;\n if (fontSize >= 18.66 && fontWeight >= 700) return true;\n return false;\n}\n\n/**\n * Infer numeric font weight from Figma's FontName.style string.\n * Returns 400 if unknown.\n */\nexport function inferFontWeight(fontStyle: string): number {\n const s = fontStyle.toLowerCase();\n if (s.includes(\"thin\") || s.includes(\"hairline\")) return 100;\n if (s.includes(\"extralight\") || s.includes(\"extra light\") || s.includes(\"ultralight\")) return 200;\n if (s.includes(\"light\")) return 300;\n if (s.includes(\"regular\") || s.includes(\"normal\") || s === \"roman\") return 400;\n if (s.includes(\"medium\")) return 500;\n if (s.includes(\"semibold\") || s.includes(\"semi bold\") || s.includes(\"demibold\")) return 600;\n if (s.includes(\"extrabold\") || s.includes(\"extra bold\") || s.includes(\"ultrabold\")) return 800;\n if (s.includes(\"bold\")) return 700; // must come after extrabold/semibold\n if (s.includes(\"black\") || s.includes(\"heavy\")) return 900;\n return 400;\n}\n\n// ─── Interactive Element Heuristic ──────────────────────────────\n\nconst INTERACTIVE_NAME_PATTERN = /\\b(button|btn|link|tab|toggle|switch|checkbox|radio|chip|badge|tag|cta|menu[-_]?item|nav[-_]?item|input|select|dropdown|close|action|icon[-_]?button)\\b/i;\n\n/**\n * Heuristic: does this node look like an interactive element?\n * Figma has no click handler concept, so we check type + name patterns.\n */\nexport function looksInteractive(node: { type: string; name: string }): boolean {\n if (node.type === \"COMPONENT\" || node.type === \"INSTANCE\") return true;\n if (node.type === \"FRAME\" && INTERACTIVE_NAME_PATTERN.test(node.name)) return true;\n return false;\n}\n\n// ─── Color extraction for contrast report ───────────────────────\n\n/**\n * Format a contrast failure report for color style/variable creation.\n * Only reports failing AA pairs. Returns null if all pass.\n */\nexport function formatContrastFailures(\n newColor: { r: number; g: number; b: number },\n existingColors: Array<{ name: string; color: { r: number; g: number; b: number } }>,\n): string | null {\n let worstRatio = Infinity;\n let worstName = \"\";\n let failCount = 0;\n\n for (const existing of existingColors) {\n const result = checkContrastPair(newColor, existing.color);\n if (!result.passesAA) {\n failCount++;\n if (result.ratio < worstRatio) {\n worstRatio = result.ratio;\n worstName = existing.name;\n }\n }\n }\n\n const parts: string[] = [];\n if (failCount > 0) {\n parts.push(`Fails AA against ${failCount} style${failCount > 1 ? \"s\" : \"\"} (worst: ${worstRatio}:1 vs '${worstName}')`);\n }\n\n // Also check against white and black for non-text contrast (3:1)\n const whiteResult = checkContrastPair(newColor, { r: 1, g: 1, b: 1 });\n const blackResult = checkContrastPair(newColor, { r: 0, g: 0, b: 0 });\n if (whiteResult.ratio < 3 && blackResult.ratio < 3) {\n parts.push(\"<3:1 vs both white & black\");\n }\n\n if (parts.length === 0) return null;\n return \"WCAG: \" + parts.join(\". \") + \".\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BO,SAAS,sBAAsB,GAAW,GAAW,GAAmB;AAC7E,QAAM,YAAY,CAAC,MACjB,KAAK,UAAU,IAAI,QAAQ,KAAK,KAAK,IAAI,SAAS,OAAO,GAAG;AAC9D,SAAO,SAAS,UAAU,CAAC,IAAI,SAAS,UAAU,CAAC,IAAI,SAAS,UAAU,CAAC;AAC7E;AAMO,SAAS,cAAc,IAAY,IAAoB;AAC5D,QAAM,UAAU,KAAK,IAAI,IAAI,EAAE;AAC/B,QAAM,SAAS,KAAK,IAAI,IAAI,EAAE;AAC9B,UAAQ,UAAU,SAAS,SAAS;AACtC;AAMO,SAAS,eACd,KAAa,KAAa,KAAa,KACvC,KAAa,KAAa,KACW;AACrC,SAAO;AAAA,IACL,GAAG,MAAM,MAAM,OAAO,IAAI;AAAA,IAC1B,GAAG,MAAM,MAAM,OAAO,IAAI;AAAA,IAC1B,GAAG,MAAM,MAAM,OAAO,IAAI;AAAA,EAC5B;AACF;AAMO,SAAS,kBACd,IACA,IACA,QAAQ,OACQ;AAChB,QAAM,QAAQ,sBAAsB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACpD,QAAM,QAAQ,sBAAsB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACpD,QAAM,QAAQ,cAAc,OAAO,KAAK;AACxC,QAAM,aAAa,QAAQ,IAAM;AACjC,QAAM,cAAc,QAAQ,MAAM;AAClC,SAAO;AAAA,IACL,OAAO,KAAK,MAAM,QAAQ,GAAG,IAAI;AAAA,IACjC,UAAU,SAAS;AAAA,IACnB,WAAW,SAAS;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AACF;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BAAa,OAAO;AACpB,oBAAY,SAAS;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAEA,QAAM,QAAkB,CAAC;AACzB,MAAI,YAAY,GAAG;AACjB,UAAM,KAAK,oBAAoB,SAAS,SAAS,YAAY,IAAI,MAAM,EAAE,YAAY,UAAU,UAAU,SAAS,IAAI;AAAA,EACxH;AAGA,QAAM,cAAc,kBAAkB,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;AACpE,QAAM,cAAc,kBAAkB,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;AACpE,MAAI,YAAY,QAAQ,KAAK,YAAY,QAAQ,GAAG;AAClD,UAAM,KAAK,4BAA4B;AAAA,EACzC;AAEA,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,SAAO,WAAW,MAAM,KAAK,IAAI,IAAI;AACvC;","names":[]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
interface SolidColor {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
a: number;
|
|
6
|
+
}
|
|
7
|
+
interface ContrastResult {
|
|
8
|
+
ratio: number;
|
|
9
|
+
passesAA: boolean;
|
|
10
|
+
passesAAA: boolean;
|
|
11
|
+
aaRequired: number;
|
|
12
|
+
aaaRequired: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* WCAG 2.2 relative luminance from sRGB channels (0-1 float).
|
|
16
|
+
* https://www.w3.org/TR/WCAG22/#dfn-relative-luminance
|
|
17
|
+
*/
|
|
18
|
+
declare function srgbRelativeLuminance(r: number, g: number, b: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* WCAG contrast ratio between two relative luminances.
|
|
21
|
+
* Always returns a value >= 1.0.
|
|
22
|
+
*/
|
|
23
|
+
declare function contrastRatio(l1: number, l2: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* Composite a foreground RGBA color over an opaque background RGB.
|
|
26
|
+
* Returns the resulting opaque RGB (0-1 float).
|
|
27
|
+
*/
|
|
28
|
+
declare function alphaComposite(fgR: number, fgG: number, fgB: number, fgA: number, bgR: number, bgG: number, bgB: number): {
|
|
29
|
+
r: number;
|
|
30
|
+
g: number;
|
|
31
|
+
b: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Check contrast between two colors for both AA and AAA levels.
|
|
35
|
+
* `large` = true for large text (relaxed requirements).
|
|
36
|
+
*/
|
|
37
|
+
declare function checkContrastPair(fg: {
|
|
38
|
+
r: number;
|
|
39
|
+
g: number;
|
|
40
|
+
b: number;
|
|
41
|
+
}, bg: {
|
|
42
|
+
r: number;
|
|
43
|
+
g: number;
|
|
44
|
+
b: number;
|
|
45
|
+
}, large?: boolean): ContrastResult;
|
|
46
|
+
/**
|
|
47
|
+
* WCAG "large text": >= 24px regular, or >= 18.66px bold (>= 700).
|
|
48
|
+
*/
|
|
49
|
+
declare function isLargeText(fontSize: number, fontWeight: number): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Infer numeric font weight from Figma's FontName.style string.
|
|
52
|
+
* Returns 400 if unknown.
|
|
53
|
+
*/
|
|
54
|
+
declare function inferFontWeight(fontStyle: string): number;
|
|
55
|
+
/**
|
|
56
|
+
* Heuristic: does this node look like an interactive element?
|
|
57
|
+
* Figma has no click handler concept, so we check type + name patterns.
|
|
58
|
+
*/
|
|
59
|
+
declare function looksInteractive(node: {
|
|
60
|
+
type: string;
|
|
61
|
+
name: string;
|
|
62
|
+
}): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Format a contrast failure report for color style/variable creation.
|
|
65
|
+
* Only reports failing AA pairs. Returns null if all pass.
|
|
66
|
+
*/
|
|
67
|
+
declare function formatContrastFailures(newColor: {
|
|
68
|
+
r: number;
|
|
69
|
+
g: number;
|
|
70
|
+
b: number;
|
|
71
|
+
}, existingColors: Array<{
|
|
72
|
+
name: string;
|
|
73
|
+
color: {
|
|
74
|
+
r: number;
|
|
75
|
+
g: number;
|
|
76
|
+
b: number;
|
|
77
|
+
};
|
|
78
|
+
}>): string | null;
|
|
79
|
+
|
|
80
|
+
export { type ContrastResult, type SolidColor, alphaComposite, checkContrastPair, contrastRatio, formatContrastFailures, inferFontWeight, isLargeText, looksInteractive, srgbRelativeLuminance };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
interface SolidColor {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
a: number;
|
|
6
|
+
}
|
|
7
|
+
interface ContrastResult {
|
|
8
|
+
ratio: number;
|
|
9
|
+
passesAA: boolean;
|
|
10
|
+
passesAAA: boolean;
|
|
11
|
+
aaRequired: number;
|
|
12
|
+
aaaRequired: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* WCAG 2.2 relative luminance from sRGB channels (0-1 float).
|
|
16
|
+
* https://www.w3.org/TR/WCAG22/#dfn-relative-luminance
|
|
17
|
+
*/
|
|
18
|
+
declare function srgbRelativeLuminance(r: number, g: number, b: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* WCAG contrast ratio between two relative luminances.
|
|
21
|
+
* Always returns a value >= 1.0.
|
|
22
|
+
*/
|
|
23
|
+
declare function contrastRatio(l1: number, l2: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* Composite a foreground RGBA color over an opaque background RGB.
|
|
26
|
+
* Returns the resulting opaque RGB (0-1 float).
|
|
27
|
+
*/
|
|
28
|
+
declare function alphaComposite(fgR: number, fgG: number, fgB: number, fgA: number, bgR: number, bgG: number, bgB: number): {
|
|
29
|
+
r: number;
|
|
30
|
+
g: number;
|
|
31
|
+
b: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Check contrast between two colors for both AA and AAA levels.
|
|
35
|
+
* `large` = true for large text (relaxed requirements).
|
|
36
|
+
*/
|
|
37
|
+
declare function checkContrastPair(fg: {
|
|
38
|
+
r: number;
|
|
39
|
+
g: number;
|
|
40
|
+
b: number;
|
|
41
|
+
}, bg: {
|
|
42
|
+
r: number;
|
|
43
|
+
g: number;
|
|
44
|
+
b: number;
|
|
45
|
+
}, large?: boolean): ContrastResult;
|
|
46
|
+
/**
|
|
47
|
+
* WCAG "large text": >= 24px regular, or >= 18.66px bold (>= 700).
|
|
48
|
+
*/
|
|
49
|
+
declare function isLargeText(fontSize: number, fontWeight: number): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Infer numeric font weight from Figma's FontName.style string.
|
|
52
|
+
* Returns 400 if unknown.
|
|
53
|
+
*/
|
|
54
|
+
declare function inferFontWeight(fontStyle: string): number;
|
|
55
|
+
/**
|
|
56
|
+
* Heuristic: does this node look like an interactive element?
|
|
57
|
+
* Figma has no click handler concept, so we check type + name patterns.
|
|
58
|
+
*/
|
|
59
|
+
declare function looksInteractive(node: {
|
|
60
|
+
type: string;
|
|
61
|
+
name: string;
|
|
62
|
+
}): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Format a contrast failure report for color style/variable creation.
|
|
65
|
+
* Only reports failing AA pairs. Returns null if all pass.
|
|
66
|
+
*/
|
|
67
|
+
declare function formatContrastFailures(newColor: {
|
|
68
|
+
r: number;
|
|
69
|
+
g: number;
|
|
70
|
+
b: number;
|
|
71
|
+
}, existingColors: Array<{
|
|
72
|
+
name: string;
|
|
73
|
+
color: {
|
|
74
|
+
r: number;
|
|
75
|
+
g: number;
|
|
76
|
+
b: number;
|
|
77
|
+
};
|
|
78
|
+
}>): string | null;
|
|
79
|
+
|
|
80
|
+
export { type ContrastResult, type SolidColor, alphaComposite, checkContrastPair, contrastRatio, formatContrastFailures, inferFontWeight, isLargeText, looksInteractive, srgbRelativeLuminance };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/utils/wcag.ts
|
|
2
|
+
function srgbRelativeLuminance(r, g, b) {
|
|
3
|
+
const linearize = (c) => c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
4
|
+
return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
|
|
5
|
+
}
|
|
6
|
+
function contrastRatio(l1, l2) {
|
|
7
|
+
const lighter = Math.max(l1, l2);
|
|
8
|
+
const darker = Math.min(l1, l2);
|
|
9
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
10
|
+
}
|
|
11
|
+
function alphaComposite(fgR, fgG, fgB, fgA, bgR, bgG, bgB) {
|
|
12
|
+
return {
|
|
13
|
+
r: fgR * fgA + bgR * (1 - fgA),
|
|
14
|
+
g: fgG * fgA + bgG * (1 - fgA),
|
|
15
|
+
b: fgB * fgA + bgB * (1 - fgA)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function checkContrastPair(fg, bg, large = false) {
|
|
19
|
+
const fgLum = srgbRelativeLuminance(fg.r, fg.g, fg.b);
|
|
20
|
+
const bgLum = srgbRelativeLuminance(bg.r, bg.g, bg.b);
|
|
21
|
+
const ratio = contrastRatio(fgLum, bgLum);
|
|
22
|
+
const aaRequired = large ? 3 : 4.5;
|
|
23
|
+
const aaaRequired = large ? 4.5 : 7;
|
|
24
|
+
return {
|
|
25
|
+
ratio: Math.round(ratio * 100) / 100,
|
|
26
|
+
passesAA: ratio >= aaRequired,
|
|
27
|
+
passesAAA: ratio >= aaaRequired,
|
|
28
|
+
aaRequired,
|
|
29
|
+
aaaRequired
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function isLargeText(fontSize, fontWeight) {
|
|
33
|
+
if (fontSize >= 24) return true;
|
|
34
|
+
if (fontSize >= 18.66 && fontWeight >= 700) return true;
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
function inferFontWeight(fontStyle) {
|
|
38
|
+
const s = fontStyle.toLowerCase();
|
|
39
|
+
if (s.includes("thin") || s.includes("hairline")) return 100;
|
|
40
|
+
if (s.includes("extralight") || s.includes("extra light") || s.includes("ultralight")) return 200;
|
|
41
|
+
if (s.includes("light")) return 300;
|
|
42
|
+
if (s.includes("regular") || s.includes("normal") || s === "roman") return 400;
|
|
43
|
+
if (s.includes("medium")) return 500;
|
|
44
|
+
if (s.includes("semibold") || s.includes("semi bold") || s.includes("demibold")) return 600;
|
|
45
|
+
if (s.includes("extrabold") || s.includes("extra bold") || s.includes("ultrabold")) return 800;
|
|
46
|
+
if (s.includes("bold")) return 700;
|
|
47
|
+
if (s.includes("black") || s.includes("heavy")) return 900;
|
|
48
|
+
return 400;
|
|
49
|
+
}
|
|
50
|
+
var INTERACTIVE_NAME_PATTERN = /\b(button|btn|link|tab|toggle|switch|checkbox|radio|chip|badge|tag|cta|menu[-_]?item|nav[-_]?item|input|select|dropdown|close|action|icon[-_]?button)\b/i;
|
|
51
|
+
function looksInteractive(node) {
|
|
52
|
+
if (node.type === "COMPONENT" || node.type === "INSTANCE") return true;
|
|
53
|
+
if (node.type === "FRAME" && INTERACTIVE_NAME_PATTERN.test(node.name)) return true;
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
function formatContrastFailures(newColor, existingColors) {
|
|
57
|
+
let worstRatio = Infinity;
|
|
58
|
+
let worstName = "";
|
|
59
|
+
let failCount = 0;
|
|
60
|
+
for (const existing of existingColors) {
|
|
61
|
+
const result = checkContrastPair(newColor, existing.color);
|
|
62
|
+
if (!result.passesAA) {
|
|
63
|
+
failCount++;
|
|
64
|
+
if (result.ratio < worstRatio) {
|
|
65
|
+
worstRatio = result.ratio;
|
|
66
|
+
worstName = existing.name;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const parts = [];
|
|
71
|
+
if (failCount > 0) {
|
|
72
|
+
parts.push(`Fails AA against ${failCount} style${failCount > 1 ? "s" : ""} (worst: ${worstRatio}:1 vs '${worstName}')`);
|
|
73
|
+
}
|
|
74
|
+
const whiteResult = checkContrastPair(newColor, { r: 1, g: 1, b: 1 });
|
|
75
|
+
const blackResult = checkContrastPair(newColor, { r: 0, g: 0, b: 0 });
|
|
76
|
+
if (whiteResult.ratio < 3 && blackResult.ratio < 3) {
|
|
77
|
+
parts.push("<3:1 vs both white & black");
|
|
78
|
+
}
|
|
79
|
+
if (parts.length === 0) return null;
|
|
80
|
+
return "WCAG: " + parts.join(". ") + ".";
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
alphaComposite,
|
|
84
|
+
checkContrastPair,
|
|
85
|
+
contrastRatio,
|
|
86
|
+
formatContrastFailures,
|
|
87
|
+
inferFontWeight,
|
|
88
|
+
isLargeText,
|
|
89
|
+
looksInteractive,
|
|
90
|
+
srgbRelativeLuminance
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=wcag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/wcag.ts"],"sourcesContent":["// ─── WCAG 2.2 Accessibility Utilities ────────────────────────────\n// Shared functions for contrast checking, luminance calculation, and\n// accessibility heuristics. Used by lint rules and creation-time recommendations.\n\n\n\n// ─── Types ──────────────────────────────────────────────────────\n\nexport interface SolidColor {\n r: number; g: number; b: number; a: number;\n}\n\nexport interface ContrastResult {\n ratio: number;\n passesAA: boolean;\n passesAAA: boolean;\n aaRequired: number;\n aaaRequired: number;\n}\n\n// ─── Core WCAG Calculations ─────────────────────────────────────\n\n/**\n * WCAG 2.2 relative luminance from sRGB channels (0-1 float).\n * https://www.w3.org/TR/WCAG22/#dfn-relative-luminance\n */\nexport function srgbRelativeLuminance(r: number, g: number, b: number): number {\n const linearize = (c: number) =>\n c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);\n return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);\n}\n\n/**\n * WCAG contrast ratio between two relative luminances.\n * Always returns a value >= 1.0.\n */\nexport function contrastRatio(l1: number, l2: number): number {\n const lighter = Math.max(l1, l2);\n const darker = Math.min(l1, l2);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\n/**\n * Composite a foreground RGBA color over an opaque background RGB.\n * Returns the resulting opaque RGB (0-1 float).\n */\nexport function alphaComposite(\n fgR: number, fgG: number, fgB: number, fgA: number,\n bgR: number, bgG: number, bgB: number,\n): { r: number; g: number; b: number } {\n return {\n r: fgR * fgA + bgR * (1 - fgA),\n g: fgG * fgA + bgG * (1 - fgA),\n b: fgB * fgA + bgB * (1 - fgA),\n };\n}\n\n/**\n * Check contrast between two colors for both AA and AAA levels.\n * `large` = true for large text (relaxed requirements).\n */\nexport function checkContrastPair(\n fg: { r: number; g: number; b: number },\n bg: { r: number; g: number; b: number },\n large = false,\n): ContrastResult {\n const fgLum = srgbRelativeLuminance(fg.r, fg.g, fg.b);\n const bgLum = srgbRelativeLuminance(bg.r, bg.g, bg.b);\n const ratio = contrastRatio(fgLum, bgLum);\n const aaRequired = large ? 3.0 : 4.5;\n const aaaRequired = large ? 4.5 : 7.0;\n return {\n ratio: Math.round(ratio * 100) / 100,\n passesAA: ratio >= aaRequired,\n passesAAA: ratio >= aaaRequired,\n aaRequired,\n aaaRequired,\n };\n}\n\n// ─── Text Helpers ───────────────────────────────────────────────\n\n/**\n * WCAG \"large text\": >= 24px regular, or >= 18.66px bold (>= 700).\n */\nexport function isLargeText(fontSize: number, fontWeight: number): boolean {\n if (fontSize >= 24) return true;\n if (fontSize >= 18.66 && fontWeight >= 700) return true;\n return false;\n}\n\n/**\n * Infer numeric font weight from Figma's FontName.style string.\n * Returns 400 if unknown.\n */\nexport function inferFontWeight(fontStyle: string): number {\n const s = fontStyle.toLowerCase();\n if (s.includes(\"thin\") || s.includes(\"hairline\")) return 100;\n if (s.includes(\"extralight\") || s.includes(\"extra light\") || s.includes(\"ultralight\")) return 200;\n if (s.includes(\"light\")) return 300;\n if (s.includes(\"regular\") || s.includes(\"normal\") || s === \"roman\") return 400;\n if (s.includes(\"medium\")) return 500;\n if (s.includes(\"semibold\") || s.includes(\"semi bold\") || s.includes(\"demibold\")) return 600;\n if (s.includes(\"extrabold\") || s.includes(\"extra bold\") || s.includes(\"ultrabold\")) return 800;\n if (s.includes(\"bold\")) return 700; // must come after extrabold/semibold\n if (s.includes(\"black\") || s.includes(\"heavy\")) return 900;\n return 400;\n}\n\n// ─── Interactive Element Heuristic ──────────────────────────────\n\nconst INTERACTIVE_NAME_PATTERN = /\\b(button|btn|link|tab|toggle|switch|checkbox|radio|chip|badge|tag|cta|menu[-_]?item|nav[-_]?item|input|select|dropdown|close|action|icon[-_]?button)\\b/i;\n\n/**\n * Heuristic: does this node look like an interactive element?\n * Figma has no click handler concept, so we check type + name patterns.\n */\nexport function looksInteractive(node: { type: string; name: string }): boolean {\n if (node.type === \"COMPONENT\" || node.type === \"INSTANCE\") return true;\n if (node.type === \"FRAME\" && INTERACTIVE_NAME_PATTERN.test(node.name)) return true;\n return false;\n}\n\n// ─── Color extraction for contrast report ───────────────────────\n\n/**\n * Format a contrast failure report for color style/variable creation.\n * Only reports failing AA pairs. Returns null if all pass.\n */\nexport function formatContrastFailures(\n newColor: { r: number; g: number; b: number },\n existingColors: Array<{ name: string; color: { r: number; g: number; b: number } }>,\n): string | null {\n let worstRatio = Infinity;\n let worstName = \"\";\n let failCount = 0;\n\n for (const existing of existingColors) {\n const result = checkContrastPair(newColor, existing.color);\n if (!result.passesAA) {\n failCount++;\n if (result.ratio < worstRatio) {\n worstRatio = result.ratio;\n worstName = existing.name;\n }\n }\n }\n\n const parts: string[] = [];\n if (failCount > 0) {\n parts.push(`Fails AA against ${failCount} style${failCount > 1 ? \"s\" : \"\"} (worst: ${worstRatio}:1 vs '${worstName}')`);\n }\n\n // Also check against white and black for non-text contrast (3:1)\n const whiteResult = checkContrastPair(newColor, { r: 1, g: 1, b: 1 });\n const blackResult = checkContrastPair(newColor, { r: 0, g: 0, b: 0 });\n if (whiteResult.ratio < 3 && blackResult.ratio < 3) {\n parts.push(\"<3:1 vs both white & black\");\n }\n\n if (parts.length === 0) return null;\n return \"WCAG: \" + parts.join(\". \") + \".\";\n}\n"],"mappings":";AA0BO,SAAS,sBAAsB,GAAW,GAAW,GAAmB;AAC7E,Q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,GAAG,GAAG,EAAE,CAAC;AACpE,QAAM,cAAc,kBAAkB,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;AACpE,MAAI,YAAY,QAAQ,KAAK,YAAY,QAAQ,GAAG;AAClD,UAAM,KAAK,4BAA4B;AAAA,EACzC;AAEA,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,SAAO,WAAW,MAAM,KAAK,IAAI,IAAI;AACvC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ufira/vibma",
|
|
3
3
|
"description": "Vibma — Vibe Design meets Figma. AI-powered MCP bridge for designing in Figma.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ufira <https://github.com/ufira-ai>",
|
|
7
7
|
"homepage": "https://github.com/ufira-ai/vibma",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/ufira-ai/vibma.git"
|
|
10
|
+
"url": "git+https://github.com/ufira-ai/vibma.git",
|
|
11
|
+
"directory": "packages/core"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [
|
|
13
14
|
"figma",
|
|
@@ -22,6 +23,40 @@
|
|
|
22
23
|
"bin": {
|
|
23
24
|
"vibma-mcp": "dist/mcp.js"
|
|
24
25
|
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": "./dist/mcp.js",
|
|
29
|
+
"require": "./dist/mcp.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./types": {
|
|
32
|
+
"import": "./dist/tools/types.js",
|
|
33
|
+
"require": "./dist/tools/types.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./endpoint": {
|
|
36
|
+
"import": "./dist/tools/endpoint.js",
|
|
37
|
+
"require": "./dist/tools/endpoint.cjs"
|
|
38
|
+
},
|
|
39
|
+
"./schemas": {
|
|
40
|
+
"import": "./dist/tools/schemas.js",
|
|
41
|
+
"require": "./dist/tools/schemas.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./registry": {
|
|
44
|
+
"import": "./dist/tools/registry.js",
|
|
45
|
+
"require": "./dist/tools/registry.cjs"
|
|
46
|
+
},
|
|
47
|
+
"./utils/color": {
|
|
48
|
+
"import": "./dist/utils/color.js",
|
|
49
|
+
"require": "./dist/utils/color.cjs"
|
|
50
|
+
},
|
|
51
|
+
"./utils/wcag": {
|
|
52
|
+
"import": "./dist/utils/wcag.js",
|
|
53
|
+
"require": "./dist/utils/wcag.cjs"
|
|
54
|
+
},
|
|
55
|
+
"./utils/coercion": {
|
|
56
|
+
"import": "./dist/utils/coercion.js",
|
|
57
|
+
"require": "./dist/utils/coercion.cjs"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
25
60
|
"files": [
|
|
26
61
|
"dist",
|
|
27
62
|
"README.md",
|
|
@@ -29,27 +64,21 @@
|
|
|
29
64
|
],
|
|
30
65
|
"type": "module",
|
|
31
66
|
"scripts": {
|
|
32
|
-
"start": "node dist/mcp.js",
|
|
33
|
-
"socket": "tsx packages/tunnel/src/index.ts",
|
|
34
|
-
"setup": "./scripts/setup.sh",
|
|
35
67
|
"build": "tsup",
|
|
36
68
|
"build:watch": "tsup --watch",
|
|
37
|
-
"
|
|
38
|
-
"dev:mcp": "tsx src/mcp.ts",
|
|
69
|
+
"prepack": "cp ../../README.md . 2>/dev/null || true",
|
|
39
70
|
"pub:release": "npm run build && npm publish"
|
|
40
71
|
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@figma/plugin-typings": "^1.123.0",
|
|
43
|
-
"@types/node": "^25.3.2",
|
|
44
|
-
"@types/ws": "^8.18.1",
|
|
45
|
-
"tsup": "^8.5.1",
|
|
46
|
-
"tsx": "^4.21.0",
|
|
47
|
-
"typescript": "^5.9.3"
|
|
48
|
-
},
|
|
49
72
|
"dependencies": {
|
|
50
73
|
"@modelcontextprotocol/sdk": "1.27.1",
|
|
51
74
|
"uuid": "latest",
|
|
52
75
|
"ws": "latest",
|
|
53
76
|
"zod": "4.3.6"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@types/node": "^25.3.2",
|
|
80
|
+
"@types/ws": "^8.18.1",
|
|
81
|
+
"tsup": "^8.5.1",
|
|
82
|
+
"typescript": "^5.9.3"
|
|
54
83
|
}
|
|
55
84
|
}
|
package/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 ufira.ai
|
|
4
|
-
Copyright (c) 2025 sonnylazuardi (original work)
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in
|
|
14
|
-
all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
-
THE SOFTWARE.
|