@yahoo/uds 3.142.0 → 3.144.0

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 (114) hide show
  1. package/dist/automated-config/dist/utils/getConfigVariantProperties.d.cts +2 -2
  2. package/dist/automated-config/dist/utils/getConfigVariantProperties.d.ts +2 -2
  3. package/dist/components/client/Popover/UDSPopoverConfigProvider.d.cts +1 -1
  4. package/dist/components/client/Popover/UDSPopoverConfigProvider.d.ts +1 -1
  5. package/dist/components/client/Toast/UDSToastConfigProvider.d.cts +1 -1
  6. package/dist/components/client/Toast/UDSToastConfigProvider.d.ts +1 -1
  7. package/dist/styles/styler.d.cts +54 -54
  8. package/dist/styles/styler.d.ts +54 -54
  9. package/dist/tailwind/dist/automated-config/dist/mapTextVariantFixtureToValue.js.map +1 -1
  10. package/dist/tailwind/dist/automated-config/dist/properties.js.map +1 -1
  11. package/dist/tailwind/dist/automated-config/dist/utils/assertUnreachable.js.map +1 -1
  12. package/dist/tailwind/dist/automated-config/dist/utils/generateDefaultClassName.js.map +1 -1
  13. package/dist/tailwind/dist/automated-config/dist/utils/generateSchemaKey.js.map +1 -1
  14. package/dist/tailwind/dist/automated-config/dist/utils/index.js.map +1 -1
  15. package/dist/tailwind/dist/automated-config/dist/utils/mapColorFixtureToValue.js.map +1 -1
  16. package/dist/tailwind/dist/cli/dist/lib/logger.js.map +1 -1
  17. package/dist/tailwind/dist/cli/dist/lib/print.js.map +1 -1
  18. package/dist/tailwind/dist/cli/dist/lib/spinner.js.map +1 -1
  19. package/dist/tailwind/dist/commands/css.helpers.js.map +1 -1
  20. package/dist/tailwind/dist/commands/css.js.map +1 -1
  21. package/dist/tailwind/dist/commands/generateComponentData.js.map +1 -1
  22. package/dist/tailwind/dist/commands/generatePurgeCSSData.js.map +1 -1
  23. package/dist/tailwind/dist/commands/purge.js.map +1 -1
  24. package/dist/tailwind/dist/css/generate.helpers.js.map +1 -1
  25. package/dist/tailwind/dist/css/generate.js.map +1 -1
  26. package/dist/tailwind/dist/css/nodeUtils.js.map +1 -1
  27. package/dist/tailwind/dist/css/perf.js.map +1 -1
  28. package/dist/tailwind/dist/css/postcss.helpers.js.map +1 -1
  29. package/dist/tailwind/dist/css/postcss.js.map +1 -1
  30. package/dist/tailwind/dist/css/purgeWorker.js.map +1 -1
  31. package/dist/tailwind/dist/css/runner.helpers.js.map +1 -1
  32. package/dist/tailwind/dist/css/runner.js.map +1 -1
  33. package/dist/tailwind/dist/css/utils.js.map +1 -1
  34. package/dist/tailwind/dist/css/workerPool.js.map +1 -1
  35. package/dist/tailwind/dist/css-tokens/dist/index.js.map +1 -1
  36. package/dist/tailwind/dist/fixtures/dist/index.cjs +0 -10
  37. package/dist/tailwind/dist/fixtures/dist/index.js +0 -10
  38. package/dist/tailwind/dist/fixtures/dist/index.js.map +1 -1
  39. package/dist/tailwind/dist/modes/dist/index.cjs +1 -0
  40. package/dist/tailwind/dist/modes/dist/index.js +1 -0
  41. package/dist/tailwind/dist/modes/dist/index.js.map +1 -1
  42. package/dist/tailwind/dist/plugin.js.map +1 -1
  43. package/dist/tailwind/dist/purger/legacy/purgeCSS.js.map +1 -1
  44. package/dist/tailwind/dist/purger/legacy/purgeFromCode.js.map +1 -1
  45. package/dist/tailwind/dist/purger/optimized/ast/expressions.js.map +1 -1
  46. package/dist/tailwind/dist/purger/optimized/purge.js.map +1 -1
  47. package/dist/tailwind/dist/purger/optimized/purgeFromCode.js.map +1 -1
  48. package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.js.map +1 -1
  49. package/dist/tailwind/dist/purger/optimized/utils/files.js.map +1 -1
  50. package/dist/tailwind/dist/purger/optimized/utils/safelist.js.map +1 -1
  51. package/dist/tailwind/dist/runtimeConfig/hookMetadata.js.map +1 -1
  52. package/dist/tailwind/dist/tailwind/base/addColorModeVars.js.map +1 -1
  53. package/dist/tailwind/dist/tailwind/base/addColorModeVarsV2.js.map +1 -1
  54. package/dist/tailwind/dist/tailwind/base/addFontFaceDeclarations.js.map +1 -1
  55. package/dist/tailwind/dist/tailwind/base/addFontVars.js.map +1 -1
  56. package/dist/tailwind/dist/tailwind/base/addMotionVars.js.map +1 -1
  57. package/dist/tailwind/dist/tailwind/base/addScaleModeVars.js.map +1 -1
  58. package/dist/tailwind/dist/tailwind/components/getFocusRingStyles.js.map +1 -1
  59. package/dist/tailwind/dist/tailwind/components/getHitTargetStyles.js.map +1 -1
  60. package/dist/tailwind/dist/tailwind/components/getIconStyles.js.map +1 -1
  61. package/dist/tailwind/dist/tailwind/components/getInputStyles.js.map +1 -1
  62. package/dist/tailwind/dist/tailwind/components/getResponsiveTextStyles.js.map +1 -1
  63. package/dist/tailwind/dist/tailwind/plugins/a11y.js.map +1 -1
  64. package/dist/tailwind/dist/tailwind/plugins/blurBgFallback.js.map +1 -1
  65. package/dist/tailwind/dist/tailwind/plugins/borderRadius.js.map +1 -1
  66. package/dist/tailwind/dist/tailwind/plugins/borderWidth.js.map +1 -1
  67. package/dist/tailwind/dist/tailwind/plugins/breakpoints.js.map +1 -1
  68. package/dist/tailwind/dist/tailwind/plugins/colors.js.map +1 -1
  69. package/dist/tailwind/dist/tailwind/plugins/components.js.map +1 -1
  70. package/dist/tailwind/dist/tailwind/plugins/elevation.js.map +1 -1
  71. package/dist/tailwind/dist/tailwind/plugins/getTailwindAsUdsColors.js.map +1 -1
  72. package/dist/tailwind/dist/tailwind/plugins/icons.js.map +1 -1
  73. package/dist/tailwind/dist/tailwind/plugins/input.js.map +1 -1
  74. package/dist/tailwind/dist/tailwind/plugins/motion.js.map +1 -1
  75. package/dist/tailwind/dist/tailwind/plugins/nestedBorderRadius.js.map +1 -1
  76. package/dist/tailwind/dist/tailwind/plugins/scaleMode.js.map +1 -1
  77. package/dist/tailwind/dist/tailwind/plugins/shadows.js.map +1 -1
  78. package/dist/tailwind/dist/tailwind/plugins/sizing.js.map +1 -1
  79. package/dist/tailwind/dist/tailwind/plugins/typography.js.map +1 -1
  80. package/dist/tailwind/dist/tailwind/theme/getFontFamilyTheme.js.map +1 -1
  81. package/dist/tailwind/dist/tailwind/utils/addFontsPlugin.js.map +1 -1
  82. package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.js.map +1 -1
  83. package/dist/tailwind/dist/tailwind/utils/getColorModeStyles.js.map +1 -1
  84. package/dist/tailwind/dist/tailwind/utils/getElevationStyles.js.map +1 -1
  85. package/dist/tailwind/dist/tailwind/utils/getFontFaceDeclarations.js.map +1 -1
  86. package/dist/tailwind/dist/tailwind/utils/getFontStyles.js.map +1 -1
  87. package/dist/tailwind/dist/tailwind/utils/getMotionStyles.js.map +1 -1
  88. package/dist/tailwind/dist/tailwind/utils/getNestedBorderRadiusUtilities.js.map +1 -1
  89. package/dist/tailwind/dist/tailwind/utils/getScaleModeStyles.js.map +1 -1
  90. package/dist/tailwind/dist/tailwind/utils/getShadowPresetValues.js.map +1 -1
  91. package/dist/tailwind/dist/tailwind/utils/getShadowStyles.d.cts +4 -4
  92. package/dist/tailwind/dist/tailwind/utils/getShadowStyles.d.ts +4 -4
  93. package/dist/tailwind/dist/tailwind/utils/getShadowStyles.js.map +1 -1
  94. package/dist/tailwind/dist/utils/assertUnreachable.js.map +1 -1
  95. package/dist/tailwind/dist/utils/entries.js.map +1 -1
  96. package/dist/tailwind/dist/utils/entryPoints.js.map +1 -1
  97. package/dist/tailwind/dist/utils/fromEntries.js.map +1 -1
  98. package/dist/tailwind/dist/utils/generatePurgeCSSData.js.map +1 -1
  99. package/dist/tailwind/dist/utils/mapValues.js.map +1 -1
  100. package/dist/tailwind/dist/utils/opacity.js.map +1 -1
  101. package/dist/tailwind/dist/utils/optimizeCSS.js.map +1 -1
  102. package/dist/tailwind/dist/utils/parseTokens.js.map +1 -1
  103. package/dist/tailwind/dist/utils/postcssPreserveVars.js.map +1 -1
  104. package/dist/tailwind/dist/utils/tsMorph.js.map +1 -1
  105. package/dist/types/dist/index.d.cts +2 -2
  106. package/dist/types/dist/index.d.ts +2 -2
  107. package/dist/uds/generated/componentData.cjs +1371 -1371
  108. package/dist/uds/generated/componentData.js +1371 -1371
  109. package/dist/uds/generated/tailwindPurge.cjs +3 -0
  110. package/dist/uds/generated/tailwindPurge.js +3 -0
  111. package/dist/uds/package.cjs +3 -3
  112. package/dist/uds/package.js +3 -3
  113. package/generated/componentData.json +1749 -1749
  114. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"parseTokens.js","names":[],"sources":["../../src/utils/parseTokens.ts"],"sourcesContent":["import type { UniversalTokensConfig } from '@yahoo/uds-config';\nimport {\n AVATAR_SIZE_PREFIX,\n BACKGROUND_BLUR_FALLBACK_COLOR_PREFIX,\n BACKGROUND_BLUR_RADIUS_PREFIX,\n BACKGROUND_COLOR_PREFIX,\n BORDER_RADIUS_PREFIX,\n BORDER_WIDTH_PREFIX,\n DROP_SHADOW_PREFIX,\n getShadowLayerValue,\n ICON_SIZE_PREFIX,\n INSET_SHADOW_PREFIX,\n LINE_COLOR_PREFIX,\n OUTLINE_PREFIX,\n SPECTRUM_COLOR_PREFIX,\n UDS_PREFIX,\n} from '@yahoo/uds-css-tokens';\nimport { alwaysPalette } from '@yahoo/uds-palette';\nimport type {\n ColorMode,\n ColorsConfig,\n ElevationLevel,\n ElevationPreset,\n FocusRingColor,\n FocusRingConfig,\n Hue,\n HueStep,\n OpacityStep,\n PaletteConfig,\n PaletteType,\n ScaleMode,\n} from '@yahoo/uds-types';\n\nimport { entries } from './entries';\nimport { mapValues } from './mapValues';\nimport { parseOpacityStep } from './opacity';\n\n/** Converts a SpectrumValueEntry to a space-separated RGB string for CSS variables. */\nfunction spectrumValueToRgbString(value: { rgb: { r: number; g: number; b: number } }): string {\n const { r, g, b } = value.rgb;\n return `${r} ${g} ${b}`;\n}\n\nfunction shouldIncludeOpacity(opacity: OpacityStep | undefined): boolean {\n if (!opacity) {\n return false;\n }\n\n const parsedOpacity = parseInt(opacity, 10);\n return !isNaN(parsedOpacity) && parsedOpacity !== 100;\n}\n\ntype ColorModeElevationPresets = Partial<Record<ElevationLevel, ElevationPreset>>;\n\nfunction resolveFocusRingColor(color: FocusRingColor): string {\n switch (color.type) {\n case 'spectrum':\n return `rgb(var(--${SPECTRUM_COLOR_PREFIX}-${color.value.hue}-${color.value.step}))`;\n case 'line':\n return `rgb(var(--${LINE_COLOR_PREFIX}-${color.value}))`;\n case 'always':\n return alwaysPalette[color.value as keyof typeof alwaysPalette];\n default:\n return `rgb(var(--${SPECTRUM_COLOR_PREFIX}-gray-15))`;\n }\n}\n\nfunction transformColors(\n colors: ColorsConfig,\n elevationPresets: ColorModeElevationPresets,\n focusRingConfig?: FocusRingConfig,\n) {\n const { palette, spectrum } = colors;\n const rootVars: Record<string, string> = {};\n const tailwindConfig = {\n spectrum: {} as Record<Hue, Record<HueStep, string>>,\n palette: {} as {\n [key in PaletteType]: Record<keyof PaletteConfig[key], string>;\n },\n };\n\n for (const [hue, hueSteps] of entries(spectrum)) {\n for (const [hueStep, value] of entries(hueSteps)) {\n const name = `${hue}-${hueStep}`;\n const varKey = `--${SPECTRUM_COLOR_PREFIX}-${name}`;\n if (!tailwindConfig.spectrum[hue]) {\n tailwindConfig.spectrum[hue] = {} as Record<HueStep, string>;\n }\n tailwindConfig.spectrum[hue][hueStep] = `rgb(var(${varKey}))`;\n rootVars[varKey] = spectrumValueToRgbString(value);\n }\n }\n\n entries(palette).forEach(([paletteType, paletteConfig]) => {\n for (const [paletteKey, { hue, step, opacity }] of Object.entries(paletteConfig)) {\n if (!(paletteType in tailwindConfig.palette)) {\n // @ts-expect-error we fill this object later\n tailwindConfig.palette[paletteType] = {};\n }\n const name = `--${UDS_PREFIX}-${paletteType}-color-${paletteKey}`;\n rootVars[name] = `var(--${SPECTRUM_COLOR_PREFIX}-${hue}-${step})`;\n const opacityValue = opacity !== undefined ? parseOpacityStep(opacity) : undefined;\n // @ts-expect-error this is fine\n tailwindConfig.palette[paletteType][paletteKey] = shouldIncludeOpacity(opacityValue)\n ? `rgb(var(${name}) / ${opacityValue}%)`\n : `rgb(var(${name}))`;\n }\n });\n\n // Elevation levels\n entries(elevationPresets).forEach(([level, elevationPreset]) => {\n if (elevationPreset) {\n entries(elevationPreset).forEach(([key]) => {\n // background color\n if (key === 'finalBackgroundValue') {\n const { r, g, b, a } = elevationPreset[key];\n const alpha = parseInt(a) / 100;\n const name = `--${BACKGROUND_COLOR_PREFIX}-elevation-${level}`;\n rootVars[name] = `rgba(${r}, ${g}, ${b}, ${alpha})`;\n }\n\n // border color\n if (key === 'borderColor') {\n const name = `--${LINE_COLOR_PREFIX}-elevation-${level}`;\n\n switch (elevationPreset[key].type) {\n case 'always':\n rootVars[name] = alwaysPalette[elevationPreset[key].value];\n break;\n case 'spectrum':\n rootVars[name] =\n `rgb(var(--${SPECTRUM_COLOR_PREFIX}-${elevationPreset[key].value.hue}-${elevationPreset[key].value.step}))`;\n break;\n case 'line':\n rootVars[name] = `rgb(var(--${LINE_COLOR_PREFIX}-${elevationPreset[key].value}))`;\n break;\n }\n }\n\n // border width\n if (key === 'borderWidth') {\n const name = `--${BORDER_WIDTH_PREFIX}-elevation-${level}`;\n rootVars[name] = `var(--${BORDER_WIDTH_PREFIX}-${elevationPreset[key]})`;\n }\n\n // drop shadow\n if (key === 'dropShadow') {\n const name = `--${DROP_SHADOW_PREFIX}-elevation-${level}`;\n const configValue = elevationPreset[key];\n\n rootVars[name] = Array.isArray(configValue)\n ? configValue\n .map((preset, index) =>\n getShadowLayerValue({\n preset,\n prefix: index > 0 ? `${index + 1}` : undefined,\n shadowType: 'drop',\n }),\n )\n .join(', ')\n : `var(--${DROP_SHADOW_PREFIX}-${elevationPreset[key]})`;\n }\n\n // inset shadow\n if (key === 'insetShadow') {\n const name = `--${INSET_SHADOW_PREFIX}-elevation-${level}`;\n const configValue = elevationPreset[key];\n\n rootVars[name] = Array.isArray(configValue)\n ? configValue\n .map((preset, index) =>\n getShadowLayerValue({\n preset,\n prefix: index > 0 ? `${index + 1}` : undefined,\n shadowType: 'inset',\n }),\n )\n .join(', ')\n : `var(--${INSET_SHADOW_PREFIX}-${elevationPreset[key]})`;\n }\n\n // background blur radius\n if (key === 'backgroundBlurRadius') {\n const name = `--${BACKGROUND_BLUR_RADIUS_PREFIX}-elevation-${level}`;\n rootVars[name] = `blur(${elevationPreset[key]}px)`;\n }\n\n // background blur fallback value\n if (key === 'fallbackBlurredBackgroundValue') {\n const { r, g, b } = elevationPreset[key];\n const name = `--${BACKGROUND_BLUR_FALLBACK_COLOR_PREFIX}-elevation-${level}`;\n rootVars[name] = `rgb(${r}, ${g}, ${b})`;\n }\n });\n }\n });\n\n rootVars[`--${OUTLINE_PREFIX}-offset`] = focusRingConfig ? `${focusRingConfig.offset}px` : '2px';\n rootVars[`--${OUTLINE_PREFIX}-width`] = focusRingConfig ? `${focusRingConfig.width}px` : '2px';\n rootVars[`--${OUTLINE_PREFIX}-style`] = 'solid';\n rootVars[`--${OUTLINE_PREFIX}-color`] = focusRingConfig\n ? resolveFocusRingColor(focusRingConfig.color)\n : `rgb(var(--${SPECTRUM_COLOR_PREFIX}-gray-15))`;\n\n return {\n _vars: rootVars,\n _raw: colors,\n tailwindConfig,\n };\n}\n\nfunction transformNumericToPx<T extends Record<string, number>>(prefix: string, config: T) {\n if (!config) {\n return {\n _vars: {} as Record<string, string>,\n _raw: {} as Record<string, number>,\n tailwindConfig: {} as Record<string, string>,\n };\n }\n const rootVars: Record<string, string> = {};\n const tailwindConfig = {} as Record<string, string>;\n for (const [variant, value] of entries(config)) {\n const rootVarKey = `--${prefix}-${variant}`;\n const rootVarValue = `${value}px`;\n rootVars[rootVarKey] = rootVarValue;\n tailwindConfig[variant] = `var(${rootVarKey})`;\n }\n return {\n _vars: rootVars,\n _raw: config,\n tailwindConfig,\n };\n}\n\ntype WebTokens = Omit<UniversalTokensConfig, 'colorMode' | 'scaleMode' | 'fontFamily'> & {\n colorMode: Record<ColorMode, ReturnType<typeof transformColors>>;\n scaleMode: Record<\n ScaleMode,\n {\n borderRadius: ReturnType<typeof transformNumericToPx>;\n borderWidth: ReturnType<typeof transformNumericToPx>;\n avatarSizes: ReturnType<typeof transformNumericToPx>;\n iconSizes: ReturnType<typeof transformNumericToPx>;\n }\n >;\n};\n\nfunction getElevationPresetsForColorMode(\n colorMode: ColorMode,\n config: UniversalTokensConfig,\n): ColorModeElevationPresets {\n if (!config.elevation) {\n return {};\n }\n\n const result: ColorModeElevationPresets = {};\n\n entries(config.elevation).forEach(([level, levelPreset]) => {\n result[level] = levelPreset[colorMode];\n });\n\n return result;\n}\n\nexport function parseTokens(config: UniversalTokensConfig): WebTokens {\n const { colorMode, scaleMode } = config;\n\n return {\n ...config,\n colorMode: {\n light: transformColors(\n colorMode.light,\n getElevationPresetsForColorMode('light', config),\n config.focusRing?.light,\n ),\n dark: transformColors(\n colorMode.dark,\n getElevationPresetsForColorMode('dark', config),\n config.focusRing?.dark,\n ),\n },\n scaleMode: mapValues(scaleMode, ({ borderRadius, borderWidth, avatarSizes, iconSizes }) => {\n return {\n borderRadius: transformNumericToPx(BORDER_RADIUS_PREFIX, borderRadius),\n borderWidth: transformNumericToPx(BORDER_WIDTH_PREFIX, borderWidth),\n avatarSizes: transformNumericToPx(AVATAR_SIZE_PREFIX, avatarSizes),\n iconSizes: transformNumericToPx(ICON_SIZE_PREFIX, iconSizes),\n };\n }),\n };\n}\n\nexport { type WebTokens };\n"],"mappings":";;;;;;;;AAsCA,SAAS,yBAAyB,OAA6D;CAC7F,MAAM,EAAE,GAAG,GAAG,MAAM,MAAM;AAC1B,QAAO,GAAG,EAAE,GAAG,EAAE,GAAG;;AAGtB,SAAS,qBAAqB,SAA2C;AACvE,KAAI,CAAC,QACH,QAAO;CAGT,MAAM,gBAAgB,SAAS,SAAS,GAAG;AAC3C,QAAO,CAAC,MAAM,cAAc,IAAI,kBAAkB;;AAKpD,SAAS,sBAAsB,OAA+B;AAC5D,SAAQ,MAAM,MAAd;EACE,KAAK,WACH,QAAO,aAAa,sBAAsB,GAAG,MAAM,MAAM,IAAI,GAAG,M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AAE,WAAW,cAAc;AAEjC,QAAO;EACL,GAAG;EACH,WAAW;GACT,OAAO,gBACL,UAAU,OACV,gCAAgC,SAAS,OAAO,EAChD,OAAO,WAAW,MACnB;GACD,MAAM,gBACJ,UAAU,MACV,gCAAgC,QAAQ,OAAO,EAC/C,OAAO,WAAW,KACnB;GACF;EACD,WAAW,UAAU,YAAY,EAAE,cAAc,aAAa,aAAa,gBAAgB;AACzF,UAAO;IACL,cAAc,qBAAqB,sBAAsB,aAAa;IACtE,aAAa,qBAAqB,qBAAqB,YAAY;IACnE,aAAa,qBAAqB,oBAAoB,YAAY;IAClE,WAAW,qBAAqB,kBAAkB,UAAU;IAC7D;IACD;EACH"}
1
+ {"version":3,"file":"parseTokens.js","names":[],"sources":["../../src/utils/parseTokens.ts"],"sourcesContent":["import type { UniversalTokensConfig } from '@yahoo/uds-config';\nimport {\n AVATAR_SIZE_PREFIX,\n BACKGROUND_BLUR_FALLBACK_COLOR_PREFIX,\n BACKGROUND_BLUR_RADIUS_PREFIX,\n BACKGROUND_COLOR_PREFIX,\n BORDER_RADIUS_PREFIX,\n BORDER_WIDTH_PREFIX,\n DROP_SHADOW_PREFIX,\n getShadowLayerValue,\n ICON_SIZE_PREFIX,\n INSET_SHADOW_PREFIX,\n LINE_COLOR_PREFIX,\n OUTLINE_PREFIX,\n SPECTRUM_COLOR_PREFIX,\n UDS_PREFIX,\n} from '@yahoo/uds-css-tokens';\nimport { alwaysPalette } from '@yahoo/uds-palette';\nimport type {\n ColorMode,\n ColorsConfig,\n ElevationLevel,\n ElevationPreset,\n FocusRingColor,\n FocusRingConfig,\n Hue,\n HueStep,\n OpacityStep,\n PaletteConfig,\n PaletteType,\n ScaleMode,\n} from '@yahoo/uds-types';\n\nimport { entries } from './entries';\nimport { mapValues } from './mapValues';\nimport { parseOpacityStep } from './opacity';\n\n/** Converts a SpectrumValueEntry to a space-separated RGB string for CSS variables. */\nfunction spectrumValueToRgbString(value: { rgb: { r: number; g: number; b: number } }): string {\n const { r, g, b } = value.rgb;\n return `${r} ${g} ${b}`;\n}\n\nfunction shouldIncludeOpacity(opacity: OpacityStep | undefined): boolean {\n if (!opacity) {\n return false;\n }\n\n const parsedOpacity = parseInt(opacity, 10);\n return !isNaN(parsedOpacity) && parsedOpacity !== 100;\n}\n\ntype ColorModeElevationPresets = Partial<Record<ElevationLevel, ElevationPreset>>;\n\nfunction resolveFocusRingColor(color: FocusRingColor): string {\n switch (color.type) {\n case 'spectrum':\n return `rgb(var(--${SPECTRUM_COLOR_PREFIX}-${color.value.hue}-${color.value.step}))`;\n case 'line':\n return `rgb(var(--${LINE_COLOR_PREFIX}-${color.value}))`;\n case 'always':\n return alwaysPalette[color.value as keyof typeof alwaysPalette];\n default:\n return `rgb(var(--${SPECTRUM_COLOR_PREFIX}-gray-15))`;\n }\n}\n\nfunction transformColors(\n colors: ColorsConfig,\n elevationPresets: ColorModeElevationPresets,\n focusRingConfig?: FocusRingConfig,\n) {\n const { palette, spectrum } = colors;\n const rootVars: Record<string, string> = {};\n const tailwindConfig = {\n spectrum: {} as Record<Hue, Record<HueStep, string>>,\n palette: {} as {\n [key in PaletteType]: Record<keyof PaletteConfig[key], string>;\n },\n };\n\n for (const [hue, hueSteps] of entries(spectrum)) {\n for (const [hueStep, value] of entries(hueSteps)) {\n const name = `${hue}-${hueStep}`;\n const varKey = `--${SPECTRUM_COLOR_PREFIX}-${name}`;\n if (!tailwindConfig.spectrum[hue]) {\n tailwindConfig.spectrum[hue] = {} as Record<HueStep, string>;\n }\n tailwindConfig.spectrum[hue][hueStep] = `rgb(var(${varKey}))`;\n rootVars[varKey] = spectrumValueToRgbString(value);\n }\n }\n\n entries(palette).forEach(([paletteType, paletteConfig]) => {\n for (const [paletteKey, { hue, step, opacity }] of Object.entries(paletteConfig)) {\n if (!(paletteType in tailwindConfig.palette)) {\n // @ts-expect-error we fill this object later\n tailwindConfig.palette[paletteType] = {};\n }\n const name = `--${UDS_PREFIX}-${paletteType}-color-${paletteKey}`;\n rootVars[name] = `var(--${SPECTRUM_COLOR_PREFIX}-${hue}-${step})`;\n const opacityValue = opacity !== undefined ? parseOpacityStep(opacity) : undefined;\n // @ts-expect-error this is fine\n tailwindConfig.palette[paletteType][paletteKey] = shouldIncludeOpacity(opacityValue)\n ? `rgb(var(${name}) / ${opacityValue}%)`\n : `rgb(var(${name}))`;\n }\n });\n\n // Elevation levels\n entries(elevationPresets).forEach(([level, elevationPreset]) => {\n if (elevationPreset) {\n entries(elevationPreset).forEach(([key]) => {\n // background color\n if (key === 'finalBackgroundValue') {\n const { r, g, b, a } = elevationPreset[key];\n const alpha = parseInt(a) / 100;\n const name = `--${BACKGROUND_COLOR_PREFIX}-elevation-${level}`;\n rootVars[name] = `rgba(${r}, ${g}, ${b}, ${alpha})`;\n }\n\n // border color\n if (key === 'borderColor') {\n const name = `--${LINE_COLOR_PREFIX}-elevation-${level}`;\n\n switch (elevationPreset[key].type) {\n case 'always':\n rootVars[name] = alwaysPalette[elevationPreset[key].value];\n break;\n case 'spectrum':\n rootVars[name] =\n `rgb(var(--${SPECTRUM_COLOR_PREFIX}-${elevationPreset[key].value.hue}-${elevationPreset[key].value.step}))`;\n break;\n case 'line':\n rootVars[name] = `rgb(var(--${LINE_COLOR_PREFIX}-${elevationPreset[key].value}))`;\n break;\n }\n }\n\n // border width\n if (key === 'borderWidth') {\n const name = `--${BORDER_WIDTH_PREFIX}-elevation-${level}`;\n rootVars[name] = `var(--${BORDER_WIDTH_PREFIX}-${elevationPreset[key]})`;\n }\n\n // drop shadow\n if (key === 'dropShadow') {\n const name = `--${DROP_SHADOW_PREFIX}-elevation-${level}`;\n const configValue = elevationPreset[key];\n\n rootVars[name] = Array.isArray(configValue)\n ? configValue\n .map((preset, index) =>\n getShadowLayerValue({\n preset,\n prefix: index > 0 ? `${index + 1}` : undefined,\n shadowType: 'drop',\n }),\n )\n .join(', ')\n : `var(--${DROP_SHADOW_PREFIX}-${elevationPreset[key]})`;\n }\n\n // inset shadow\n if (key === 'insetShadow') {\n const name = `--${INSET_SHADOW_PREFIX}-elevation-${level}`;\n const configValue = elevationPreset[key];\n\n rootVars[name] = Array.isArray(configValue)\n ? configValue\n .map((preset, index) =>\n getShadowLayerValue({\n preset,\n prefix: index > 0 ? `${index + 1}` : undefined,\n shadowType: 'inset',\n }),\n )\n .join(', ')\n : `var(--${INSET_SHADOW_PREFIX}-${elevationPreset[key]})`;\n }\n\n // background blur radius\n if (key === 'backgroundBlurRadius') {\n const name = `--${BACKGROUND_BLUR_RADIUS_PREFIX}-elevation-${level}`;\n rootVars[name] = `blur(${elevationPreset[key]}px)`;\n }\n\n // background blur fallback value\n if (key === 'fallbackBlurredBackgroundValue') {\n const { r, g, b } = elevationPreset[key];\n const name = `--${BACKGROUND_BLUR_FALLBACK_COLOR_PREFIX}-elevation-${level}`;\n rootVars[name] = `rgb(${r}, ${g}, ${b})`;\n }\n });\n }\n });\n\n rootVars[`--${OUTLINE_PREFIX}-offset`] = focusRingConfig ? `${focusRingConfig.offset}px` : '2px';\n rootVars[`--${OUTLINE_PREFIX}-width`] = focusRingConfig ? `${focusRingConfig.width}px` : '2px';\n rootVars[`--${OUTLINE_PREFIX}-style`] = 'solid';\n rootVars[`--${OUTLINE_PREFIX}-color`] = focusRingConfig\n ? resolveFocusRingColor(focusRingConfig.color)\n : `rgb(var(--${SPECTRUM_COLOR_PREFIX}-gray-15))`;\n\n return {\n _vars: rootVars,\n _raw: colors,\n tailwindConfig,\n };\n}\n\nfunction transformNumericToPx<T extends Record<string, number>>(prefix: string, config: T) {\n if (!config) {\n return {\n _vars: {} as Record<string, string>,\n _raw: {} as Record<string, number>,\n tailwindConfig: {} as Record<string, string>,\n };\n }\n const rootVars: Record<string, string> = {};\n const tailwindConfig = {} as Record<string, string>;\n for (const [variant, value] of entries(config)) {\n const rootVarKey = `--${prefix}-${variant}`;\n const rootVarValue = `${value}px`;\n rootVars[rootVarKey] = rootVarValue;\n tailwindConfig[variant] = `var(${rootVarKey})`;\n }\n return {\n _vars: rootVars,\n _raw: config,\n tailwindConfig,\n };\n}\n\ntype WebTokens = Omit<UniversalTokensConfig, 'colorMode' | 'scaleMode' | 'fontFamily'> & {\n colorMode: Record<ColorMode, ReturnType<typeof transformColors>>;\n scaleMode: Record<\n ScaleMode,\n {\n borderRadius: ReturnType<typeof transformNumericToPx>;\n borderWidth: ReturnType<typeof transformNumericToPx>;\n avatarSizes: ReturnType<typeof transformNumericToPx>;\n iconSizes: ReturnType<typeof transformNumericToPx>;\n }\n >;\n};\n\nfunction getElevationPresetsForColorMode(\n colorMode: ColorMode,\n config: UniversalTokensConfig,\n): ColorModeElevationPresets {\n if (!config.elevation) {\n return {};\n }\n\n const result: ColorModeElevationPresets = {};\n\n entries(config.elevation).forEach(([level, levelPreset]) => {\n result[level] = levelPreset[colorMode];\n });\n\n return result;\n}\n\nexport function parseTokens(config: UniversalTokensConfig): WebTokens {\n const { colorMode, scaleMode } = config;\n\n return {\n ...config,\n colorMode: {\n light: transformColors(\n colorMode.light,\n getElevationPresetsForColorMode('light', config),\n config.focusRing?.light,\n ),\n dark: transformColors(\n colorMode.dark,\n getElevationPresetsForColorMode('dark', config),\n config.focusRing?.dark,\n ),\n },\n scaleMode: mapValues(scaleMode, ({ borderRadius, borderWidth, avatarSizes, iconSizes }) => {\n return {\n borderRadius: transformNumericToPx(BORDER_RADIUS_PREFIX, borderRadius),\n borderWidth: transformNumericToPx(BORDER_WIDTH_PREFIX, borderWidth),\n avatarSizes: transformNumericToPx(AVATAR_SIZE_PREFIX, avatarSizes),\n iconSizes: transformNumericToPx(ICON_SIZE_PREFIX, iconSizes),\n };\n }),\n };\n}\n\nexport { type WebTokens };\n"],"mappings":";;;;;;;;AAsCA,SAAS,yBAAyB,OAA6D;CAC7F,MAAM,EAAE,GAAG,GAAG,MAAM,MAAM;CAC1B,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG;;AAGtB,SAAS,qBAAqB,SAA2C;CACvE,IAAI,CAAC,SACH,OAAO;CAGT,MAAM,gBAA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ACV,OAAO,EAAE;CAGX,MAAM,SAAoC,EAAE;CAE5C,QAAQ,OAAO,UAAU,CAAC,SAAS,CAAC,OAAO,iBAAiB;EAC1D,OAAO,SAAS,YAAY;GAC5B;CAEF,OAAO;;AAGT,SAAgB,YAAY,QAA0C;CACpE,MAAM,EAAE,WAAW,cAAc;CAEjC,OAAO;EACL,GAAG;EACH,WAAW;GACT,OAAO,gBACL,UAAU,OACV,gCAAgC,SAAS,OAAO,EAChD,OAAO,WAAW,MACnB;GACD,MAAM,gBACJ,UAAU,MACV,gCAAgC,QAAQ,OAAO,EAC/C,OAAO,WAAW,KACnB;GACF;EACD,WAAW,UAAU,YAAY,EAAE,cAAc,aAAa,aAAa,gBAAgB;GACzF,OAAO;IACL,cAAc,qBAAqB,sBAAsB,aAAa;IACtE,aAAa,qBAAqB,qBAAqB,YAAY;IACnE,aAAa,qBAAqB,oBAAoB,YAAY;IAClE,WAAW,qBAAqB,kBAAkB,UAAU;IAC7D;IACD;EACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"postcssPreserveVars.js","names":[],"sources":["../../src/utils/postcssPreserveVars.ts"],"sourcesContent":["import type { Plugin } from 'postcss';\n\ninterface PreserveVarsOptions {\n /** Variable name patterns to preserve (regex or string prefix) */\n preserve?: (string | RegExp)[];\n}\n\nconst PRESERVE_SELECTOR = '._uds-preserve-vars';\n\n/**\n * PostCSS plugin to preserve CSS variables from being pruned.\n *\n * Runs BEFORE postcss-prune-var to inject fake usages for preserved variables,\n * preventing them from being removed.\n *\n * @example\n * ```ts\n * postcss([\n * preserveVars({ preserve: ['--uds-motion-'] }),\n * pruneVar(),\n * preserveVarsCleanup(),\n * ])\n * ```\n */\nfunction preserveVars(options: PreserveVarsOptions = {}): Plugin {\n const { preserve = [] } = options;\n\n return {\n postcssPlugin: 'postcss-preserve-vars',\n Once(root) {\n if (preserve.length === 0) {\n return;\n }\n\n // Collect all CSS variable declarations\n const declaredVars = new Set<string>();\n\n root.walkDecls((decl) => {\n if (decl.prop.startsWith('--')) {\n declaredVars.add(decl.prop);\n }\n });\n\n // Find variables that match preserve patterns\n const varsToPreserve: string[] = [];\n\n for (const varName of declaredVars) {\n for (const pattern of preserve) {\n const matches =\n pattern instanceof RegExp ? pattern.test(varName) : varName.startsWith(pattern);\n\n if (matches) {\n varsToPreserve.push(varName);\n break;\n }\n }\n }\n\n if (varsToPreserve.length === 0) {\n return;\n }\n\n // Add a temporary rule that \"uses\" all preserved variables\n // This prevents postcss-prune-var from removing them\n const varUsages = varsToPreserve.map((v) => `var(${v})`).join(' ');\n\n root.append({\n selector: PRESERVE_SELECTOR,\n nodes: [{ prop: 'content', value: `\"${varUsages}\"` }],\n });\n },\n };\n}\n\npreserveVars.postcss = true;\n\n/**\n * PostCSS plugin to remove the temporary preserve rule after pruning.\n * Run this AFTER postcss-prune-var.\n */\nfunction preserveVarsCleanup(): Plugin {\n return {\n postcssPlugin: 'postcss-preserve-vars-cleanup',\n Once(root) {\n root.walkRules((rule) => {\n if (rule.selector === PRESERVE_SELECTOR) {\n rule.remove();\n }\n });\n },\n };\n}\n\npreserveVarsCleanup.postcss = true;\n\nexport { preserveVars, preserveVarsCleanup };\nexport type { PreserveVarsOptions };\n"],"mappings":";;AAOA,MAAM,oBAAoB;;;;;;;;;;;;;;;;AAiB1B,SAAS,aAAa,UAA+B,EAAE,EAAU;CAC/D,MAAM,EAAE,WAAW,EAAE,KAAK;AAE1B,QAAO;EACL,eAAe;EACf,KAAK,MAAM;AACT,OAAI,SAAS,WAAW,EACtB;GAIF,MAAM,+BAAe,IAAI,KAAa;AAEtC,QAAK,WAAW,SAAS;AACvB,QAAI,KAAK,KAAK,WAAW,KAAK,CAC5B,cAAa,IAAI,KAAK,KAAK;KAE7B;GAGF,MAAM,iBAA2B,EAAE;AAEnC,QAAK,MAAM,WAAW,aACpB,MAAK,MAAM,WAAW,SAIpB,KAFE,mBAAmB,SAAS,QAAQ,KAAK,QAAQ,GAAG,QAAQ,WAAW,QAAQ,EAEpE;AACX,mBAAe,KAAK,QAAQ;AAC5B;;AAKN,OAAI,eAAe,WAAW,EAC5B;GAKF,MAAM,YAAY,eAAe,KAAK,MAAM,OAAO,EAAE,GAAG,CAAC,KAAK,IAAI;AAElE,QAAK,OAAO;IACV,UAAU;IACV,OAAO,CAAC;KAAE,MAAM;KAAW,OAAO,IAAI,UAAU;KAAI,CAAC;IACtD,CAAC;;EAEL;;AAGH,aAAa,UAAU;;;;;AAMvB,SAAS,sBAA8B;AACrC,QAAO;EACL,eAAe;EACf,KAAK,MAAM;AACT,QAAK,WAAW,SAAS;AACvB,QAAI,KAAK,aAAa,kBACpB,MAAK,QAAQ;KAEf;;EAEL;;AAGH,oBAAoB,UAAU"}
1
+ {"version":3,"file":"postcssPreserveVars.js","names":[],"sources":["../../src/utils/postcssPreserveVars.ts"],"sourcesContent":["import type { Plugin } from 'postcss';\n\ninterface PreserveVarsOptions {\n /** Variable name patterns to preserve (regex or string prefix) */\n preserve?: (string | RegExp)[];\n}\n\nconst PRESERVE_SELECTOR = '._uds-preserve-vars';\n\n/**\n * PostCSS plugin to preserve CSS variables from being pruned.\n *\n * Runs BEFORE postcss-prune-var to inject fake usages for preserved variables,\n * preventing them from being removed.\n *\n * @example\n * ```ts\n * postcss([\n * preserveVars({ preserve: ['--uds-motion-'] }),\n * pruneVar(),\n * preserveVarsCleanup(),\n * ])\n * ```\n */\nfunction preserveVars(options: PreserveVarsOptions = {}): Plugin {\n const { preserve = [] } = options;\n\n return {\n postcssPlugin: 'postcss-preserve-vars',\n Once(root) {\n if (preserve.length === 0) {\n return;\n }\n\n // Collect all CSS variable declarations\n const declaredVars = new Set<string>();\n\n root.walkDecls((decl) => {\n if (decl.prop.startsWith('--')) {\n declaredVars.add(decl.prop);\n }\n });\n\n // Find variables that match preserve patterns\n const varsToPreserve: string[] = [];\n\n for (const varName of declaredVars) {\n for (const pattern of preserve) {\n const matches =\n pattern instanceof RegExp ? pattern.test(varName) : varName.startsWith(pattern);\n\n if (matches) {\n varsToPreserve.push(varName);\n break;\n }\n }\n }\n\n if (varsToPreserve.length === 0) {\n return;\n }\n\n // Add a temporary rule that \"uses\" all preserved variables\n // This prevents postcss-prune-var from removing them\n const varUsages = varsToPreserve.map((v) => `var(${v})`).join(' ');\n\n root.append({\n selector: PRESERVE_SELECTOR,\n nodes: [{ prop: 'content', value: `\"${varUsages}\"` }],\n });\n },\n };\n}\n\npreserveVars.postcss = true;\n\n/**\n * PostCSS plugin to remove the temporary preserve rule after pruning.\n * Run this AFTER postcss-prune-var.\n */\nfunction preserveVarsCleanup(): Plugin {\n return {\n postcssPlugin: 'postcss-preserve-vars-cleanup',\n Once(root) {\n root.walkRules((rule) => {\n if (rule.selector === PRESERVE_SELECTOR) {\n rule.remove();\n }\n });\n },\n };\n}\n\npreserveVarsCleanup.postcss = true;\n\nexport { preserveVars, preserveVarsCleanup };\nexport type { PreserveVarsOptions };\n"],"mappings":";;AAOA,MAAM,oBAAoB;;;;;;;;;;;;;;;;AAiB1B,SAAS,aAAa,UAA+B,EAAE,EAAU;CAC/D,MAAM,EAAE,WAAW,EAAE,KAAK;CAE1B,OAAO;EACL,eAAe;EACf,KAAK,MAAM;GACT,IAAI,SAAS,WAAW,GACtB;GAIF,MAAM,+BAAe,IAAI,KAAa;GAEtC,KAAK,WAAW,SAAS;IACvB,IAAI,KAAK,KAAK,WAAW,KAAK,EAC5B,aAAa,IAAI,KAAK,KAAK;KAE7B;GAGF,MAAM,iBAA2B,EAAE;GAEnC,KAAK,MAAM,WAAW,cACpB,KAAK,MAAM,WAAW,UAIpB,IAFE,mBAAmB,SAAS,QAAQ,KAAK,QAAQ,GAAG,QAAQ,WAAW,QAAQ,EAEpE;IACX,eAAe,KAAK,QAAQ;IAC5B;;GAKN,IAAI,eAAe,WAAW,GAC5B;GAKF,MAAM,YAAY,eAAe,KAAK,MAAM,OAAO,EAAE,GAAG,CAAC,KAAK,IAAI;GAElE,KAAK,OAAO;IACV,UAAU;IACV,OAAO,CAAC;KAAE,MAAM;KAAW,OAAO,IAAI,UAAU;KAAI,CAAC;IACtD,CAAC;;EAEL;;AAGH,aAAa,UAAU;;;;;AAMvB,SAAS,sBAA8B;CACrC,OAAO;EACL,eAAe;EACf,KAAK,MAAM;GACT,KAAK,WAAW,SAAS;IACvB,IAAI,KAAK,aAAa,mBACpB,KAAK,QAAQ;KAEf;;EAEL;;AAGH,oBAAoB,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"tsMorph.js","names":[],"sources":["../../src/utils/tsMorph.ts"],"sourcesContent":["import { camelCase, isEmpty } from 'lodash';\nimport type {\n ArrowFunction,\n CallExpression,\n ClassDeclaration,\n FunctionDeclaration,\n FunctionExpression,\n Identifier,\n JsxElement,\n JsxOpeningElement,\n JsxSelfClosingElement,\n VariableDeclaration,\n} from 'ts-morph';\nimport { Node, SyntaxKind } from 'ts-morph';\n\n/** Determines if an expression is using React.forwardRef. */\nexport function isForwardRefExpression(node: Node): node is CallExpression {\n if (Node.isCallExpression(node)) {\n const expression = node.getExpression();\n\n /**\n * forwardRef(() => <Component />)\n */\n if (Node.isIdentifier(expression) && expression.getText() === 'forwardRef') {\n return true;\n }\n\n /**\n * React.forwardRef(() => <Component />)\n */\n if (\n Node.isPropertyAccessExpression(expression) &&\n expression.getText() === 'React.forwardRef'\n ) {\n return true;\n }\n }\n\n return false;\n}\n\n/** Determines if a node is a JSX component. */\nexport function isJsxComponent(\n node: Node,\n): node is\n | VariableDeclaration\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunction\n | ClassDeclaration {\n let name: string | undefined;\n\n if (\n Node.isVariableDeclaration(node) ||\n Node.isFunctionDeclaration(node) ||\n Node.isClassDeclaration(node)\n ) {\n name = node.getName();\n } else if (Node.isFunctionExpression(node) || Node.isArrowFunction(node)) {\n const variableDeclaration = node.getFirstAncestorByKind(SyntaxKind.VariableDeclaration);\n name = variableDeclaration?.getName();\n }\n\n return name ? /[A-Z]/.test(name.charAt(0)) : false;\n}\n\n/** Returns a functional component declaration, unwrapping forwardRef if needed. */\nexport function getReactFunctionDeclaration(\n declaration: Node,\n): ArrowFunction | FunctionDeclaration | FunctionExpression | null {\n if (isJsxComponent(declaration)) {\n if (Node.isFunctionDeclaration(declaration)) {\n return declaration;\n }\n\n if (Node.isVariableDeclaration(declaration)) {\n const initializer = declaration.getInitializer();\n\n if (initializer) {\n if (isForwardRefExpression(initializer)) {\n const [initializerDeclaration] = initializer.getArguments();\n if (\n Node.isFunctionDeclaration(initializerDeclaration) ||\n Node.isFunctionExpression(initializerDeclaration) ||\n Node.isArrowFunction(initializerDeclaration)\n ) {\n return initializerDeclaration;\n }\n } else if (\n Node.isFunctionDeclaration(initializer) ||\n Node.isFunctionExpression(initializer) ||\n Node.isArrowFunction(initializer)\n ) {\n return initializer;\n }\n }\n }\n }\n\n return null;\n}\n\n/** Get the first descendant JsxElement based on the identifier. */\nexport function getJsxElement(node: Node, name: string) {\n return getJsxElements(node).find(\n (node) => node.getFirstDescendantByKindOrThrow(SyntaxKind.Identifier).getText() === name,\n );\n}\n\n/** Get all descendant JsxElement nodes. */\nexport function getJsxElements(node: Node) {\n return node\n .getDescendants()\n .filter((node) => Node.isJsxElement(node) || Node.isJsxSelfClosingElement(node)) as (\n | JsxElement\n | JsxSelfClosingElement\n )[];\n}\n\n/**\n * Traces component references.\n *\n * This is similar to `findReferencesAsNodes` but returns JsxSelfClosingElement and JsxElement nodes.\n * Note, this currently does not account for cases where the component is used as a prop or is renamed.\n */\nexport function findReferencesAsJsxElements(\n identifer: Identifier,\n): (JsxOpeningElement | JsxSelfClosingElement)[] {\n const jsxElements: Node[] = [];\n\n for (const reference of identifer.findReferencesAsNodes()) {\n const node = reference.getFirstAncestor((node) => {\n return Node.isJsxOpeningElement(node) || Node.isJsxSelfClosingElement(node);\n });\n\n if (node) {\n jsxElements.push(node);\n }\n }\n\n return jsxElements as (JsxOpeningElement | JsxSelfClosingElement)[];\n}\n\n/**\n * Given a Jsx Reference, this function finds the parent of that reference,\n * looks at the props, and returns the name used either for spread operator rest or\n * the prop name if there's no spread operator\n */\nexport const getParentSpreadOrParamIdentifier = (\n reference: JsxOpeningElement | JsxSelfClosingElement,\n): string | undefined => {\n // get the parent component where this reference is used\n const block = reference.getParentWhile((parent) => {\n return !getReactFunctionDeclaration(parent);\n })!;\n\n const blockParent = block.getParent();\n\n if (!blockParent) {\n return undefined;\n }\n\n // check if the parent is a react component\n const reactComponent = getReactFunctionDeclaration(blockParent);\n\n if (reactComponent) {\n const parameters = reactComponent.getParameters();\n\n for (let i = 0; i < parameters.length; i++) {\n const parameter = parameters[i];\n const objectBindingPattern = parameter.getChildrenOfKind(SyntaxKind.ObjectBindingPattern)[0]; // ({ param1, ...props }: Props)\n const identifier = parameter.getChildrenOfKind(SyntaxKind.Identifier)[0]; // (props: Props)\n\n if (objectBindingPattern) {\n const dotDotToken = objectBindingPattern.getFirstDescendantByKind(\n SyntaxKind.DotDotDotToken,\n );\n const isSpreadOperatorRest = dotDotToken !== undefined;\n if (isSpreadOperatorRest) {\n const spreadRestIdentifier = dotDotToken\n ?.getParent()\n ?.getFirstChildByKindOrThrow(SyntaxKind.Identifier)\n .getText();\n\n return spreadRestIdentifier;\n }\n } else if (identifier) {\n return identifier.getText();\n }\n }\n }\n};\n\n/**\n * Get used props on a reference.\n */\nexport const getUsedPropsInReference = (\n reference: JsxOpeningElement | JsxSelfClosingElement,\n variants: Record<string, Record<string, string>>,\n): Array<[string, string[]]> => {\n const attributes = reference.getAttributes();\n const res: Array<[string, string[]]> = [];\n\n attributes.forEach((attribute) => {\n if (Node.isJsxAttribute(attribute)) {\n const attributeName = attribute.getNameNode().getText();\n // TODO: try to resolve the expression (ex: on the Icon button we know that ony sm value is passed)\n // <Button display=\"flex\" /> or <Button display={\"flex\"} />\n // BORDER_WIDTH === 'thin' ? '0.5' : '1'\n const stringLiterals = attribute.getDescendantsOfKind(SyntaxKind.StringLiteral);\n const values: string[] = [];\n if (stringLiterals.length !== 0) {\n stringLiterals.forEach((stringLiteral) => values.push(stringLiteral.getLiteralText()));\n }\n // Sometimes the property name doesn't directly map to the variant,\n // but instead, the properties type name does. (Ex: `iconSize` is the corresponding variant for `size` prop on Icons)\n const typeName = attribute\n .getFirstChildByKindOrThrow(SyntaxKind.Identifier)\n .getDefinitions()\n .map((d) =>\n d.getDeclarationNode()?.getChildrenOfKind(SyntaxKind.TypeReference).pop()?.getText(),\n )\n .pop();\n\n if (!typeName && !isEmpty(attributeName)) {\n res.push([attributeName, values]);\n } else if (variants[camelCase(typeName) as keyof typeof variants] && !isEmpty(typeName)) {\n res.push([camelCase(typeName), values]);\n } else if (!isEmpty(attributeName)) {\n res.push([attributeName, values]);\n }\n }\n\n if (Node.isJsxSpreadAttribute(attribute)) {\n const componentPropsSpreadIdentifier = getParentSpreadOrParamIdentifier(reference);\n const children = attribute.getExpression().getChildren();\n\n // we need the last element in the spread operator\n // the goal here is to find if we are blindly just passing all the props from the parent\n const lastIdentifier = children.length === 0 ? attribute.getExpression() : children.pop();\n if (!lastIdentifier || lastIdentifier?.getText() === componentPropsSpreadIdentifier) {\n return [];\n }\n\n lastIdentifier\n .getType()\n .getProperties()\n // these are typescript properties\n // so we don't know which values have been used.\n .forEach((property) => {\n // Sometimes the property name doesn't directly map to the variant,\n // but instead, the properties type name does. (Ex: `iconSize` is the corresponding variant for `size` prop on Icons)\n const propertyNameFromType = property.getDeclarations().map((declaration) => {\n const typeName =\n declaration.getChildrenOfKind(SyntaxKind.TypeReference)[0]?.getText() ?? '';\n return camelCase(typeName);\n })[0];\n if (!isEmpty(property.getName())) {\n res.push([property.getName(), []]);\n }\n if (!isEmpty(propertyNameFromType)) {\n res.push([propertyNameFromType, []]);\n }\n });\n }\n\n return [];\n });\n\n return res;\n};\n"],"mappings":";;;;;AAgBA,SAAgB,uBAAuB,MAAoC;AACzE,KAAI,KAAK,iBAAiB,KAAK,EAAE;EAC/B,MAAM,aAAa,KAAK,eAAe;;;;AAKvC,MAAI,KAAK,aAAa,WAAW,IAAI,WAAW,SAAS,KAAK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OAAO,CAAC;YAC9B,CAAC,QAAQ,cAAc,CAChC,KAAI,KAAK,CAAC,eAAe,OAAO,CAAC;;AAIrC,MAAI,KAAK,qBAAqB,UAAU,EAAE;GACxC,MAAM,iCAAiC,iCAAiC,UAAU;GAClF,MAAM,WAAW,UAAU,eAAe,CAAC,aAAa;GAIxD,MAAM,iBAAiB,SAAS,WAAW,IAAI,UAAU,eAAe,GAAG,SAAS,KAAK;AACzF,OAAI,CAAC,kBAAkB,gBAAgB,SAAS,KAAK,+BACnD,QAAO,EAAE;AAGX,kBACG,SAAQ,CACR,eAAc,CAGd,SAAS,aAAa;IAGrB,MAAM,uBAAuB,SAAS,iBAAiB,CAAC,KAAK,gBAAgB;AAG3E,YAAO,UADL,YAAY,kBAAkB,WAAW,cAAc,CAAC,IAAI,SAAS,IAAI,GACjD;MAC1B,CAAC;AACH,QAAI,CAAC,QAAQ,SAAS,SAAS,CAAC,CAC9B,KAAI,KAAK,CAAC,SAAS,SAAS,EAAE,EAAE,CAAC,CAAC;AAEpC,QAAI,CAAC,QAAQ,qBAAqB,CAChC,KAAI,KAAK,CAAC,sBAAsB,EAAE,CAAC,CAAC;KAEtC;;AAGN,SAAO,EAAE;GACT;AAEF,QAAO"}
1
+ {"version":3,"file":"tsMorph.js","names":[],"sources":["../../src/utils/tsMorph.ts"],"sourcesContent":["import { camelCase, isEmpty } from 'lodash';\nimport type {\n ArrowFunction,\n CallExpression,\n ClassDeclaration,\n FunctionDeclaration,\n FunctionExpression,\n Identifier,\n JsxElement,\n JsxOpeningElement,\n JsxSelfClosingElement,\n VariableDeclaration,\n} from 'ts-morph';\nimport { Node, SyntaxKind } from 'ts-morph';\n\n/** Determines if an expression is using React.forwardRef. */\nexport function isForwardRefExpression(node: Node): node is CallExpression {\n if (Node.isCallExpression(node)) {\n const expression = node.getExpression();\n\n /**\n * forwardRef(() => <Component />)\n */\n if (Node.isIdentifier(expression) && expression.getText() === 'forwardRef') {\n return true;\n }\n\n /**\n * React.forwardRef(() => <Component />)\n */\n if (\n Node.isPropertyAccessExpression(expression) &&\n expression.getText() === 'React.forwardRef'\n ) {\n return true;\n }\n }\n\n return false;\n}\n\n/** Determines if a node is a JSX component. */\nexport function isJsxComponent(\n node: Node,\n): node is\n | VariableDeclaration\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunction\n | ClassDeclaration {\n let name: string | undefined;\n\n if (\n Node.isVariableDeclaration(node) ||\n Node.isFunctionDeclaration(node) ||\n Node.isClassDeclaration(node)\n ) {\n name = node.getName();\n } else if (Node.isFunctionExpression(node) || Node.isArrowFunction(node)) {\n const variableDeclaration = node.getFirstAncestorByKind(SyntaxKind.VariableDeclaration);\n name = variableDeclaration?.getName();\n }\n\n return name ? /[A-Z]/.test(name.charAt(0)) : false;\n}\n\n/** Returns a functional component declaration, unwrapping forwardRef if needed. */\nexport function getReactFunctionDeclaration(\n declaration: Node,\n): ArrowFunction | FunctionDeclaration | FunctionExpression | null {\n if (isJsxComponent(declaration)) {\n if (Node.isFunctionDeclaration(declaration)) {\n return declaration;\n }\n\n if (Node.isVariableDeclaration(declaration)) {\n const initializer = declaration.getInitializer();\n\n if (initializer) {\n if (isForwardRefExpression(initializer)) {\n const [initializerDeclaration] = initializer.getArguments();\n if (\n Node.isFunctionDeclaration(initializerDeclaration) ||\n Node.isFunctionExpression(initializerDeclaration) ||\n Node.isArrowFunction(initializerDeclaration)\n ) {\n return initializerDeclaration;\n }\n } else if (\n Node.isFunctionDeclaration(initializer) ||\n Node.isFunctionExpression(initializer) ||\n Node.isArrowFunction(initializer)\n ) {\n return initializer;\n }\n }\n }\n }\n\n return null;\n}\n\n/** Get the first descendant JsxElement based on the identifier. */\nexport function getJsxElement(node: Node, name: string) {\n return getJsxElements(node).find(\n (node) => node.getFirstDescendantByKindOrThrow(SyntaxKind.Identifier).getText() === name,\n );\n}\n\n/** Get all descendant JsxElement nodes. */\nexport function getJsxElements(node: Node) {\n return node\n .getDescendants()\n .filter((node) => Node.isJsxElement(node) || Node.isJsxSelfClosingElement(node)) as (\n | JsxElement\n | JsxSelfClosingElement\n )[];\n}\n\n/**\n * Traces component references.\n *\n * This is similar to `findReferencesAsNodes` but returns JsxSelfClosingElement and JsxElement nodes.\n * Note, this currently does not account for cases where the component is used as a prop or is renamed.\n */\nexport function findReferencesAsJsxElements(\n identifer: Identifier,\n): (JsxOpeningElement | JsxSelfClosingElement)[] {\n const jsxElements: Node[] = [];\n\n for (const reference of identifer.findReferencesAsNodes()) {\n const node = reference.getFirstAncestor((node) => {\n return Node.isJsxOpeningElement(node) || Node.isJsxSelfClosingElement(node);\n });\n\n if (node) {\n jsxElements.push(node);\n }\n }\n\n return jsxElements as (JsxOpeningElement | JsxSelfClosingElement)[];\n}\n\n/**\n * Given a Jsx Reference, this function finds the parent of that reference,\n * looks at the props, and returns the name used either for spread operator rest or\n * the prop name if there's no spread operator\n */\nexport const getParentSpreadOrParamIdentifier = (\n reference: JsxOpeningElement | JsxSelfClosingElement,\n): string | undefined => {\n // get the parent component where this reference is used\n const block = reference.getParentWhile((parent) => {\n return !getReactFunctionDeclaration(parent);\n })!;\n\n const blockParent = block.getParent();\n\n if (!blockParent) {\n return undefined;\n }\n\n // check if the parent is a react component\n const reactComponent = getReactFunctionDeclaration(blockParent);\n\n if (reactComponent) {\n const parameters = reactComponent.getParameters();\n\n for (let i = 0; i < parameters.length; i++) {\n const parameter = parameters[i];\n const objectBindingPattern = parameter.getChildrenOfKind(SyntaxKind.ObjectBindingPattern)[0]; // ({ param1, ...props }: Props)\n const identifier = parameter.getChildrenOfKind(SyntaxKind.Identifier)[0]; // (props: Props)\n\n if (objectBindingPattern) {\n const dotDotToken = objectBindingPattern.getFirstDescendantByKind(\n SyntaxKind.DotDotDotToken,\n );\n const isSpreadOperatorRest = dotDotToken !== undefined;\n if (isSpreadOperatorRest) {\n const spreadRestIdentifier = dotDotToken\n ?.getParent()\n ?.getFirstChildByKindOrThrow(SyntaxKind.Identifier)\n .getText();\n\n return spreadRestIdentifier;\n }\n } else if (identifier) {\n return identifier.getText();\n }\n }\n }\n};\n\n/**\n * Get used props on a reference.\n */\nexport const getUsedPropsInReference = (\n reference: JsxOpeningElement | JsxSelfClosingElement,\n variants: Record<string, Record<string, string>>,\n): Array<[string, string[]]> => {\n const attributes = reference.getAttributes();\n const res: Array<[string, string[]]> = [];\n\n attributes.forEach((attribute) => {\n if (Node.isJsxAttribute(attribute)) {\n const attributeName = attribute.getNameNode().getText();\n // TODO: try to resolve the expression (ex: on the Icon button we know that ony sm value is passed)\n // <Button display=\"flex\" /> or <Button display={\"flex\"} />\n // BORDER_WIDTH === 'thin' ? '0.5' : '1'\n const stringLiterals = attribute.getDescendantsOfKind(SyntaxKind.StringLiteral);\n const values: string[] = [];\n if (stringLiterals.length !== 0) {\n stringLiterals.forEach((stringLiteral) => values.push(stringLiteral.getLiteralText()));\n }\n // Sometimes the property name doesn't directly map to the variant,\n // but instead, the properties type name does. (Ex: `iconSize` is the corresponding variant for `size` prop on Icons)\n const typeName = attribute\n .getFirstChildByKindOrThrow(SyntaxKind.Identifier)\n .getDefinitions()\n .map((d) =>\n d.getDeclarationNode()?.getChildrenOfKind(SyntaxKind.TypeReference).pop()?.getText(),\n )\n .pop();\n\n if (!typeName && !isEmpty(attributeName)) {\n res.push([attributeName, values]);\n } else if (variants[camelCase(typeName) as keyof typeof variants] && !isEmpty(typeName)) {\n res.push([camelCase(typeName), values]);\n } else if (!isEmpty(attributeName)) {\n res.push([attributeName, values]);\n }\n }\n\n if (Node.isJsxSpreadAttribute(attribute)) {\n const componentPropsSpreadIdentifier = getParentSpreadOrParamIdentifier(reference);\n const children = attribute.getExpression().getChildren();\n\n // we need the last element in the spread operator\n // the goal here is to find if we are blindly just passing all the props from the parent\n const lastIdentifier = children.length === 0 ? attribute.getExpression() : children.pop();\n if (!lastIdentifier || lastIdentifier?.getText() === componentPropsSpreadIdentifier) {\n return [];\n }\n\n lastIdentifier\n .getType()\n .getProperties()\n // these are typescript properties\n // so we don't know which values have been used.\n .forEach((property) => {\n // Sometimes the property name doesn't directly map to the variant,\n // but instead, the properties type name does. (Ex: `iconSize` is the corresponding variant for `size` prop on Icons)\n const propertyNameFromType = property.getDeclarations().map((declaration) => {\n const typeName =\n declaration.getChildrenOfKind(SyntaxKind.TypeReference)[0]?.getText() ?? '';\n return camelCase(typeName);\n })[0];\n if (!isEmpty(property.getName())) {\n res.push([property.getName(), []]);\n }\n if (!isEmpty(propertyNameFromType)) {\n res.push([propertyNameFromType, []]);\n }\n });\n }\n\n return [];\n });\n\n return res;\n};\n"],"mappings":";;;;;AAgBA,SAAgB,uBAAuB,MAAoC;CACzE,IAAI,KAAK,iBAAiB,KAAK,EAAE;EAC/B,MAAM,aAAa,KAAK,eAAe;;;;EAKvC,IAAI,KAAK,aAAa,WAAW,IAAI,WAAW,SAAS,KAAK,cAC5D,OAAO;;;;EAMT,IACE,KAAK,2BAA2B,WAAW,IAC3C,WAAW,SAAS,KAAK,oBAEzB,OAAO;;CAIX,OAAO;;;AAIT,SAAgB,eACd,MAMmB;CACnB,IAAI;CAEJ,IACE,KAAK,sBAAsB,KAAK,IAChC,KAAK,sBAAsB,KAAK,IAChC,KAAK,mBAAmB,KAAI,EAE5B,OAAO,KAAK,SAAS;MAChB,IAAI,KAAK,qBAAqB,KAAK,IAAI,KAAK,gBAAgB,KAAK,EAEtE,OAD4B,KAAK,uBAAuB,WAAW,oBACzC,EAAE,SAAS;CAGvC,OAAO,OAAO,QAAQ,KAAK,KAAK,OAAO,EAAE,CAAC,GAAG;;;AAI/C,SAAgB,4BACd,aACiE;CACjE,IAAI,eAAe,YAAY,EAAE;EAC/B,IAAI,KAAK,sBAAsB,YAAY,EACzC,OAAO;EAGT,IAAI,KAAK,sBAAsB,YAAY,EAAE;GAC3C,MAAM,cAAc,YAAY,gBAAgB;GAEhD,IAAI;QACE,uBAAuB,YAAY,EAAE;KACvC,MAAM,CAAC,0BAA0B,YAAY,cAAc;KAC3D,IACE,KAAK,sBAAsB,uBAAuB,IAClD,KAAK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AE,CAAC,CAAC;KAEtC;;EAGN,OAAO,EAAE;GACT;CAEF,OAAO"}
@@ -640,7 +640,7 @@ interface UniversalRadioProps {
640
640
  size?: RadioSize;
641
641
  /** The label content displayed alongside the radio. */
642
642
  label?: string | ReactNode | (() => ReactNode);
643
- /** The value submitted with form data. @default '' */
643
+ /** The option value for this radio. Required when used inside a RadioGroup. @default '' */
644
644
  value?: string;
645
645
  /** The controlled checked state. */
646
646
  checked?: boolean;
@@ -654,7 +654,7 @@ interface UniversalRadioProps {
654
654
  interface UniversalRadioGroupProps {
655
655
  /** The name shared by all radios in the group (for form submission). */
656
656
  name?: string;
657
- /** The controlled selected value. */
657
+ /** The controlled selected option value. */
658
658
  value?: string;
659
659
  /** The initial selected value for uncontrolled mode. */
660
660
  defaultValue?: string;
@@ -640,7 +640,7 @@ interface UniversalRadioProps {
640
640
  size?: RadioSize;
641
641
  /** The label content displayed alongside the radio. */
642
642
  label?: string | ReactNode | (() => ReactNode);
643
- /** The value submitted with form data. @default '' */
643
+ /** The option value for this radio. Required when used inside a RadioGroup. @default '' */
644
644
  value?: string;
645
645
  /** The controlled checked state. */
646
646
  checked?: boolean;
@@ -654,7 +654,7 @@ interface UniversalRadioProps {
654
654
  interface UniversalRadioGroupProps {
655
655
  /** The name shared by all radios in the group (for form submission). */
656
656
  name?: string;
657
- /** The controlled selected value. */
657
+ /** The controlled selected option value. */
658
658
  value?: string;
659
659
  /** The initial selected value for uncontrolled mode. */
660
660
  defaultValue?: string;