@muloka/figma-console-mcp 0.5.4 → 0.5.6
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 +5 -4
- package/dist/apps/design-system-dashboard/mcp-app.html +26 -26
- package/dist/apps/token-browser/mcp-app.html +34 -34
- package/dist/core/http-request-guard.d.ts.map +1 -1
- package/dist/core/http-request-guard.js +12 -14
- package/dist/core/http-request-guard.js.map +1 -1
- package/dist/core/port-discovery.d.ts.map +1 -1
- package/dist/core/port-discovery.js +151 -52
- package/dist/core/port-discovery.js.map +1 -1
- package/dist/core/websocket-server.d.ts.map +1 -1
- package/dist/core/websocket-server.js +9 -1
- package/dist/core/websocket-server.js.map +1 -1
- package/dist/core/write-tools.d.ts +5 -1
- package/dist/core/write-tools.d.ts.map +1 -1
- package/dist/core/write-tools.js +113 -83
- package/dist/core/write-tools.js.map +1 -1
- package/dist/local.d.ts.map +1 -1
- package/dist/local.js +9 -2
- package/dist/local.js.map +1 -1
- package/figma-desktop-bridge/code.js +10 -2
- package/figma-desktop-bridge/ui.html +82 -8
- package/package.json +1 -1
- package/dist/cloudflare/apps/design-system-dashboard/scoring/accessibility.js +0 -277
- package/dist/cloudflare/apps/design-system-dashboard/scoring/component-metadata.js +0 -357
- package/dist/cloudflare/apps/design-system-dashboard/scoring/consistency.js +0 -341
- package/dist/cloudflare/apps/design-system-dashboard/scoring/coverage.js +0 -230
- package/dist/cloudflare/apps/design-system-dashboard/scoring/engine.js +0 -92
- package/dist/cloudflare/apps/design-system-dashboard/scoring/naming-semantics.js +0 -308
- package/dist/cloudflare/apps/design-system-dashboard/scoring/token-architecture.js +0 -349
- package/dist/cloudflare/apps/design-system-dashboard/scoring/types.js +0 -40
- package/dist/cloudflare/apps/design-system-dashboard/server.js +0 -159
- package/dist/cloudflare/apps/token-browser/server.js +0 -136
- package/dist/cloudflare/browser-manager.js +0 -157
- package/dist/cloudflare/core/accessibility-tools.js +0 -361
- package/dist/cloudflare/core/annotation-tools.js +0 -230
- package/dist/cloudflare/core/cloud-websocket-connector.js +0 -419
- package/dist/cloudflare/core/cloud-websocket-relay.js +0 -198
- package/dist/cloudflare/core/comment-tools.js +0 -292
- package/dist/cloudflare/core/config.js +0 -153
- package/dist/cloudflare/core/console-monitor.js +0 -427
- package/dist/cloudflare/core/deep-component-tools.js +0 -128
- package/dist/cloudflare/core/design-code-tools.js +0 -2793
- package/dist/cloudflare/core/design-system-manifest.js +0 -265
- package/dist/cloudflare/core/design-system-tools.js +0 -882
- package/dist/cloudflare/core/diagnose-tool.js +0 -100
- package/dist/cloudflare/core/diff/changelog-formatter.js +0 -275
- package/dist/cloudflare/core/diff/diff-engine.js +0 -334
- package/dist/cloudflare/core/diff/property-compare.js +0 -36
- package/dist/cloudflare/core/diff/version-cache.js +0 -74
- package/dist/cloudflare/core/enrichment/enrichment-service.js +0 -374
- package/dist/cloudflare/core/enrichment/index.js +0 -7
- package/dist/cloudflare/core/enrichment/relationship-mapper.js +0 -351
- package/dist/cloudflare/core/enrichment/style-resolver.js +0 -346
- package/dist/cloudflare/core/figjam-tools.js +0 -547
- package/dist/cloudflare/core/figma-api.js +0 -509
- package/dist/cloudflare/core/figma-connector.js +0 -7
- package/dist/cloudflare/core/figma-reconstruction-spec.js +0 -402
- package/dist/cloudflare/core/figma-style-extractor.js +0 -311
- package/dist/cloudflare/core/figma-tools.js +0 -3353
- package/dist/cloudflare/core/identity.js +0 -96
- package/dist/cloudflare/core/library-tools.js +0 -580
- package/dist/cloudflare/core/logger.js +0 -53
- package/dist/cloudflare/core/port-discovery.js +0 -935
- package/dist/cloudflare/core/resolve-package-root.js +0 -11
- package/dist/cloudflare/core/slides-tools.js +0 -714
- package/dist/cloudflare/core/slot-tools.js +0 -334
- package/dist/cloudflare/core/snippet-injector.js +0 -96
- package/dist/cloudflare/core/tokens/alias-resolver.js +0 -205
- package/dist/cloudflare/core/tokens/config.js +0 -294
- package/dist/cloudflare/core/tokens/dialect.js +0 -232
- package/dist/cloudflare/core/tokens/figma-converter.js +0 -323
- package/dist/cloudflare/core/tokens/formatters/css-vars.js +0 -338
- package/dist/cloudflare/core/tokens/formatters/dtcg.js +0 -376
- package/dist/cloudflare/core/tokens/formatters/index.js +0 -45
- package/dist/cloudflare/core/tokens/formatters/json.js +0 -205
- package/dist/cloudflare/core/tokens/formatters/less.js +0 -4
- package/dist/cloudflare/core/tokens/formatters/scss.js +0 -258
- package/dist/cloudflare/core/tokens/formatters/stubs.js +0 -13
- package/dist/cloudflare/core/tokens/formatters/style-dictionary-v3.js +0 -213
- package/dist/cloudflare/core/tokens/formatters/tailwind-v3.js +0 -237
- package/dist/cloudflare/core/tokens/formatters/tailwind-v4.js +0 -335
- package/dist/cloudflare/core/tokens/formatters/tokens-studio.js +0 -256
- package/dist/cloudflare/core/tokens/formatters/ts-module.js +0 -198
- package/dist/cloudflare/core/tokens/index.js +0 -16
- package/dist/cloudflare/core/tokens/parsers/css-vars.js +0 -4
- package/dist/cloudflare/core/tokens/parsers/dtcg.js +0 -280
- package/dist/cloudflare/core/tokens/parsers/index.js +0 -138
- package/dist/cloudflare/core/tokens/parsers/json.js +0 -7
- package/dist/cloudflare/core/tokens/parsers/scss.js +0 -4
- package/dist/cloudflare/core/tokens/parsers/stubs.js +0 -20
- package/dist/cloudflare/core/tokens/parsers/style-dictionary-v3.js +0 -4
- package/dist/cloudflare/core/tokens/parsers/tailwind-v3.js +0 -4
- package/dist/cloudflare/core/tokens/parsers/tailwind-v4.js +0 -4
- package/dist/cloudflare/core/tokens/parsers/tokens-studio.js +0 -4
- package/dist/cloudflare/core/tokens/schemas.js +0 -152
- package/dist/cloudflare/core/tokens/transforms/color.js +0 -12
- package/dist/cloudflare/core/tokens/transforms/index.js +0 -29
- package/dist/cloudflare/core/tokens/transforms/size.js +0 -7
- package/dist/cloudflare/core/tokens/types.js +0 -18
- package/dist/cloudflare/core/tokens-tools.js +0 -1788
- package/dist/cloudflare/core/types/design-code.js +0 -4
- package/dist/cloudflare/core/types/enriched.js +0 -5
- package/dist/cloudflare/core/types/index.js +0 -4
- package/dist/cloudflare/core/variable-resolver.js +0 -85
- package/dist/cloudflare/core/version-tools.js +0 -1199
- package/dist/cloudflare/core/websocket-connector.js +0 -436
- package/dist/cloudflare/core/websocket-server.js +0 -1009
- package/dist/cloudflare/core/write-tools.js +0 -2506
- package/dist/cloudflare/index.js +0 -3010
|
@@ -1266,10 +1266,42 @@
|
|
|
1266
1266
|
}
|
|
1267
1267
|
};
|
|
1268
1268
|
|
|
1269
|
+
// Ports with an in-flight CONNECTING handshake: { [port]: { ws, timer } }.
|
|
1270
|
+
// Kept separate from activeConnections so status-pill counts reflect only
|
|
1271
|
+
// open sockets, while preventing the 3s discovery loop from opening
|
|
1272
|
+
// duplicate sockets to a port still mid-handshake.
|
|
1273
|
+
var connectingSockets = {};
|
|
1274
|
+
var CONNECT_STALE_TIMEOUT_MS = 10000;
|
|
1275
|
+
|
|
1276
|
+
function clearConnecting(port, sock) {
|
|
1277
|
+
var entry = connectingSockets[port];
|
|
1278
|
+
if (entry && (!sock || entry.ws === sock)) {
|
|
1279
|
+
clearTimeout(entry.timer);
|
|
1280
|
+
delete connectingSockets[port];
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
function trackConnecting(port, sock) {
|
|
1285
|
+
clearConnecting(port, sock);
|
|
1286
|
+
var staleTimer = setTimeout(function() {
|
|
1287
|
+
if (connectingSockets[port] && connectingSockets[port].ws === sock) {
|
|
1288
|
+
delete connectingSockets[port];
|
|
1289
|
+
if (sock.readyState === 0) {
|
|
1290
|
+
try { sock.close(); } catch (e) {}
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}, CONNECT_STALE_TIMEOUT_MS);
|
|
1294
|
+
connectingSockets[port] = { ws: sock, timer: staleTimer };
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1269
1297
|
/**
|
|
1270
|
-
* Check if we already have
|
|
1298
|
+
* Check if we already have an open or in-flight connection to a specific port.
|
|
1271
1299
|
*/
|
|
1272
1300
|
function isPortConnected(port) {
|
|
1301
|
+
var pendingEntry = connectingSockets[port];
|
|
1302
|
+
if (pendingEntry && pendingEntry.ws && pendingEntry.ws.readyState === 0) {
|
|
1303
|
+
return true;
|
|
1304
|
+
}
|
|
1273
1305
|
for (var i = 0; i < activeConnections.length; i++) {
|
|
1274
1306
|
if (activeConnections[i].port === port && activeConnections[i].ws.readyState === 1) {
|
|
1275
1307
|
return true;
|
|
@@ -1279,10 +1311,12 @@
|
|
|
1279
1311
|
}
|
|
1280
1312
|
|
|
1281
1313
|
/**
|
|
1282
|
-
* Remove a
|
|
1314
|
+
* Remove a specific socket from the active list and update compat state.
|
|
1315
|
+
* Matches by socket reference (not port) so a late onclose from an old
|
|
1316
|
+
* socket can never evict a live replacement socket on the same port.
|
|
1283
1317
|
*/
|
|
1284
|
-
function removeConnection(
|
|
1285
|
-
activeConnections = activeConnections.filter(function(c) { return c.
|
|
1318
|
+
function removeConnection(targetWs) {
|
|
1319
|
+
activeConnections = activeConnections.filter(function(c) { return c.ws !== targetWs; });
|
|
1286
1320
|
updateCompatState();
|
|
1287
1321
|
// Re-pace the health discovery loop: dropping to zero connections
|
|
1288
1322
|
// switches it to the fast (3s) cadence immediately.
|
|
@@ -1364,6 +1398,7 @@
|
|
|
1364
1398
|
portsToTry.forEach(function(port) {
|
|
1365
1399
|
try {
|
|
1366
1400
|
var testWs = new WebSocket('ws://localhost:' + port);
|
|
1401
|
+
trackConnecting(port, testWs);
|
|
1367
1402
|
|
|
1368
1403
|
var timeout = setTimeout(function() {
|
|
1369
1404
|
if (testWs.readyState !== 1) testWs.close();
|
|
@@ -1371,6 +1406,7 @@
|
|
|
1371
1406
|
|
|
1372
1407
|
testWs.onopen = function() {
|
|
1373
1408
|
clearTimeout(timeout);
|
|
1409
|
+
clearConnecting(port, testWs);
|
|
1374
1410
|
foundAny = true;
|
|
1375
1411
|
activeConnections.push({ port: port, ws: testWs });
|
|
1376
1412
|
updateCompatState();
|
|
@@ -1385,10 +1421,12 @@
|
|
|
1385
1421
|
|
|
1386
1422
|
testWs.onerror = function() {
|
|
1387
1423
|
clearTimeout(timeout);
|
|
1424
|
+
clearConnecting(port, testWs);
|
|
1388
1425
|
};
|
|
1389
1426
|
|
|
1390
1427
|
testWs.onclose = function() {
|
|
1391
1428
|
clearTimeout(timeout);
|
|
1429
|
+
clearConnecting(port, testWs);
|
|
1392
1430
|
pending--;
|
|
1393
1431
|
if (pending <= 0) {
|
|
1394
1432
|
isScanning = false;
|
|
@@ -1435,12 +1473,14 @@
|
|
|
1435
1473
|
if (userPaused || isPortConnected(port)) return;
|
|
1436
1474
|
try {
|
|
1437
1475
|
var testWs = new WebSocket('ws://localhost:' + port);
|
|
1476
|
+
trackConnecting(port, testWs);
|
|
1438
1477
|
var timeout = setTimeout(function() {
|
|
1439
1478
|
if (testWs.readyState !== 1) testWs.close();
|
|
1440
1479
|
}, 2000);
|
|
1441
1480
|
|
|
1442
1481
|
testWs.onopen = function() {
|
|
1443
1482
|
clearTimeout(timeout);
|
|
1483
|
+
clearConnecting(port, testWs);
|
|
1444
1484
|
activeConnections.push({ port: port, ws: testWs });
|
|
1445
1485
|
updateCompatState();
|
|
1446
1486
|
console.log('[MCP Bridge] Reconnected to port ' + port + ' (' + activeConnections.length + ' server(s) total)');
|
|
@@ -1450,6 +1490,12 @@
|
|
|
1450
1490
|
|
|
1451
1491
|
testWs.onerror = function() {
|
|
1452
1492
|
clearTimeout(timeout);
|
|
1493
|
+
clearConnecting(port, testWs);
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
testWs.onclose = function() {
|
|
1497
|
+
clearTimeout(timeout);
|
|
1498
|
+
clearConnecting(port, testWs);
|
|
1453
1499
|
};
|
|
1454
1500
|
} catch (e) {
|
|
1455
1501
|
// Port gone — the discovery loop will find it if it comes back
|
|
@@ -1465,12 +1511,14 @@
|
|
|
1465
1511
|
if (userPaused || isPortConnected(port)) return;
|
|
1466
1512
|
try {
|
|
1467
1513
|
var testWs = new WebSocket('ws://localhost:' + port);
|
|
1514
|
+
trackConnecting(port, testWs);
|
|
1468
1515
|
var timeout = setTimeout(function() {
|
|
1469
1516
|
if (testWs.readyState !== 1) testWs.close();
|
|
1470
1517
|
}, 3000);
|
|
1471
1518
|
|
|
1472
1519
|
testWs.onopen = function() {
|
|
1473
1520
|
clearTimeout(timeout);
|
|
1521
|
+
clearConnecting(port, testWs);
|
|
1474
1522
|
var conn = { port: port, ws: testWs };
|
|
1475
1523
|
if (serverVersion) conn.serverVersion = serverVersion;
|
|
1476
1524
|
activeConnections.push(conn);
|
|
@@ -1482,6 +1530,12 @@
|
|
|
1482
1530
|
|
|
1483
1531
|
testWs.onerror = function() {
|
|
1484
1532
|
clearTimeout(timeout);
|
|
1533
|
+
clearConnecting(port, testWs);
|
|
1534
|
+
};
|
|
1535
|
+
|
|
1536
|
+
testWs.onclose = function() {
|
|
1537
|
+
clearTimeout(timeout);
|
|
1538
|
+
clearConnecting(port, testWs);
|
|
1485
1539
|
};
|
|
1486
1540
|
} catch (e) {
|
|
1487
1541
|
// ignore — next discovery pass will retry
|
|
@@ -1536,7 +1590,11 @@
|
|
|
1536
1590
|
var HANDLER_TIMEOUT_MS = requestedBudget ? Math.min(requestedBudget + 5000, 310000) : 30000;
|
|
1537
1591
|
var handlerSettled = false;
|
|
1538
1592
|
var handlerTimeoutId = null;
|
|
1539
|
-
|
|
1593
|
+
// Wrap inside Promise constructor so synchronous throws reject
|
|
1594
|
+
// into .catch() and send { id, error } instead of hanging the caller.
|
|
1595
|
+
var handlerPromise = new Promise(function(resolve) {
|
|
1596
|
+
resolve(handler(message.params || {}));
|
|
1597
|
+
});
|
|
1540
1598
|
var timeoutPromise = new Promise(function(_, reject) {
|
|
1541
1599
|
handlerTimeoutId = setTimeout(function() {
|
|
1542
1600
|
if (!handlerSettled) {
|
|
@@ -1570,7 +1628,7 @@
|
|
|
1570
1628
|
};
|
|
1571
1629
|
|
|
1572
1630
|
activeWs.onclose = function(event) {
|
|
1573
|
-
removeConnection(
|
|
1631
|
+
removeConnection(activeWs);
|
|
1574
1632
|
console.log('[MCP Bridge] WebSocket disconnected from port ' + port + ' (' + activeConnections.length + ' server(s) remaining)');
|
|
1575
1633
|
|
|
1576
1634
|
// If replaced by same file reconnecting (e.g., plugin reloaded), stop
|
|
@@ -1672,6 +1730,14 @@
|
|
|
1672
1730
|
window.__wsGetActiveConnections = function() { return activeConnections; };
|
|
1673
1731
|
|
|
1674
1732
|
window.__wsDisconnectAll = function() {
|
|
1733
|
+
for (var cPort in connectingSockets) {
|
|
1734
|
+
if (Object.prototype.hasOwnProperty.call(connectingSockets, cPort)) {
|
|
1735
|
+
var cEntry = connectingSockets[cPort];
|
|
1736
|
+
clearTimeout(cEntry.timer);
|
|
1737
|
+
try { cEntry.ws.close(1000, 'Manual disconnect'); } catch (e) {}
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
connectingSockets = {};
|
|
1675
1741
|
for (var i = 0; i < activeConnections.length; i++) {
|
|
1676
1742
|
try { activeConnections[i].ws.close(1000, 'Manual disconnect'); } catch (e) {}
|
|
1677
1743
|
}
|
|
@@ -1982,7 +2048,12 @@
|
|
|
1982
2048
|
}
|
|
1983
2049
|
|
|
1984
2050
|
function escHtml(s) {
|
|
1985
|
-
return s
|
|
2051
|
+
return String(s)
|
|
2052
|
+
.replace(/&/g, '&')
|
|
2053
|
+
.replace(/</g, '<')
|
|
2054
|
+
.replace(/>/g, '>')
|
|
2055
|
+
.replace(/"/g, '"')
|
|
2056
|
+
.replace(/'/g, ''');
|
|
1986
2057
|
}
|
|
1987
2058
|
|
|
1988
2059
|
function log(message, level, ts) {
|
|
@@ -2528,7 +2599,10 @@
|
|
|
2528
2599
|
if (msg.fileContext !== undefined) result.fileContext = msg.fileContext;
|
|
2529
2600
|
request.resolve(result);
|
|
2530
2601
|
} else {
|
|
2531
|
-
|
|
2602
|
+
var errResult = { success: false, error: msg.error || 'Unknown error' };
|
|
2603
|
+
if (msg.data !== undefined) errResult.data = msg.data;
|
|
2604
|
+
if (msg.fileContext !== undefined) errResult.fileContext = msg.fileContext;
|
|
2605
|
+
request.resolve(errResult);
|
|
2532
2606
|
}
|
|
2533
2607
|
window.__figmaPendingRequests.delete(msg.requestId);
|
|
2534
2608
|
}
|
package/package.json
CHANGED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Accessibility Scorer (weight: 0.15)
|
|
3
|
-
*
|
|
4
|
-
* Checks accessibility-related signals in the design system.
|
|
5
|
-
* Evaluates color contrast ratios, state variant coverage,
|
|
6
|
-
* and semantic color naming patterns.
|
|
7
|
-
*/
|
|
8
|
-
import { clamp, getSeverity } from "./types.js";
|
|
9
|
-
/** Maximum examples to include in a finding. */
|
|
10
|
-
const MAX_EXAMPLES = 5;
|
|
11
|
-
/** WCAG AA minimum contrast ratio for normal text. */
|
|
12
|
-
const WCAG_AA_RATIO = 4.5;
|
|
13
|
-
/** State-related variant values that indicate accessible component design. */
|
|
14
|
-
const STATE_VARIANTS = [
|
|
15
|
-
"disabled",
|
|
16
|
-
"error",
|
|
17
|
-
"focus",
|
|
18
|
-
"hover",
|
|
19
|
-
"active",
|
|
20
|
-
"pressed",
|
|
21
|
-
"selected",
|
|
22
|
-
];
|
|
23
|
-
/** Semantic color token name patterns that indicate accessibility awareness. */
|
|
24
|
-
const SEMANTIC_COLOR_NAMES = ["error", "warning", "success", "info", "danger"];
|
|
25
|
-
/**
|
|
26
|
-
* Linearize an sRGB channel value for luminance calculation.
|
|
27
|
-
* Input: channel value in 0-1 range.
|
|
28
|
-
*/
|
|
29
|
-
function linearize(channel) {
|
|
30
|
-
return channel <= 0.04045
|
|
31
|
-
? channel / 12.92
|
|
32
|
-
: ((channel + 0.055) / 1.055) ** 2.4;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Calculate relative luminance of a color.
|
|
36
|
-
* r, g, b are in 0-1 range (as Figma provides them).
|
|
37
|
-
*/
|
|
38
|
-
function luminance(r, g, b) {
|
|
39
|
-
return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Calculate contrast ratio between two colors.
|
|
43
|
-
* Returns a ratio >= 1 (e.g., 4.5 for WCAG AA compliance).
|
|
44
|
-
*/
|
|
45
|
-
function contrastRatio(r1, g1, b1, r2, g2, b2) {
|
|
46
|
-
const lum1 = luminance(r1, g1, b1);
|
|
47
|
-
const lum2 = luminance(r2, g2, b2);
|
|
48
|
-
const lighter = Math.max(lum1, lum2);
|
|
49
|
-
const darker = Math.min(lum1, lum2);
|
|
50
|
-
return (lighter + 0.05) / (darker + 0.05);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Check if a value is a direct color (not an alias).
|
|
54
|
-
*/
|
|
55
|
-
function isDirectColor(value) {
|
|
56
|
-
if (typeof value !== "object" || value === null)
|
|
57
|
-
return false;
|
|
58
|
-
const v = value;
|
|
59
|
-
return (typeof v.r === "number" &&
|
|
60
|
-
typeof v.g === "number" &&
|
|
61
|
-
typeof v.b === "number" &&
|
|
62
|
-
v.type !== "VARIABLE_ALIAS");
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Extract resolved color values from variables.
|
|
66
|
-
* Returns an array of { name, r, g, b } objects for direct color values.
|
|
67
|
-
*/
|
|
68
|
-
function extractColorValues(variables) {
|
|
69
|
-
const colors = [];
|
|
70
|
-
for (const variable of variables) {
|
|
71
|
-
if (variable.resolvedType !== "COLOR" || !variable.valuesByMode)
|
|
72
|
-
continue;
|
|
73
|
-
for (const value of Object.values(variable.valuesByMode)) {
|
|
74
|
-
if (isDirectColor(value)) {
|
|
75
|
-
colors.push({
|
|
76
|
-
name: variable.name,
|
|
77
|
-
r: value.r,
|
|
78
|
-
g: value.g,
|
|
79
|
-
b: value.b,
|
|
80
|
-
});
|
|
81
|
-
break; // Use the first direct color value per variable
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return colors;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Identify likely foreground/background color pairs and check contrast.
|
|
89
|
-
*
|
|
90
|
-
* Strategy: pair colors whose names suggest fg/bg relationships:
|
|
91
|
-
* - Names containing "background"/"bg"/"surface" are backgrounds
|
|
92
|
-
* - Names containing "text"/"foreground"/"fg"/"on" are foregrounds
|
|
93
|
-
* Falls back to pairing dark colors with light colors if no naming convention found.
|
|
94
|
-
*/
|
|
95
|
-
function scoreColorContrast(data) {
|
|
96
|
-
const colors = extractColorValues(data.variables);
|
|
97
|
-
if (colors.length < 2) {
|
|
98
|
-
return {
|
|
99
|
-
id: "a11y-color-contrast",
|
|
100
|
-
label: "Color contrast",
|
|
101
|
-
score: 100,
|
|
102
|
-
severity: "info",
|
|
103
|
-
tooltip: "Foreground/background color pairs should meet WCAG AA contrast ratio (4.5:1). Low contrast makes content unreadable for users with vision impairments.",
|
|
104
|
-
details: colors.length === 0
|
|
105
|
-
? "No direct color values to evaluate."
|
|
106
|
-
: "Only one color found; need at least two to check contrast.",
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
const bgPattern = /background|bg|surface|canvas|base/i;
|
|
110
|
-
const fgPattern = /text|foreground|fg|on-|on\.|label|title|body|heading/i;
|
|
111
|
-
const backgrounds = colors.filter((c) => bgPattern.test(c.name));
|
|
112
|
-
const foregrounds = colors.filter((c) => fgPattern.test(c.name));
|
|
113
|
-
// If naming conventions are not used, use luminance-based heuristic
|
|
114
|
-
let pairs = [];
|
|
115
|
-
if (backgrounds.length > 0 && foregrounds.length > 0) {
|
|
116
|
-
// Pair foregrounds with backgrounds by naming proximity
|
|
117
|
-
for (const fg of foregrounds) {
|
|
118
|
-
for (const bg of backgrounds) {
|
|
119
|
-
pairs.push({ fg, bg });
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
// Heuristic: separate into light (luminance > 0.5) and dark (luminance <= 0.5)
|
|
125
|
-
const lightColors = colors.filter((c) => luminance(c.r, c.g, c.b) > 0.5);
|
|
126
|
-
const darkColors = colors.filter((c) => luminance(c.r, c.g, c.b) <= 0.5);
|
|
127
|
-
for (const dark of darkColors) {
|
|
128
|
-
for (const light of lightColors) {
|
|
129
|
-
pairs.push({ fg: dark, bg: light });
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (pairs.length === 0) {
|
|
134
|
-
return {
|
|
135
|
-
id: "a11y-color-contrast",
|
|
136
|
-
label: "Color contrast",
|
|
137
|
-
score: 50,
|
|
138
|
-
severity: "warning",
|
|
139
|
-
tooltip: "Foreground/background color pairs should meet WCAG AA contrast ratio (4.5:1). Low contrast makes content unreadable for users with vision impairments.",
|
|
140
|
-
details: "Could not identify foreground/background color pairs to check contrast.",
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
// Limit pair evaluation to avoid performance issues with large token sets
|
|
144
|
-
const maxPairs = 50;
|
|
145
|
-
if (pairs.length > maxPairs) {
|
|
146
|
-
pairs = pairs.slice(0, maxPairs);
|
|
147
|
-
}
|
|
148
|
-
let passingPairs = 0;
|
|
149
|
-
const failingExamples = [];
|
|
150
|
-
for (const { fg, bg } of pairs) {
|
|
151
|
-
const ratio = contrastRatio(fg.r, fg.g, fg.b, bg.r, bg.g, bg.b);
|
|
152
|
-
if (ratio >= WCAG_AA_RATIO) {
|
|
153
|
-
passingPairs++;
|
|
154
|
-
}
|
|
155
|
-
else if (failingExamples.length < MAX_EXAMPLES) {
|
|
156
|
-
failingExamples.push(`${fg.name} / ${bg.name} (${ratio.toFixed(1)}:1)`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
const passRatio = passingPairs / pairs.length;
|
|
160
|
-
const score = clamp(passRatio * 100);
|
|
161
|
-
return {
|
|
162
|
-
id: "a11y-color-contrast",
|
|
163
|
-
label: "Color contrast",
|
|
164
|
-
score,
|
|
165
|
-
severity: getSeverity(score),
|
|
166
|
-
tooltip: "Foreground/background color pairs should meet WCAG AA contrast ratio (4.5:1). Low contrast makes content unreadable for users with vision impairments.",
|
|
167
|
-
details: `${passingPairs} of ${pairs.length} color pairs meet WCAG AA contrast ratio (${WCAG_AA_RATIO}:1).`,
|
|
168
|
-
examples: failingExamples.length > 0 ? failingExamples : undefined,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Score state variant coverage.
|
|
173
|
-
* Components should include state-related variants for accessibility.
|
|
174
|
-
*/
|
|
175
|
-
function scoreStateVariants(data) {
|
|
176
|
-
const components = data.components;
|
|
177
|
-
if (components.length === 0) {
|
|
178
|
-
return {
|
|
179
|
-
id: "a11y-state-variants",
|
|
180
|
-
label: "State variants",
|
|
181
|
-
score: 100,
|
|
182
|
-
severity: "info",
|
|
183
|
-
tooltip: "Interactive components should include state variants (disabled, error, focus, hover, active, pressed, selected) for accessible interactions.",
|
|
184
|
-
details: "No components to evaluate.",
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
// Check which state variants exist across all component names
|
|
188
|
-
const allNames = components.map((c) => c.name.toLowerCase()).join(" ");
|
|
189
|
-
const foundStates = STATE_VARIANTS.filter((state) => allNames.includes(state));
|
|
190
|
-
const ratio = foundStates.length / STATE_VARIANTS.length;
|
|
191
|
-
const score = clamp(ratio * 100);
|
|
192
|
-
const missingStates = STATE_VARIANTS.filter((state) => !allNames.includes(state));
|
|
193
|
-
return {
|
|
194
|
-
id: "a11y-state-variants",
|
|
195
|
-
label: "State variants",
|
|
196
|
-
score,
|
|
197
|
-
severity: getSeverity(score),
|
|
198
|
-
tooltip: "Interactive components should include state variants (disabled, error, focus, hover, active, pressed, selected) for accessible interactions.",
|
|
199
|
-
details: missingStates.length > 0
|
|
200
|
-
? `Found ${foundStates.length} of ${STATE_VARIANTS.length} state variants. Missing: ${missingStates.join(", ")}.`
|
|
201
|
-
: `All ${STATE_VARIANTS.length} state variants are represented.`,
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Score semantic color naming.
|
|
206
|
-
* The token set should include semantic color tokens for error/warning/success/info.
|
|
207
|
-
*/
|
|
208
|
-
function variableDataUnavailable(data) {
|
|
209
|
-
return (data.dataAvailability !== undefined && !data.dataAvailability.variables);
|
|
210
|
-
}
|
|
211
|
-
function scoreSemanticColorNaming(data) {
|
|
212
|
-
const colorVars = data.variables.filter((v) => v.resolvedType === "COLOR");
|
|
213
|
-
if (colorVars.length === 0) {
|
|
214
|
-
const unavailable = variableDataUnavailable(data);
|
|
215
|
-
return {
|
|
216
|
-
id: "a11y-semantic-colors",
|
|
217
|
-
label: "Semantic color naming",
|
|
218
|
-
score: 0,
|
|
219
|
-
severity: unavailable ? "info" : "fail",
|
|
220
|
-
tooltip: "The token set should include semantic color categories (error, warning, success, info, danger) to convey meaning beyond color alone.",
|
|
221
|
-
details: unavailable
|
|
222
|
-
? `Variable data unavailable: ${data.dataAvailability?.variableError || "Requires Desktop Bridge or Enterprise plan."}`
|
|
223
|
-
: "No color variables found.",
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
const foundSemantic = [];
|
|
227
|
-
const missingSemantic = [];
|
|
228
|
-
const semanticExamples = [];
|
|
229
|
-
for (const name of SEMANTIC_COLOR_NAMES) {
|
|
230
|
-
const matching = colorVars.filter((v) => v.name.toLowerCase().includes(name));
|
|
231
|
-
if (matching.length > 0) {
|
|
232
|
-
foundSemantic.push(name);
|
|
233
|
-
semanticExamples.push(`${name}: ${matching
|
|
234
|
-
.slice(0, 2)
|
|
235
|
-
.map((v) => v.name)
|
|
236
|
-
.join(", ")}`);
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
missingSemantic.push(name);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const ratio = foundSemantic.length / SEMANTIC_COLOR_NAMES.length;
|
|
243
|
-
const score = clamp(ratio * 100);
|
|
244
|
-
return {
|
|
245
|
-
id: "a11y-semantic-colors",
|
|
246
|
-
label: "Semantic color naming",
|
|
247
|
-
score,
|
|
248
|
-
severity: getSeverity(score),
|
|
249
|
-
tooltip: "The token set should include semantic color categories (error, warning, success, info, danger) to convey meaning beyond color alone.",
|
|
250
|
-
details: missingSemantic.length > 0
|
|
251
|
-
? `Found ${foundSemantic.length} of ${SEMANTIC_COLOR_NAMES.length} semantic color categories. Missing: ${missingSemantic.join(", ")}.`
|
|
252
|
-
: "All semantic color categories (error, warning, success, info, danger) are present.",
|
|
253
|
-
examples: semanticExamples.length > 0
|
|
254
|
-
? semanticExamples.slice(0, MAX_EXAMPLES)
|
|
255
|
-
: undefined,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Accessibility category scorer.
|
|
260
|
-
* Returns the average score across all accessibility checks.
|
|
261
|
-
*/
|
|
262
|
-
export function scoreAccessibility(data) {
|
|
263
|
-
const findings = [
|
|
264
|
-
scoreColorContrast(data),
|
|
265
|
-
scoreStateVariants(data),
|
|
266
|
-
scoreSemanticColorNaming(data),
|
|
267
|
-
];
|
|
268
|
-
const score = clamp(findings.reduce((sum, f) => sum + f.score, 0) / findings.length);
|
|
269
|
-
return {
|
|
270
|
-
id: "accessibility",
|
|
271
|
-
label: "Accessibility",
|
|
272
|
-
shortLabel: "Accessibility",
|
|
273
|
-
score,
|
|
274
|
-
weight: 0.15,
|
|
275
|
-
findings,
|
|
276
|
-
};
|
|
277
|
-
}
|