@vettvangur/design-system 2.0.59 → 2.0.60
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/dist/index.js +50 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2444,6 +2444,15 @@ const extractVariantColors = variantNode => {
|
|
|
2444
2444
|
}
|
|
2445
2445
|
return false;
|
|
2446
2446
|
};
|
|
2447
|
+
const getArea = node => {
|
|
2448
|
+
const box = node?.absoluteBoundingBox;
|
|
2449
|
+
const w = typeof box?.width === 'number' ? box.width : null;
|
|
2450
|
+
const h = typeof box?.height === 'number' ? box.height : null;
|
|
2451
|
+
if (w === null || h === null) {
|
|
2452
|
+
return 0;
|
|
2453
|
+
}
|
|
2454
|
+
return Math.max(0, w) * Math.max(0, h);
|
|
2455
|
+
};
|
|
2447
2456
|
const getFillToken = node => {
|
|
2448
2457
|
const fillAlias = Array.isArray(node?.boundVariables?.fills) ? node.boundVariables.fills[0] : null;
|
|
2449
2458
|
const fillVar = fillAlias?.variable;
|
|
@@ -2454,14 +2463,6 @@ const extractVariantColors = variantNode => {
|
|
|
2454
2463
|
const strokeVar = strokeAlias?.variable;
|
|
2455
2464
|
return strokeVar?.resolvedType === 'COLOR' && strokeVar?.nameKebab ? strokeVar.nameKebab : null;
|
|
2456
2465
|
};
|
|
2457
|
-
const isIconNode = node => {
|
|
2458
|
-
const name = typeof node?.name === 'string' ? node.name : '';
|
|
2459
|
-
return /\bicon\b/i.test(name);
|
|
2460
|
-
};
|
|
2461
|
-
const isRootBgNode = node => {
|
|
2462
|
-
const name = typeof node?.name === 'string' ? node.name : '';
|
|
2463
|
-
return /\b(background|container|base|bg)\b/i.test(name);
|
|
2464
|
-
};
|
|
2465
2466
|
const root = {
|
|
2466
2467
|
bg: null,
|
|
2467
2468
|
border: null,
|
|
@@ -2470,16 +2471,9 @@ const extractVariantColors = variantNode => {
|
|
|
2470
2471
|
const icon = {
|
|
2471
2472
|
bg: null
|
|
2472
2473
|
};
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
root.bg = hasVisibleFill(variantNode) ? getFillToken(variantNode) : null;
|
|
2477
|
-
root.border = getStrokeToken(variantNode);
|
|
2478
|
-
}
|
|
2479
|
-
let fallbackRootBg = null;
|
|
2480
|
-
let namedRootBg = null;
|
|
2481
|
-
let fallbackRootBorder = null;
|
|
2482
|
-
let namedRootBorder = null;
|
|
2474
|
+
const fillCandidates = [];
|
|
2475
|
+
const strokeCandidates = [];
|
|
2476
|
+
const rootArea = getArea(variantNode);
|
|
2483
2477
|
walkFigmaNode(variantNode, node => {
|
|
2484
2478
|
if (!node || typeof node !== 'object') {
|
|
2485
2479
|
return;
|
|
@@ -2494,38 +2488,50 @@ const extractVariantColors = variantNode => {
|
|
|
2494
2488
|
if (node?.type === 'TEXT') {
|
|
2495
2489
|
return;
|
|
2496
2490
|
}
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
const t = hasVisibleFill(node) ? getFillToken(node) : null;
|
|
2491
|
+
const area = getArea(node);
|
|
2492
|
+
if (hasVisibleFill(node)) {
|
|
2493
|
+
const t = getFillToken(node);
|
|
2501
2494
|
if (t) {
|
|
2502
|
-
|
|
2495
|
+
fillCandidates.push({
|
|
2496
|
+
token: t,
|
|
2497
|
+
area
|
|
2498
|
+
});
|
|
2503
2499
|
}
|
|
2504
|
-
return;
|
|
2505
2500
|
}
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
if (!namedRootBg && isRootBgNode(node)) {
|
|
2513
|
-
namedRootBg = t;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2501
|
+
const s = getStrokeToken(node);
|
|
2502
|
+
if (s) {
|
|
2503
|
+
strokeCandidates.push({
|
|
2504
|
+
token: s,
|
|
2505
|
+
area
|
|
2506
|
+
});
|
|
2516
2507
|
}
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2508
|
+
});
|
|
2509
|
+
|
|
2510
|
+
// Decide whether the variant has a true button background.
|
|
2511
|
+
// If the only filled element is much smaller than the button itself (common for arrow/icon buttons),
|
|
2512
|
+
// treat it as `.button__icon` background instead.
|
|
2513
|
+
const pickLargest = candidates => {
|
|
2514
|
+
let best = null;
|
|
2515
|
+
for (const c of candidates) {
|
|
2516
|
+
if (!best || c.area > best.area) {
|
|
2517
|
+
best = c;
|
|
2524
2518
|
}
|
|
2525
2519
|
}
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2520
|
+
return best;
|
|
2521
|
+
};
|
|
2522
|
+
const ROOT_BG_RATIO_MIN = 0.6;
|
|
2523
|
+
const bestFill = pickLargest(fillCandidates);
|
|
2524
|
+
const bestStroke = pickLargest(strokeCandidates);
|
|
2525
|
+
const fillRatio = rootArea > 0 && bestFill?.area ? bestFill.area / rootArea : 1;
|
|
2526
|
+
if (bestFill && fillRatio >= ROOT_BG_RATIO_MIN) {
|
|
2527
|
+
root.bg = bestFill.token;
|
|
2528
|
+
} else if (bestFill) {
|
|
2529
|
+
icon.bg = bestFill.token;
|
|
2530
|
+
}
|
|
2531
|
+
const strokeRatio = rootArea > 0 && bestStroke?.area ? bestStroke.area / rootArea : 1;
|
|
2532
|
+
if (bestStroke && strokeRatio >= ROOT_BG_RATIO_MIN) {
|
|
2533
|
+
root.border = bestStroke.token;
|
|
2534
|
+
}
|
|
2529
2535
|
return {
|
|
2530
2536
|
root,
|
|
2531
2537
|
icon
|