@vettvangur/design-system 2.0.59 → 2.0.61
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 +59 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1759,6 +1759,15 @@ function groupTypography(variableSet) {
|
|
|
1759
1759
|
message('grouping typography...');
|
|
1760
1760
|
const col = variableSet.typography;
|
|
1761
1761
|
const toks = col?.tokens || {};
|
|
1762
|
+
if (process$1.env.DS_DEBUG) {
|
|
1763
|
+
const keys = Object.keys(toks);
|
|
1764
|
+
console.log('[design-system] typography: token count =', keys.length);
|
|
1765
|
+
if (keys.length) {
|
|
1766
|
+
console.log('[design-system] typography: token key sample =', keys.slice(0, 25).join(', '));
|
|
1767
|
+
const ff = keys.filter(k => k.startsWith('font-family-'));
|
|
1768
|
+
console.log('[design-system] typography: font-family key sample =', ff.slice(0, 25).join(', '));
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1762
1771
|
const out = {
|
|
1763
1772
|
families: {},
|
|
1764
1773
|
weights: {},
|
|
@@ -2444,6 +2453,15 @@ const extractVariantColors = variantNode => {
|
|
|
2444
2453
|
}
|
|
2445
2454
|
return false;
|
|
2446
2455
|
};
|
|
2456
|
+
const getArea = node => {
|
|
2457
|
+
const box = node?.absoluteBoundingBox;
|
|
2458
|
+
const w = typeof box?.width === 'number' ? box.width : null;
|
|
2459
|
+
const h = typeof box?.height === 'number' ? box.height : null;
|
|
2460
|
+
if (w === null || h === null) {
|
|
2461
|
+
return 0;
|
|
2462
|
+
}
|
|
2463
|
+
return Math.max(0, w) * Math.max(0, h);
|
|
2464
|
+
};
|
|
2447
2465
|
const getFillToken = node => {
|
|
2448
2466
|
const fillAlias = Array.isArray(node?.boundVariables?.fills) ? node.boundVariables.fills[0] : null;
|
|
2449
2467
|
const fillVar = fillAlias?.variable;
|
|
@@ -2454,14 +2472,6 @@ const extractVariantColors = variantNode => {
|
|
|
2454
2472
|
const strokeVar = strokeAlias?.variable;
|
|
2455
2473
|
return strokeVar?.resolvedType === 'COLOR' && strokeVar?.nameKebab ? strokeVar.nameKebab : null;
|
|
2456
2474
|
};
|
|
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
2475
|
const root = {
|
|
2466
2476
|
bg: null,
|
|
2467
2477
|
border: null,
|
|
@@ -2470,16 +2480,9 @@ const extractVariantColors = variantNode => {
|
|
|
2470
2480
|
const icon = {
|
|
2471
2481
|
bg: null
|
|
2472
2482
|
};
|
|
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;
|
|
2483
|
+
const fillCandidates = [];
|
|
2484
|
+
const strokeCandidates = [];
|
|
2485
|
+
const rootArea = getArea(variantNode);
|
|
2483
2486
|
walkFigmaNode(variantNode, node => {
|
|
2484
2487
|
if (!node || typeof node !== 'object') {
|
|
2485
2488
|
return;
|
|
@@ -2494,38 +2497,50 @@ const extractVariantColors = variantNode => {
|
|
|
2494
2497
|
if (node?.type === 'TEXT') {
|
|
2495
2498
|
return;
|
|
2496
2499
|
}
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
const t = hasVisibleFill(node) ? getFillToken(node) : null;
|
|
2500
|
+
const area = getArea(node);
|
|
2501
|
+
if (hasVisibleFill(node)) {
|
|
2502
|
+
const t = getFillToken(node);
|
|
2501
2503
|
if (t) {
|
|
2502
|
-
|
|
2504
|
+
fillCandidates.push({
|
|
2505
|
+
token: t,
|
|
2506
|
+
area
|
|
2507
|
+
});
|
|
2503
2508
|
}
|
|
2504
|
-
return;
|
|
2505
2509
|
}
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
if (!namedRootBg && isRootBgNode(node)) {
|
|
2513
|
-
namedRootBg = t;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2510
|
+
const s = getStrokeToken(node);
|
|
2511
|
+
if (s) {
|
|
2512
|
+
strokeCandidates.push({
|
|
2513
|
+
token: s,
|
|
2514
|
+
area
|
|
2515
|
+
});
|
|
2516
2516
|
}
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2517
|
+
});
|
|
2518
|
+
|
|
2519
|
+
// Decide whether the variant has a true button background.
|
|
2520
|
+
// If the only filled element is much smaller than the button itself (common for arrow/icon buttons),
|
|
2521
|
+
// treat it as `.button__icon` background instead.
|
|
2522
|
+
const pickLargest = candidates => {
|
|
2523
|
+
let best = null;
|
|
2524
|
+
for (const c of candidates) {
|
|
2525
|
+
if (!best || c.area > best.area) {
|
|
2526
|
+
best = c;
|
|
2524
2527
|
}
|
|
2525
2528
|
}
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
+
return best;
|
|
2530
|
+
};
|
|
2531
|
+
const ROOT_BG_RATIO_MIN = 0.6;
|
|
2532
|
+
const bestFill = pickLargest(fillCandidates);
|
|
2533
|
+
const bestStroke = pickLargest(strokeCandidates);
|
|
2534
|
+
const fillRatio = rootArea > 0 && bestFill?.area ? bestFill.area / rootArea : 1;
|
|
2535
|
+
if (bestFill && fillRatio >= ROOT_BG_RATIO_MIN) {
|
|
2536
|
+
root.bg = bestFill.token;
|
|
2537
|
+
} else if (bestFill) {
|
|
2538
|
+
icon.bg = bestFill.token;
|
|
2539
|
+
}
|
|
2540
|
+
const strokeRatio = rootArea > 0 && bestStroke?.area ? bestStroke.area / rootArea : 1;
|
|
2541
|
+
if (bestStroke && strokeRatio >= ROOT_BG_RATIO_MIN) {
|
|
2542
|
+
root.border = bestStroke.token;
|
|
2543
|
+
}
|
|
2529
2544
|
return {
|
|
2530
2545
|
root,
|
|
2531
2546
|
icon
|