@vettvangur/design-system 2.0.49 → 2.0.50

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.
Files changed (2) hide show
  1. package/dist/index.js +71 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2404,8 +2404,57 @@ const extractButtonGroupsByComponentSet = (nodesResponse, {
2404
2404
  });
2405
2405
  return groups;
2406
2406
  };
2407
- function renderUtility(name) {
2408
- return `@utility ${name} {\n @apply button;\n\n &:not([disabled]):hover {\n \n }\n}\n`;
2407
+ const extractVariantColors = variantNode => {
2408
+ if (!variantNode || typeof variantNode !== 'object') {
2409
+ return {
2410
+ bg: null,
2411
+ border: null,
2412
+ text: null
2413
+ };
2414
+ }
2415
+ let bg = null;
2416
+ let border = null;
2417
+ let text = null;
2418
+ walkFigmaNode(variantNode, node => {
2419
+ if (!node || typeof node !== 'object') {
2420
+ return;
2421
+ }
2422
+ if (!bg && node?.type !== 'TEXT') {
2423
+ const fillAlias = Array.isArray(node?.boundVariables?.fills) ? node.boundVariables.fills[0] : null;
2424
+ const fillVar = fillAlias?.variable;
2425
+ if (fillVar?.resolvedType === 'COLOR' && fillVar?.nameKebab) {
2426
+ bg = fillVar.nameKebab;
2427
+ }
2428
+ }
2429
+ if (!border && node?.type !== 'TEXT') {
2430
+ const strokeAlias = Array.isArray(node?.boundVariables?.strokes) ? node.boundVariables.strokes[0] : null;
2431
+ const strokeVar = strokeAlias?.variable;
2432
+ if (strokeVar?.resolvedType === 'COLOR' && strokeVar?.nameKebab) {
2433
+ border = strokeVar.nameKebab;
2434
+ }
2435
+ }
2436
+ if (!text && node?.type === 'TEXT') {
2437
+ const textFillAlias = Array.isArray(node?.boundVariables?.fills) ? node.boundVariables.fills[0] : null;
2438
+ const textFillVar = textFillAlias?.variable;
2439
+ if (textFillVar?.resolvedType === 'COLOR' && textFillVar?.nameKebab) {
2440
+ text = textFillVar.nameKebab;
2441
+ }
2442
+ }
2443
+ });
2444
+ return {
2445
+ bg,
2446
+ border,
2447
+ text
2448
+ };
2449
+ };
2450
+ const renderApplyLine = (prefix, token) => token ? ` @apply ${prefix}-${token};\n` : '';
2451
+ function renderUtility(name, base, hover) {
2452
+ const baseLines = renderApplyLine('bg', base?.bg) + renderApplyLine('border', base?.border) + renderApplyLine('text', base?.text);
2453
+ const hoverBg = hover?.bg && hover.bg !== base?.bg ? hover.bg : null;
2454
+ const hoverBorder = hover?.border && hover.border !== base?.border ? hover.border : null;
2455
+ const hoverText = hover?.text && hover.text !== base?.text ? hover.text : null;
2456
+ const hoverLines = renderApplyLine('bg', hoverBg) + renderApplyLine('border', hoverBorder) + renderApplyLine('text', hoverText);
2457
+ return `@utility ${name} {\n @apply button;\n${baseLines}\n &:not([disabled]):hover {\n${hoverLines} }\n}\n`;
2409
2458
  }
2410
2459
  async function generateButtons$1(_components, config) {
2411
2460
  message('generating buttons (from figma Buttons page)...');
@@ -2438,19 +2487,29 @@ async function generateButtons$1(_components, config) {
2438
2487
  pageNodeId,
2439
2488
  groups
2440
2489
  }, null, 2)}\n`, 'utf8');
2441
- const utilityNames = [];
2490
+ const blocks = [];
2442
2491
  for (const group of groups) {
2443
- const setKey = group.componentSet?.nameKebab;
2444
- for (const variant of group.componentSet?.variants ?? []) {
2445
- const variantKey = variant?.nameKebab;
2446
- if (!setKey || !variantKey) {
2447
- continue;
2492
+ const rawSetKey = group.componentSet?.nameKebab;
2493
+ const setKey = typeof rawSetKey === 'string' ? rawSetKey.replace(/^button-/, '') : null;
2494
+ if (!setKey) {
2495
+ continue;
2496
+ }
2497
+ const variants = Array.isArray(group.componentSet?.variants) ? group.componentSet.variants : [];
2498
+ const byState = new Map();
2499
+ for (const v of variants) {
2500
+ const k = typeof v?.nameKebab === 'string' ? v.nameKebab : null;
2501
+ if (k) {
2502
+ byState.set(k, v);
2448
2503
  }
2449
- utilityNames.push(`button-${setKey}-${variantKey}`);
2450
2504
  }
2451
- }
2452
- const blocks = Array.from(new Set(utilityNames)).sort().map(renderUtility);
2453
- const css = `/* AUTO-GENERATED ONCE - Safe to edit */\n${blocks.join('\n')}`;
2505
+ const defaultVariant = byState.get('default') ?? variants[0] ?? null;
2506
+ const hoverVariant = byState.get('hover') ?? null;
2507
+ const base = extractVariantColors(defaultVariant);
2508
+ const hover = hoverVariant ? extractVariantColors(hoverVariant) : null;
2509
+ const utilityName = `button-${setKey}`;
2510
+ blocks.push(renderUtility(utilityName, base, hover));
2511
+ }
2512
+ const css = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n${blocks.join('\n')}`;
2454
2513
  const outPath = path.join(coreOutDir, 'button-variants.css');
2455
2514
  await fs$1.writeFile(outPath, css, 'utf8');
2456
2515
  message(`finished generating button variants (count=${blocks.length})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vettvangur/design-system",
3
- "version": "2.0.49",
3
+ "version": "2.0.50",
4
4
  "description": "",
5
5
  "access": "public",
6
6
  "type": "module",