@vettvangur/design-system 2.0.49 → 2.0.51

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 +79 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2404,8 +2404,65 @@ 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) => {
2451
+ if (!token) {
2452
+ return '';
2453
+ }
2454
+ if (prefix === 'text') {
2455
+ return token.startsWith('text-') ? ` @apply ${token};\n` : ` @apply text-${token};\n`;
2456
+ }
2457
+ return ` @apply ${prefix}-${token};\n`;
2458
+ };
2459
+ function renderUtility(name, base, hover) {
2460
+ const baseLines = renderApplyLine('bg', base?.bg) + renderApplyLine('border', base?.border) + renderApplyLine('text', base?.text);
2461
+ const hoverBg = hover?.bg && hover.bg !== base?.bg ? hover.bg : null;
2462
+ const hoverBorder = hover?.border && hover.border !== base?.border ? hover.border : null;
2463
+ const hoverText = hover?.text && hover.text !== base?.text ? hover.text : null;
2464
+ const hoverLines = renderApplyLine('bg', hoverBg) + renderApplyLine('border', hoverBorder) + renderApplyLine('text', hoverText);
2465
+ return `@utility ${name} {\n @apply button;\n${baseLines}\n &:not([disabled]):hover {\n${hoverLines} }\n}\n`;
2409
2466
  }
2410
2467
  async function generateButtons$1(_components, config) {
2411
2468
  message('generating buttons (from figma Buttons page)...');
@@ -2438,19 +2495,29 @@ async function generateButtons$1(_components, config) {
2438
2495
  pageNodeId,
2439
2496
  groups
2440
2497
  }, null, 2)}\n`, 'utf8');
2441
- const utilityNames = [];
2498
+ const blocks = [];
2442
2499
  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;
2500
+ const rawSetKey = group.componentSet?.nameKebab;
2501
+ const setKey = typeof rawSetKey === 'string' ? rawSetKey.replace(/^button-/, '') : null;
2502
+ if (!setKey) {
2503
+ continue;
2504
+ }
2505
+ const variants = Array.isArray(group.componentSet?.variants) ? group.componentSet.variants : [];
2506
+ const byState = new Map();
2507
+ for (const v of variants) {
2508
+ const k = typeof v?.nameKebab === 'string' ? v.nameKebab : null;
2509
+ if (k) {
2510
+ byState.set(k, v);
2448
2511
  }
2449
- utilityNames.push(`button-${setKey}-${variantKey}`);
2450
2512
  }
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')}`;
2513
+ const defaultVariant = byState.get('default') ?? variants[0] ?? null;
2514
+ const hoverVariant = byState.get('hover') ?? null;
2515
+ const base = extractVariantColors(defaultVariant);
2516
+ const hover = hoverVariant ? extractVariantColors(hoverVariant) : null;
2517
+ const utilityName = `button-${setKey}`;
2518
+ blocks.push(renderUtility(utilityName, base, hover));
2519
+ }
2520
+ const css = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n${blocks.join('\n')}`;
2454
2521
  const outPath = path.join(coreOutDir, 'button-variants.css');
2455
2522
  await fs$1.writeFile(outPath, css, 'utf8');
2456
2523
  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.51",
4
4
  "description": "",
5
5
  "access": "public",
6
6
  "type": "module",